don't use #error as some compilers ignore it; provoke a real compile error instead
[wxWidgets.git] / build / aclocal / bakefile.m4
1 dnl ---------------------------------------------------------------------------
2 dnl Support macros for makefiles generated by BAKEFILE.
3 dnl ---------------------------------------------------------------------------
4
5 dnl Lots of compiler & linker detection code contained here was taken from
6 dnl wxWindows configure.in script (see http://www.wxwindows.org)
7
8
9
10 dnl ---------------------------------------------------------------------------
11 dnl AC_BAKEFILE_GNUMAKE
12 dnl
13 dnl Detects GNU make
14 dnl ---------------------------------------------------------------------------
15
16 AC_DEFUN([AC_BAKEFILE_GNUMAKE],
17 [
18     dnl does make support "-include" (only GNU make does AFAIK)?
19     AC_CACHE_CHECK([if make is GNU make], bakefile_cv_prog_makeisgnu,
20     [
21         if ( ${SHELL-sh} -c "${MAKE-make} --version" 2> /dev/null |
22                 egrep -s GNU > /dev/null); then
23             bakefile_cv_prog_makeisgnu="yes"
24         else
25             bakefile_cv_prog_makeisgnu="no"
26         fi
27     ])
28
29     if test "x$bakefile_cv_prog_makeisgnu" = "xyes"; then
30         IF_GNU_MAKE=""
31     else
32         IF_GNU_MAKE="#"
33     fi
34     AC_SUBST(IF_GNU_MAKE)
35 ])
36
37 dnl ---------------------------------------------------------------------------
38 dnl AC_BAKEFILE_PLATFORM
39 dnl
40 dnl Detects platform and sets PLATFORM_XXX variables accordingly
41 dnl ---------------------------------------------------------------------------
42
43 AC_DEFUN([AC_BAKEFILE_PLATFORM],
44 [
45     PLATFORM_UNIX=0
46     PLATFORM_WIN32=0
47     PLATFORM_MSDOS=0
48     PLATFORM_MAC=0
49     PLATFORM_MACOS=0
50     PLATFORM_MACOSX=0
51     PLATFORM_OS2=0
52     PLATFORM_BEOS=0
53
54     if test "x$BAKEFILE_FORCE_PLATFORM" = "x"; then 
55         case "${BAKEFILE_HOST}" in
56             *-*-mingw32* )
57                 PLATFORM_WIN32=1
58             ;;
59             *-pc-msdosdjgpp )
60                 PLATFORM_MSDOS=1
61             ;;
62             *-pc-os2_emx | *-pc-os2-emx )
63                 PLATFORM_OS2=1
64             ;;
65             *-*-darwin* )
66                 PLATFORM_MAC=1
67                 PLATFORM_MACOSX=1
68             ;; 
69             *-*-beos* )
70                 PLATFORM_BEOS=1
71             ;;
72             powerpc-apple-macos* )
73                 PLATFORM_MAC=1
74                 PLATFORM_MACOS=1
75             ;;
76             * )
77                 PLATFORM_UNIX=1
78             ;;
79         esac
80     else
81         case "$BAKEFILE_FORCE_PLATFORM" in
82             win32 )
83                 PLATFORM_WIN32=1
84             ;;
85             msdos )
86                 PLATFORM_MSDOS=1
87             ;;
88             os2 )
89                 PLATFORM_OS2=1
90             ;;
91             darwin )
92                 PLATFORM_MAC=1
93                 PLATFORM_MACOSX=1
94             ;;
95             unix )
96                 PLATFORM_UNIX=1
97             ;;
98             beos )
99                 PLATFORM_BEOS=1
100             ;;
101             * )
102                 AC_MSG_ERROR([Unknown platform: $BAKEFILE_FORCE_PLATFORM])
103             ;;
104         esac
105     fi
106
107     AC_SUBST(PLATFORM_UNIX)
108     AC_SUBST(PLATFORM_WIN32)
109     AC_SUBST(PLATFORM_MSDOS)
110     AC_SUBST(PLATFORM_MAC)
111     AC_SUBST(PLATFORM_MACOS)
112     AC_SUBST(PLATFORM_MACOSX)
113     AC_SUBST(PLATFORM_OS2)
114     AC_SUBST(PLATFORM_BEOS)
115 ])
116
117
118 dnl ---------------------------------------------------------------------------
119 dnl AC_BAKEFILE_PLATFORM_SPECIFICS
120 dnl
121 dnl Sets misc platform-specific settings
122 dnl ---------------------------------------------------------------------------
123
124 AC_DEFUN([AC_BAKEFILE_PLATFORM_SPECIFICS],
125 [
126     AC_ARG_ENABLE([omf], AS_HELP_STRING([--enable-omf],
127                                         [use OMF object format (OS/2)]),
128                   [bk_os2_use_omf="$enableval"])
129     
130     case "${BAKEFILE_HOST}" in
131       *-*-darwin* )
132         dnl For Unix to MacOS X porting instructions, see:
133         dnl http://fink.sourceforge.net/doc/porting/porting.html
134         if test "x$GCC" = "xyes"; then
135             CFLAGS="$CFLAGS -fno-common"
136             CXXFLAGS="$CXXFLAGS -fno-common"
137         fi
138         if test "x$XLCC" = "xyes"; then
139             CFLAGS="$CFLAGS -qnocommon"
140             CXXFLAGS="$CXXFLAGS -qnocommon"
141         fi
142         ;;
143
144       *-pc-os2_emx | *-pc-os2-emx )
145         if test "x$bk_os2_use_omf" = "xyes" ; then
146             AR=emxomfar
147             RANLIB=:
148             LDFLAGS="-Zomf $LDFLAGS"
149             CFLAGS="-Zomf $CFLAGS"
150             CXXFLAGS="-Zomf $CXXFLAGS"
151             OS2_LIBEXT="lib"
152         else
153             OS2_LIBEXT="a"
154         fi
155         ;;
156       
157       i*86-*-beos* )
158         LDFLAGS="-L/boot/develop/lib/x86 $LDFLAGS"
159         ;;
160     esac
161 ])
162
163 dnl ---------------------------------------------------------------------------
164 dnl AC_BAKEFILE_SUFFIXES
165 dnl
166 dnl Detects shared various suffixes for shared libraries, libraries, programs,
167 dnl plugins etc.
168 dnl ---------------------------------------------------------------------------
169
170 AC_DEFUN([AC_BAKEFILE_SUFFIXES],
171 [
172     SO_SUFFIX="so"
173     SO_SUFFIX_MODULE="so"
174     EXEEXT=""
175     LIBPREFIX="lib"
176     LIBEXT=".a"
177     DLLPREFIX="lib"
178     DLLPREFIX_MODULE=""
179     DLLIMP_SUFFIX=""
180     dlldir="$libdir"
181     
182     case "${BAKEFILE_HOST}" in
183         *-hp-hpux* )
184             SO_SUFFIX="sl"
185             SO_SUFFIX_MODULE="sl"
186         ;;
187         *-*-aix* )
188             dnl quoting from
189             dnl http://www-1.ibm.com/servers/esdd/articles/gnu.html:
190             dnl     Both archive libraries and shared libraries on AIX have an
191             dnl     .a extension. This will explain why you can't link with an
192             dnl     .so and why it works with the name changed to .a.
193             SO_SUFFIX="a"
194             SO_SUFFIX_MODULE="a"
195         ;;
196         *-*-cygwin* )
197             SO_SUFFIX="dll"
198             SO_SUFFIX_MODULE="dll"
199             DLLIMP_SUFFIX="dll.a"
200             EXEEXT=".exe"
201             DLLPREFIX="cyg"
202             dlldir="$bindir"
203         ;;
204         *-*-mingw32* )
205             SO_SUFFIX="dll"
206             SO_SUFFIX_MODULE="dll"
207             DLLIMP_SUFFIX="dll.a"
208             EXEEXT=".exe"
209             DLLPREFIX=""
210             dlldir="$bindir"
211         ;;
212         *-pc-msdosdjgpp )
213             EXEEXT=".exe"
214             DLLPREFIX=""
215             dlldir="$bindir"
216         ;;
217         *-pc-os2_emx | *-pc-os2-emx )
218             SO_SUFFIX="dll"
219             SO_SUFFIX_MODULE="dll"
220             DLLIMP_SUFFIX=$OS2_LIBEXT
221             EXEEXT=".exe"
222             DLLPREFIX=""
223             LIBPREFIX=""
224             LIBEXT=".$OS2_LIBEXT"
225             dlldir="$bindir"
226         ;;
227         *-*-darwin* )
228             SO_SUFFIX="dylib"
229             SO_SUFFIX_MODULE="bundle"
230         ;;
231     esac
232
233     if test "x$DLLIMP_SUFFIX" = "x" ; then
234         DLLIMP_SUFFIX="$SO_SUFFIX"
235     fi
236
237     AC_SUBST(SO_SUFFIX)
238     AC_SUBST(SO_SUFFIX_MODULE)
239     AC_SUBST(DLLIMP_SUFFIX)
240     AC_SUBST(EXEEXT)
241     AC_SUBST(LIBPREFIX)
242     AC_SUBST(LIBEXT)
243     AC_SUBST(DLLPREFIX)
244     AC_SUBST(DLLPREFIX_MODULE)
245     AC_SUBST(dlldir)
246 ])
247
248
249 dnl ---------------------------------------------------------------------------
250 dnl AC_BAKEFILE_SHARED_LD
251 dnl
252 dnl Detects command for making shared libraries, substitutes SHARED_LD_CC
253 dnl and SHARED_LD_CXX.
254 dnl ---------------------------------------------------------------------------
255
256 AC_DEFUN([AC_BAKEFILE_SHARED_LD],
257 [
258     dnl the extra compiler flags needed for compilation of shared library
259     PIC_FLAG=""
260     if test "x$GCC" = "xyes"; then
261         dnl the switch for gcc is the same under all platforms
262         PIC_FLAG="-fPIC"
263     fi
264     
265     dnl Defaults for GCC and ELF .so shared libs:
266     SHARED_LD_CC="\$(CC) -shared ${PIC_FLAG} -o"
267     SHARED_LD_CXX="\$(CXX) -shared ${PIC_FLAG} -o"
268     WINDOWS_IMPLIB=0
269
270     case "${BAKEFILE_HOST}" in
271       *-hp-hpux* )
272         dnl default settings are good for gcc but not for the native HP-UX
273         if test "x$GCC" != "xyes"; then
274             dnl no idea why it wants it, but it does
275             LDFLAGS="$LDFLAGS -L/usr/lib"
276
277             SHARED_LD_CC="${CC} -b -o"
278             SHARED_LD_CXX="${CXX} -b -o"
279             PIC_FLAG="+Z"
280         fi
281       ;;
282
283       *-*-linux* )
284         if test "x$GCC" != "xyes"; then
285             AC_CACHE_CHECK([for Intel compiler], bakefile_cv_prog_icc,
286             [
287                 AC_TRY_COMPILE([],
288                     [
289                         #ifndef __INTEL_COMPILER
290                         This is not ICC
291                         #endif
292                     ],
293                     bakefile_cv_prog_icc=yes,
294                     bakefile_cv_prog_icc=no
295                 )
296             ])
297             if test "$bakefile_cv_prog_icc" = "yes"; then
298                 PIC_FLAG="-KPIC"
299             fi
300         fi
301       ;;
302
303       *-*-solaris2* )
304         if test "x$GCC" != xyes ; then
305             SHARED_LD_CC="${CC} -G -o"
306             SHARED_LD_CXX="${CXX} -G -o"
307             PIC_FLAG="-KPIC"
308         fi
309       ;;
310
311       *-*-darwin* )
312         AC_BAKEFILE_CREATE_FILE_SHARED_LD_SH
313         chmod +x shared-ld-sh
314
315         SHARED_LD_MODULE_CC="`pwd`/shared-ld-sh -bundle -headerpad_max_install_names -o"
316         SHARED_LD_MODULE_CXX="$SHARED_LD_MODULE_CC"
317
318         dnl Most apps benefit from being fully binded (its faster and static
319         dnl variables initialized at startup work).
320         dnl This can be done either with the exe linker flag -Wl,-bind_at_load
321         dnl or with a double stage link in order to create a single module
322         dnl "-init _wxWindowsDylibInit" not useful with lazy linking solved
323
324         dnl If using newer dev tools then there is a -single_module flag that
325         dnl we can use to do this for dylibs, otherwise we'll need to use a helper
326         dnl script.  Check the version of gcc to see which way we can go:
327         AC_CACHE_CHECK([for gcc 3.1 or later], bakefile_cv_gcc31, [
328            AC_TRY_COMPILE([],
329                [
330                    #if (__GNUC__ < 3) || \
331                        ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1))
332                        This is old gcc
333                    #endif
334                ],
335                [
336                    bakefile_cv_gcc31=yes
337                ],
338                [
339                    bakefile_cv_gcc31=no
340                ]
341            )
342         ])
343         if test "$bakefile_cv_gcc31" = "no"; then
344             dnl Use the shared-ld-sh helper script
345             SHARED_LD_CC="`pwd`/shared-ld-sh -dynamiclib -headerpad_max_install_names -o"
346             SHARED_LD_CXX="$SHARED_LD_CC"
347         else
348             dnl Use the -single_module flag and let the linker do it for us
349             SHARED_LD_CC="\${CC} -dynamiclib -single_module -headerpad_max_install_names -o"
350             SHARED_LD_CXX="\${CXX} -dynamiclib -single_module -headerpad_max_install_names -o"
351         fi
352
353         if test "x$GCC" == "xyes"; then
354             PIC_FLAG="-dynamic -fPIC"
355         fi
356         if test "x$XLCC" = "xyes"; then
357             PIC_FLAG="-dynamic -DPIC"
358         fi
359       ;;
360
361       *-*-aix* )
362         if test "x$GCC" = "xyes"; then
363             dnl at least gcc 2.95 warns that -fPIC is ignored when
364             dnl compiling each and every file under AIX which is annoying,
365             dnl so don't use it there (it's useless as AIX runs on
366             dnl position-independent architectures only anyhow)
367             PIC_FLAG=""
368
369             dnl -bexpfull is needed by AIX linker to export all symbols (by
370             dnl default it doesn't export any and even with -bexpall it
371             dnl doesn't export all C++ support symbols, e.g. vtable
372             dnl pointers) but it's only available starting from 5.1 (with
373             dnl maintenance pack 2, whatever this is), see
374             dnl http://www-128.ibm.com/developerworks/eserver/articles/gnu.html
375             case "${BAKEFILE_HOST}" in
376                 *-*-aix5* )
377                     LD_EXPFULL="-Wl,-bexpfull"
378                     ;;
379             esac
380
381             SHARED_LD_CC="\$(CC) -shared $LD_EXPFULL -o"
382             SHARED_LD_CXX="\$(CXX) -shared $LD_EXPFULL -o"
383         else
384             dnl FIXME: makeC++SharedLib is obsolete, what should we do for
385             dnl        recent AIX versions?
386             AC_CHECK_PROG(AIX_CXX_LD, makeC++SharedLib,
387                           makeC++SharedLib, /usr/lpp/xlC/bin/makeC++SharedLib)
388             SHARED_LD_CC="$AIX_CC_LD -p 0 -o"
389             SHARED_LD_CXX="$AIX_CXX_LD -p 0 -o"
390         fi
391       ;;
392
393       *-*-beos* )
394         dnl can't use gcc under BeOS for shared library creation because it
395         dnl complains about missing 'main'
396         SHARED_LD_CC="${LD} -nostart -o"
397         SHARED_LD_CXX="${LD} -nostart -o"
398       ;;
399
400       *-*-irix* )
401         dnl default settings are ok for gcc
402         if test "x$GCC" != "xyes"; then
403             PIC_FLAG="-KPIC"
404         fi
405       ;;
406
407       *-*-cygwin* | *-*-mingw32* )
408         PIC_FLAG=""
409         SHARED_LD_CC="\$(CC) -shared -o"
410         SHARED_LD_CXX="\$(CXX) -shared -o"
411         WINDOWS_IMPLIB=1
412       ;;
413
414       *-pc-os2_emx | *-pc-os2-emx )
415         SHARED_LD_CC="`pwd`/dllar.sh -libf INITINSTANCE -libf TERMINSTANCE -o"
416         SHARED_LD_CXX="`pwd`/dllar.sh -libf INITINSTANCE -libf TERMINSTANCE -o"
417         PIC_FLAG=""
418         AC_BAKEFILE_CREATE_FILE_DLLAR_SH
419         chmod +x dllar.sh
420       ;;
421
422       powerpc-apple-macos* | \
423       *-*-freebsd* | *-*-openbsd* | *-*-netbsd* | *-*-k*bsd*-gnu | \
424       *-*-sunos4* | \
425       *-*-osf* | \
426       *-*-dgux5* | \
427       *-*-sysv5* | \
428       *-pc-msdosdjgpp )
429         dnl defaults are ok
430       ;;
431
432       *)
433         AC_MSG_ERROR(unknown system type $BAKEFILE_HOST.)
434     esac
435
436     if test "x$PIC_FLAG" != "x" ; then
437         PIC_FLAG="$PIC_FLAG -DPIC"
438     fi
439
440     if test "x$SHARED_LD_MODULE_CC" = "x" ; then
441         SHARED_LD_MODULE_CC="$SHARED_LD_CC"
442     fi
443     if test "x$SHARED_LD_MODULE_CXX" = "x" ; then
444         SHARED_LD_MODULE_CXX="$SHARED_LD_CXX"
445     fi
446
447     AC_SUBST(SHARED_LD_CC)
448     AC_SUBST(SHARED_LD_CXX)
449     AC_SUBST(SHARED_LD_MODULE_CC)
450     AC_SUBST(SHARED_LD_MODULE_CXX)
451     AC_SUBST(PIC_FLAG)
452     AC_SUBST(WINDOWS_IMPLIB)
453 ])
454
455
456 dnl ---------------------------------------------------------------------------
457 dnl AC_BAKEFILE_SHARED_VERSIONS
458 dnl
459 dnl Detects linker options for attaching versions (sonames) to shared  libs.
460 dnl ---------------------------------------------------------------------------
461
462 AC_DEFUN([AC_BAKEFILE_SHARED_VERSIONS],
463 [
464     USE_SOVERSION=0
465     USE_SOVERLINUX=0
466     USE_SOVERSOLARIS=0
467     USE_SOVERCYGWIN=0
468     USE_SOSYMLINKS=0
469     USE_MACVERSION=0
470     SONAME_FLAG=
471
472     case "${BAKEFILE_HOST}" in
473       *-*-linux* | *-*-freebsd* | *-*-k*bsd*-gnu )
474         SONAME_FLAG="-Wl,-soname,"
475         USE_SOVERSION=1
476         USE_SOVERLINUX=1
477         USE_SOSYMLINKS=1
478       ;;
479
480       *-*-solaris2* )
481         SONAME_FLAG="-h "
482         USE_SOVERSION=1
483         USE_SOVERSOLARIS=1
484         USE_SOSYMLINKS=1
485       ;;
486
487       *-*-darwin* )
488         USE_MACVERSION=1
489         USE_SOVERSION=1
490         USE_SOSYMLINKS=1
491       ;;
492
493       *-*-cygwin* )
494         USE_SOVERSION=1
495         USE_SOVERCYGWIN=1
496       ;;
497     esac
498
499     AC_SUBST(USE_SOVERSION)
500     AC_SUBST(USE_SOVERLINUX)
501     AC_SUBST(USE_SOVERSOLARIS)
502     AC_SUBST(USE_SOVERCYGWIN)
503     AC_SUBST(USE_MACVERSION)
504     AC_SUBST(USE_SOSYMLINKS)
505     AC_SUBST(SONAME_FLAG)
506 ])
507
508
509 dnl ---------------------------------------------------------------------------
510 dnl AC_BAKEFILE_DEPS
511 dnl
512 dnl Detects available C/C++ dependency tracking options
513 dnl ---------------------------------------------------------------------------
514
515 AC_DEFUN([AC_BAKEFILE_DEPS],
516 [
517     AC_ARG_ENABLE([dependency-tracking],
518                   AS_HELP_STRING([--disable-dependency-tracking],
519                                  [don't use dependency tracking even if the compiler can]),
520                   [bk_use_trackdeps="$enableval"])
521     
522     AC_MSG_CHECKING([for dependency tracking method])
523
524     if test "x$bk_use_trackdeps" = "xno" ; then
525         DEPS_TRACKING=0
526         AC_MSG_RESULT([disabled])
527     else
528         DEPS_TRACKING=1
529
530         if test "x$GCC" = "xyes"; then
531             DEPSMODE=gcc
532             case "${BAKEFILE_HOST}" in
533                 *-*-darwin* )
534                     dnl -cpp-precomp (the default) conflicts with -MMD option
535                     dnl used by bk-deps (see also http://developer.apple.com/documentation/Darwin/Conceptual/PortingUnix/compiling/chapter_4_section_3.html)
536                     DEPSFLAG="-no-cpp-precomp -MMD"
537                 ;;
538                 * )
539                     DEPSFLAG="-MMD"
540                 ;;
541             esac
542             AC_MSG_RESULT([gcc])
543         elif test "x$MWCC" = "xyes"; then
544             DEPSMODE=mwcc
545             DEPSFLAG="-MM"
546             AC_MSG_RESULT([mwcc])
547         elif test "x$SUNCC" = "xyes"; then
548             DEPSMODE=unixcc
549             DEPSFLAG="-xM1"
550             AC_MSG_RESULT([Sun cc])
551         elif test "x$SGICC" = "xyes"; then
552             DEPSMODE=unixcc
553             DEPSFLAG="-M"
554             AC_MSG_RESULT([SGI cc])
555         elif test "x$HPCC" = "xyes"; then
556             DEPSMODE=unixcc
557             DEPSFLAG="+make"
558             AC_MSG_RESULT([HP cc])
559         elif test "x$COMPAQCC" = "xyes"; then
560             DEPSMODE=gcc
561             DEPSFLAG="-MD"
562             AC_MSG_RESULT([Compaq cc])
563         else
564             DEPS_TRACKING=0
565             AC_MSG_RESULT([none])
566         fi
567
568         if test $DEPS_TRACKING = 1 ; then
569             AC_BAKEFILE_CREATE_FILE_BK_DEPS
570             chmod +x bk-deps
571         fi
572     fi
573
574     AC_SUBST(DEPS_TRACKING)
575 ])
576
577 dnl ---------------------------------------------------------------------------
578 dnl AC_BAKEFILE_CHECK_BASIC_STUFF
579 dnl
580 dnl Checks for presence of basic programs, such as C and C++ compiler, "ranlib"
581 dnl or "install"
582 dnl ---------------------------------------------------------------------------
583
584 AC_DEFUN([AC_BAKEFILE_CHECK_BASIC_STUFF],
585 [
586     AC_PROG_RANLIB
587     AC_PROG_INSTALL
588     AC_PROG_LN_S
589
590     AC_PROG_MAKE_SET
591     AC_SUBST(MAKE_SET)
592     
593     AC_CHECK_TOOL(AR, ar, ar)
594     AC_CHECK_TOOL(STRIP, strip, :)
595     AC_CHECK_TOOL(NM, nm, :)
596
597     case ${BAKEFILE_HOST} in
598         *-hp-hpux* )
599             dnl HP-UX install doesn't handle the "-d" switch so don't
600             dnl use it there
601             INSTALL_DIR="mkdir -p"
602             ;;
603         *)  INSTALL_DIR="$INSTALL -d"
604             ;;
605     esac
606     AC_SUBST(INSTALL_DIR)
607
608     LDFLAGS_GUI=
609     case ${BAKEFILE_HOST} in
610         *-*-cygwin* | *-*-mingw32* )
611         LDFLAGS_GUI="-mwindows"
612     esac
613     AC_SUBST(LDFLAGS_GUI)
614 ])
615
616
617 dnl ---------------------------------------------------------------------------
618 dnl AC_BAKEFILE_RES_COMPILERS
619 dnl
620 dnl Checks for presence of resource compilers for win32 or mac
621 dnl ---------------------------------------------------------------------------
622
623 AC_DEFUN([AC_BAKEFILE_RES_COMPILERS],
624 [
625     case ${BAKEFILE_HOST} in 
626         *-*-cygwin* | *-*-mingw32* )
627             dnl Check for win32 resources compiler:
628             AC_CHECK_TOOL(WINDRES, windres)
629          ;;
630  
631       *-*-darwin* | powerpc-apple-macos* )
632             AC_CHECK_PROG(REZ, Rez, Rez, /Developer/Tools/Rez)
633             AC_CHECK_PROG(SETFILE, SetFile, SetFile, /Developer/Tools/SetFile)
634         ;;
635     esac
636
637     AC_SUBST(WINDRES)
638     AC_SUBST(REZ)
639     AC_SUBST(SETFILE)
640 ])
641
642 dnl ---------------------------------------------------------------------------
643 dnl AC_BAKEFILE_PRECOMP_HEADERS
644 dnl
645 dnl Check for precompiled headers support (GCC >= 3.4)
646 dnl ---------------------------------------------------------------------------
647
648 AC_DEFUN([AC_BAKEFILE_PRECOMP_HEADERS],
649 [
650
651     AC_ARG_ENABLE([precomp-headers],
652                   AS_HELP_STRING([--disable-precomp-headers],
653                                  [don't use precompiled headers even if compiler can]),
654                   [bk_use_pch="$enableval"])
655
656     GCC_PCH=0
657     ICC_PCH=0
658     USE_PCH=0
659
660     case ${BAKEFILE_HOST} in 
661         *-*-cygwin* )
662             dnl PCH support is broken in cygwin gcc because of unportable
663             dnl assumptions about mmap() in gcc code which make PCH generation
664             dnl fail erratically; disable PCH completely until this is fixed
665             bk_use_pch="no"
666             ;;
667     esac
668
669     if test "x$bk_use_pch" = "x" -o "x$bk_use_pch" = "xyes" ; then
670         if test "x$GCC" = "xyes"; then
671             dnl test if we have gcc-3.4:
672             AC_MSG_CHECKING([if the compiler supports precompiled headers])
673             AC_TRY_COMPILE([],
674                 [
675                     #if !defined(__GNUC__) || !defined(__GNUC_MINOR__)
676                         There is no PCH support
677                     #endif
678                     #if (__GNUC__ < 3)
679                         There is no PCH support
680                     #endif
681                     #if (__GNUC__ == 3) && \
682                        ((!defined(__APPLE_CC__) && (__GNUC_MINOR__ < 4)) || \
683                        ( defined(__APPLE_CC__) && (__GNUC_MINOR__ < 3))) || \
684                        ( defined(__INTEL_COMPILER) )
685                         There is no PCH support
686                     #endif
687                 ],
688                 [
689                     AC_MSG_RESULT([yes])
690                     GCC_PCH=1
691                 ],
692                 [
693                     AC_TRY_COMPILE([],
694                         [
695                             #if !defined(__INTEL_COMPILER) || \
696                                 (__INTEL_COMPILER < 800)
697                                 There is no PCH support
698                             #endif
699                         ],
700                         [
701                             AC_MSG_RESULT([yes])
702                             ICC_PCH=1
703                         ],
704                         [
705                             AC_MSG_RESULT([no])
706                         ])
707                 ])
708             if test $GCC_PCH = 1 -o $ICC_PCH = 1 ; then
709                 USE_PCH=1
710                 AC_BAKEFILE_CREATE_FILE_BK_MAKE_PCH
711                 chmod +x bk-make-pch
712             fi
713         fi
714     fi
715
716     AC_SUBST(GCC_PCH)
717     AC_SUBST(ICC_PCH)
718 ])
719
720
721
722 dnl ---------------------------------------------------------------------------
723 dnl AC_BAKEFILE([autoconf_inc.m4 inclusion])
724 dnl
725 dnl To be used in configure.in of any project using Bakefile-generated mks
726 dnl
727 dnl Behaviour can be modified by setting following variables:
728 dnl    BAKEFILE_CHECK_BASICS    set to "no" if you don't want bakefile to
729 dnl                             to perform check for basic tools like ranlib
730 dnl    BAKEFILE_HOST            set this to override host detection, defaults
731 dnl                             to ${host}
732 dnl    BAKEFILE_FORCE_PLATFORM  set to override platform detection
733 dnl
734 dnl Example usage:
735 dnl
736 dnl   AC_BAKEFILE([FOO(autoconf_inc.m4)])
737 dnl
738 dnl (replace FOO with m4_include above, aclocal would die otherwise)
739 dnl (yes, it's ugly, but thanks to a bug in aclocal, it's the only thing
740 dnl we can do...)
741 dnl ---------------------------------------------------------------------------
742
743 AC_DEFUN([AC_BAKEFILE],
744 [
745     AC_PREREQ(2.58)
746
747     if test "x$BAKEFILE_HOST" = "x"; then
748                if test "x${host}" = "x" ; then
749                        AC_MSG_ERROR([You must call the autoconf "CANONICAL_HOST" macro in your configure.ac (or .in) file.])
750                fi
751
752         BAKEFILE_HOST="${host}"
753     fi
754
755     if test "x$BAKEFILE_CHECK_BASICS" != "xno"; then
756         AC_BAKEFILE_CHECK_BASIC_STUFF
757     fi
758     AC_BAKEFILE_GNUMAKE
759     AC_BAKEFILE_PLATFORM
760     AC_BAKEFILE_PLATFORM_SPECIFICS
761     AC_BAKEFILE_SUFFIXES
762     AC_BAKEFILE_SHARED_LD
763     AC_BAKEFILE_SHARED_VERSIONS
764     AC_BAKEFILE_DEPS
765     AC_BAKEFILE_RES_COMPILERS
766
767     BAKEFILE_BAKEFILE_M4_VERSION="0.2.0"
768    
769     dnl includes autoconf_inc.m4:
770     $1
771     
772     if test "$BAKEFILE_AUTOCONF_INC_M4_VERSION" = "" ; then
773         AC_MSG_ERROR([No version found in autoconf_inc.m4 - bakefile macro was changed to take additional argument, perhaps configure.in wasn't updated (see the documentation)?])
774     fi
775     
776     if test "$BAKEFILE_BAKEFILE_M4_VERSION" != "$BAKEFILE_AUTOCONF_INC_M4_VERSION" ; then
777         AC_MSG_ERROR([Versions of Bakefile used to generate makefiles ($BAKEFILE_AUTOCONF_INC_M4_VERSION) and configure ($BAKEFILE_BAKEFILE_M4_VERSION) do not match.])
778     fi
779 ])
780         
781
782 dnl ---------------------------------------------------------------------------
783 dnl              Embedded copies of helper scripts follow:
784 dnl ---------------------------------------------------------------------------
785
786 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_DLLAR_SH],
787 [
788 dnl ===================== dllar.sh begins here =====================
789 dnl    (Created by merge-scripts.py from dllar.sh
790 dnl     file do not edit here!)
791 D='$'
792 cat <<EOF >dllar.sh
793 #!/bin/sh
794 #
795 # dllar - a tool to build both a .dll and an .a file
796 # from a set of object (.o) files for EMX/OS2.
797 #
798 #  Written by Andrew Zabolotny, bit@freya.etu.ru
799 #  Ported to Unix like shell by Stefan Neis, Stefan.Neis@t-online.de
800 #
801 #  This script will accept a set of files on the command line.
802 #  All the public symbols from the .o files will be exported into
803 #  a .DEF file, then linker will be run (through gcc) against them to
804 #  build a shared library consisting of all given .o files. All libraries
805 #  (.a) will be first decompressed into component .o files then act as
806 #  described above. You can optionally give a description (-d "description")
807 #  which will be put into .DLL. To see the list of accepted options (as well
808 #  as command-line format) simply run this program without options. The .DLL
809 #  is built to be imported by name (there is no guarantee that new versions
810 #  of the library you build will have same ordinals for same symbols).
811 #
812 #  dllar is free software; you can redistribute it and/or modify
813 #  it under the terms of the GNU General Public License as published by
814 #  the Free Software Foundation; either version 2, or (at your option)
815 #  any later version.
816 #
817 #  dllar is distributed in the hope that it will be useful,
818 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
819 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
820 #  GNU General Public License for more details.
821 #
822 #  You should have received a copy of the GNU General Public License
823 #  along with dllar; see the file COPYING.  If not, write to the Free
824 #  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
825 #  02111-1307, USA.
826
827 # To successfuly run this program you will need:
828 #  - Current drive should have LFN support (HPFS, ext2, network, etc)
829 #    (Sometimes dllar generates filenames which won't fit 8.3 scheme)
830 #  - gcc
831 #    (used to build the .dll)
832 #  - emxexp
833 #    (used to create .def file from .o files)
834 #  - emximp
835 #    (used to create .a file from .def file)
836 #  - GNU text utilites (cat, sort, uniq)
837 #    used to process emxexp output
838 #  - GNU file utilities (mv, rm)
839 #  - GNU sed
840 #  - lxlite (optional, see flag below)
841 #    (used for general .dll cleanup)
842 #
843
844 flag_USE_LXLITE=1;
845
846 #
847 # helper functions
848 # basnam, variant of basename, which does _not_ remove the path, _iff_
849 #                              second argument (suffix to remove) is given
850 basnam(){
851     case ${D}# in
852     1)
853         echo ${D}1 | sed 's/.*\\///' | sed 's/.*\\\\//'
854         ;;
855     2)
856         echo ${D}1 | sed 's/'${D}2'${D}//'
857         ;;
858     *)
859         echo "error in basnam ${D}*"
860         exit 8
861         ;;
862     esac
863 }
864
865 # Cleanup temporary files and output
866 CleanUp() {
867     cd ${D}curDir
868     for i in ${D}inputFiles ; do
869         case ${D}i in
870         *!)
871             rm -rf \`basnam ${D}i !\`
872             ;;
873         *)
874             ;;
875         esac
876     done
877
878     # Kill result in case of failure as there is just to many stupid make/nmake
879     # things out there which doesn't do this.
880     if @<:@ ${D}# -eq 0 @:>@; then
881         rm -f ${D}arcFile ${D}arcFile2 ${D}defFile ${D}dllFile
882     fi
883 }
884
885 # Print usage and exit script with rc=1.
886 PrintHelp() {
887  echo 'Usage: dllar.sh @<:@-o@<:@utput@:>@ output_file@:>@ @<:@-i@<:@mport@:>@ importlib_name@:>@'
888  echo '       @<:@-name-mangler-script script.sh@:>@'
889  echo '       @<:@-d@<:@escription@:>@ "dll descrption"@:>@ @<:@-cc "CC"@:>@ @<:@-f@<:@lags@:>@ "CFLAGS"@:>@'
890  echo '       @<:@-ord@<:@inals@:>@@:>@ -ex@<:@clude@:>@ "symbol(s)"'
891  echo '       @<:@-libf@<:@lags@:>@ "{INIT|TERM}{GLOBAL|INSTANCE}"@:>@ @<:@-nocrt@<:@dll@:>@@:>@ @<:@-nolxl@<:@ite@:>@@:>@'
892  echo '       @<:@*.o@:>@ @<:@*.a@:>@'
893  echo '*> "output_file" should have no extension.'
894  echo '   If it has the .o, .a or .dll extension, it is automatically removed.'
895  echo '   The import library name is derived from this and is set to "name".a,'
896  echo '   unless overridden by -import'
897  echo '*> "importlib_name" should have no extension.'
898  echo '   If it has the .o, or .a extension, it is automatically removed.'
899  echo '   This name is used as the import library name and may be longer and'
900  echo '   more descriptive than the DLL name which has to follow the old '
901  echo '   8.3 convention of FAT.'
902  echo '*> "script.sh may be given to override the output_file name by a'
903  echo '   different name. It is mainly useful if the regular make process'
904  echo '   of some package does not take into account OS/2 restriction of'
905  echo '   DLL name lengths. It takes the importlib name as input and is'
906  echo '   supposed to procude a shorter name as output. The script should'
907  echo '   expect to get importlib_name without extension and should produce'
908  echo '   a (max.) 8 letter name without extension.'
909  echo '*> "cc" is used to use another GCC executable.   (default: gcc.exe)'
910  echo '*> "flags" should be any set of valid GCC flags. (default: -s -Zcrtdll)'
911  echo '   These flags will be put at the start of GCC command line.'
912  echo '*> -ord@<:@inals@:>@ tells dllar to export entries by ordinals. Be careful.'
913  echo '*> -ex@<:@clude@:>@ defines symbols which will not be exported. You can define'
914  echo '   multiple symbols, for example -ex "myfunc yourfunc _GLOBAL*".'
915  echo '   If the last character of a symbol is "*", all symbols beginning'
916  echo '   with the prefix before "*" will be exclude, (see _GLOBAL* above).'
917  echo '*> -libf@<:@lags@:>@ can be used to add INITGLOBAL/INITINSTANCE and/or'
918  echo '   TERMGLOBAL/TERMINSTANCE flags to the dynamically-linked library.'
919  echo '*> -nocrt@<:@dll@:>@ switch will disable linking the library against emx''s'
920  echo '   C runtime DLLs.'
921  echo '*> -nolxl@<:@ite@:>@ switch will disable running lxlite on the resulting DLL.'
922  echo '*> All other switches (for example -L./ or -lmylib) will be passed'
923  echo '   unchanged to GCC at the end of command line.'
924  echo '*> If you create a DLL from a library and you do not specify -o,'
925  echo '   the basename for DLL and import library will be set to library name,'
926  echo '   the initial library will be renamed to 'name'_s.a (_s for static)'
927  echo '   i.e. "dllar gcc.a" will create gcc.dll and gcc.a, and the initial'
928  echo '   library will be renamed into gcc_s.a.'
929  echo '--------'
930  echo 'Example:'
931  echo '   dllar -o gcc290.dll libgcc.a -d "GNU C runtime library" -ord'
932  echo '    -ex "__main __ctordtor*" -libf "INITINSTANCE TERMINSTANCE"'
933  CleanUp
934  exit 1
935 }
936
937 # Execute a command.
938 # If exit code of the commnad <> 0 CleanUp() is called and we'll exit the script.
939 # @Uses    Whatever CleanUp() uses.
940 doCommand() {
941     echo "${D}*"
942     eval ${D}*
943     rcCmd=${D}?
944
945     if @<:@ ${D}rcCmd -ne 0 @:>@; then
946         echo "command failed, exit code="${D}rcCmd
947         CleanUp
948         exit ${D}rcCmd
949     fi
950 }
951
952 # main routine
953 # setup globals
954 cmdLine=${D}*
955 outFile=""
956 outimpFile=""
957 inputFiles=""
958 renameScript=""
959 description=""
960 CC=gcc.exe
961 CFLAGS="-s -Zcrtdll"
962 EXTRA_CFLAGS=""
963 EXPORT_BY_ORDINALS=0
964 exclude_symbols=""
965 library_flags=""
966 curDir=\`pwd\`
967 curDirS=curDir
968 case ${D}curDirS in
969 */)
970   ;;
971 *)
972   curDirS=${D}{curDirS}"/"
973   ;;
974 esac
975 # Parse commandline
976 libsToLink=0
977 omfLinking=0
978 while @<:@ ${D}1 @:>@; do
979     case ${D}1 in
980     -ord*)
981         EXPORT_BY_ORDINALS=1;
982         ;;
983     -o*)
984         shift
985         outFile=${D}1
986         ;;
987     -i*)
988         shift
989         outimpFile=${D}1
990         ;;
991     -name-mangler-script)
992         shift
993         renameScript=${D}1
994         ;;
995     -d*)
996         shift
997         description=${D}1
998         ;;
999     -f*)
1000         shift
1001         CFLAGS=${D}1
1002         ;;
1003     -c*)
1004         shift
1005         CC=${D}1
1006         ;;
1007     -h*)
1008         PrintHelp
1009         ;;
1010     -ex*)
1011         shift
1012         exclude_symbols=${D}{exclude_symbols}${D}1" "
1013         ;;
1014     -libf*)
1015         shift
1016         library_flags=${D}{library_flags}${D}1" "
1017         ;;
1018     -nocrt*)
1019         CFLAGS="-s"
1020         ;;
1021     -nolxl*)
1022         flag_USE_LXLITE=0
1023         ;;
1024     -* | /*)
1025         case ${D}1 in
1026         -L* | -l*)
1027             libsToLink=1
1028             ;;
1029         -Zomf)
1030             omfLinking=1
1031             ;;
1032         *)
1033             ;;
1034         esac
1035         EXTRA_CFLAGS=${D}{EXTRA_CFLAGS}" "${D}1
1036         ;;
1037     *.dll)
1038         EXTRA_CFLAGS="${D}{EXTRA_CFLAGS} \`basnam ${D}1 .dll\`"
1039         if @<:@ ${D}omfLinking -eq 1 @:>@; then
1040             EXTRA_CFLAGS="${D}{EXTRA_CFLAGS}.lib"
1041         else
1042             EXTRA_CFLAGS="${D}{EXTRA_CFLAGS}.a"
1043         fi
1044         ;;
1045     *)
1046         found=0;
1047         if @<:@ ${D}libsToLink -ne 0 @:>@; then
1048             EXTRA_CFLAGS=${D}{EXTRA_CFLAGS}" "${D}1
1049         else
1050             for file in ${D}1 ; do
1051                 if @<:@ -f ${D}file @:>@; then
1052                     inputFiles="${D}{inputFiles} ${D}file"
1053                     found=1
1054                 fi
1055             done
1056             if @<:@ ${D}found -eq 0 @:>@; then
1057                 echo "ERROR: No file(s) found: "${D}1
1058                 exit 8
1059             fi
1060         fi
1061       ;;
1062     esac
1063     shift
1064 done # iterate cmdline words
1065
1066 #
1067 if @<:@ -z "${D}inputFiles" @:>@; then
1068     echo "dllar: no input files"
1069     PrintHelp
1070 fi
1071
1072 # Now extract all .o files from .a files
1073 newInputFiles=""
1074 for file in ${D}inputFiles ; do
1075     case ${D}file in
1076     *.a | *.lib)
1077         case ${D}file in
1078         *.a)
1079             suffix=".a"
1080             AR="ar"
1081             ;;
1082         *.lib)
1083             suffix=".lib"
1084             AR="emxomfar"
1085             EXTRA_CFLAGS="${D}EXTRA_CFLAGS -Zomf"
1086             ;;
1087         *)
1088             ;;
1089         esac
1090         dirname=\`basnam ${D}file ${D}suffix\`"_%"
1091         mkdir ${D}dirname
1092         if @<:@ ${D}? -ne 0 @:>@; then
1093             echo "Failed to create subdirectory ./${D}dirname"
1094             CleanUp
1095             exit 8;
1096         fi
1097         # Append '!' to indicate archive
1098         newInputFiles="${D}newInputFiles ${D}{dirname}!"
1099         doCommand "cd ${D}dirname; ${D}AR x ../${D}file"
1100         cd ${D}curDir
1101         found=0;
1102         for subfile in ${D}dirname/*.o* ; do
1103             if @<:@ -f ${D}subfile @:>@; then
1104                 found=1
1105                 if @<:@ -s ${D}subfile @:>@; then
1106                     # FIXME: This should be: is file size > 32 byte, _not_ > 0!
1107                     newInputFiles="${D}newInputFiles ${D}subfile"
1108                 fi
1109             fi
1110         done
1111         if @<:@ ${D}found -eq 0 @:>@; then
1112             echo "WARNING: there are no files in archive \\'${D}file\\'"
1113         fi
1114         ;;
1115     *)
1116         newInputFiles="${D}{newInputFiles} ${D}file"
1117         ;;
1118     esac
1119 done
1120 inputFiles="${D}newInputFiles"
1121
1122 # Output filename(s).
1123 do_backup=0;
1124 if @<:@ -z ${D}outFile @:>@; then
1125     do_backup=1;
1126     set outFile ${D}inputFiles; outFile=${D}2
1127 fi
1128
1129 # If it is an archive, remove the '!' and the '_%' suffixes
1130 case ${D}outFile in
1131 *_%!)
1132     outFile=\`basnam ${D}outFile _%!\`
1133     ;;
1134 *)
1135     ;;
1136 esac
1137 case ${D}outFile in
1138 *.dll)
1139     outFile=\`basnam ${D}outFile .dll\`
1140     ;;
1141 *.DLL)
1142     outFile=\`basnam ${D}outFile .DLL\`
1143     ;;
1144 *.o)
1145     outFile=\`basnam ${D}outFile .o\`
1146     ;;
1147 *.obj)
1148     outFile=\`basnam ${D}outFile .obj\`
1149     ;;
1150 *.a)
1151     outFile=\`basnam ${D}outFile .a\`
1152     ;;
1153 *.lib)
1154     outFile=\`basnam ${D}outFile .lib\`
1155     ;;
1156 *)
1157     ;;
1158 esac
1159 case ${D}outimpFile in
1160 *.a)
1161     outimpFile=\`basnam ${D}outimpFile .a\`
1162     ;;
1163 *.lib)
1164     outimpFile=\`basnam ${D}outimpFile .lib\`
1165     ;;
1166 *)
1167     ;;
1168 esac
1169 if @<:@ -z ${D}outimpFile @:>@; then
1170     outimpFile=${D}outFile
1171 fi
1172 defFile="${D}{outFile}.def"
1173 arcFile="${D}{outimpFile}.a"
1174 arcFile2="${D}{outimpFile}.lib"
1175
1176 #create ${D}dllFile as something matching 8.3 restrictions,
1177 if @<:@ -z ${D}renameScript @:>@ ; then
1178     dllFile="${D}outFile"
1179 else
1180     dllFile=\`${D}renameScript ${D}outimpFile\`
1181 fi
1182
1183 if @<:@ ${D}do_backup -ne 0 @:>@ ; then
1184     if @<:@ -f ${D}arcFile @:>@ ; then
1185         doCommand "mv ${D}arcFile ${D}{outFile}_s.a"
1186     fi
1187     if @<:@ -f ${D}arcFile2 @:>@ ; then
1188         doCommand "mv ${D}arcFile2 ${D}{outFile}_s.lib"
1189     fi
1190 fi
1191
1192 # Extract public symbols from all the object files.
1193 tmpdefFile=${D}{defFile}_%
1194 rm -f ${D}tmpdefFile
1195 for file in ${D}inputFiles ; do
1196     case ${D}file in
1197     *!)
1198         ;;
1199     *)
1200         doCommand "emxexp -u ${D}file >> ${D}tmpdefFile"
1201         ;;
1202     esac
1203 done
1204
1205 # Create the def file.
1206 rm -f ${D}defFile
1207 echo "LIBRARY \`basnam ${D}dllFile\` ${D}library_flags" >> ${D}defFile
1208 dllFile="${D}{dllFile}.dll"
1209 if @<:@ ! -z ${D}description @:>@; then
1210     echo "DESCRIPTION  \\"${D}{description}\\"" >> ${D}defFile
1211 fi
1212 echo "EXPORTS" >> ${D}defFile
1213
1214 doCommand "cat ${D}tmpdefFile | sort.exe | uniq.exe > ${D}{tmpdefFile}%"
1215 grep -v "^ *;" < ${D}{tmpdefFile}% | grep -v "^ *${D}" >${D}tmpdefFile
1216
1217 # Checks if the export is ok or not.
1218 for word in ${D}exclude_symbols; do
1219     grep -v ${D}word < ${D}tmpdefFile >${D}{tmpdefFile}%
1220     mv ${D}{tmpdefFile}% ${D}tmpdefFile
1221 done
1222
1223
1224 if @<:@ ${D}EXPORT_BY_ORDINALS -ne 0 @:>@; then
1225     sed "=" < ${D}tmpdefFile | \\
1226     sed '
1227       N
1228       : loop
1229       s/^\\(@<:@0-9@:>@\\+\\)\\(@<:@^;@:>@*\\)\\(;.*\\)\\?/\\2 @\\1 NONAME/
1230       t loop
1231     ' > ${D}{tmpdefFile}%
1232     grep -v "^ *${D}" < ${D}{tmpdefFile}% > ${D}tmpdefFile
1233 else
1234     rm -f ${D}{tmpdefFile}%
1235 fi
1236 cat ${D}tmpdefFile >> ${D}defFile
1237 rm -f ${D}tmpdefFile
1238
1239 # Do linking, create implib, and apply lxlite.
1240 gccCmdl="";
1241 for file in ${D}inputFiles ; do
1242     case ${D}file in
1243     *!)
1244         ;;
1245     *)
1246         gccCmdl="${D}gccCmdl ${D}file"
1247         ;;
1248     esac
1249 done
1250 doCommand "${D}CC ${D}CFLAGS -Zdll -o ${D}dllFile ${D}defFile ${D}gccCmdl ${D}EXTRA_CFLAGS"
1251 touch "${D}{outFile}.dll"
1252
1253 doCommand "emximp -o ${D}arcFile ${D}defFile"
1254 if @<:@ ${D}flag_USE_LXLITE -ne 0 @:>@; then
1255     add_flags="";
1256     if @<:@ ${D}EXPORT_BY_ORDINALS -ne 0 @:>@; then
1257         add_flags="-ynd"
1258     fi
1259     doCommand "lxlite -cs -t: -mrn -mln ${D}add_flags ${D}dllFile"
1260 fi
1261 doCommand "emxomf -s -l ${D}arcFile"
1262
1263 # Successful exit.
1264 CleanUp 1
1265 exit 0
1266 EOF
1267 dnl ===================== dllar.sh ends here =====================
1268 ])
1269
1270 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_BK_DEPS],
1271 [
1272 dnl ===================== bk-deps begins here =====================
1273 dnl    (Created by merge-scripts.py from bk-deps
1274 dnl     file do not edit here!)
1275 D='$'
1276 cat <<EOF >bk-deps
1277 #!/bin/sh
1278
1279 # This script is part of Bakefile (http://bakefile.sourceforge.net) autoconf
1280 # script. It is used to track C/C++ files dependencies in portable way.
1281 #
1282 # Permission is given to use this file in any way.
1283
1284 DEPSMODE=${DEPSMODE}
1285 DEPSDIR=.deps
1286 DEPSFLAG="${DEPSFLAG}"
1287
1288 mkdir -p ${D}DEPSDIR
1289
1290 if test ${D}DEPSMODE = gcc ; then
1291     ${D}* ${D}{DEPSFLAG}
1292     status=${D}?
1293     if test ${D}{status} != 0 ; then
1294         exit ${D}{status}
1295     fi
1296     # move created file to the location we want it in:
1297     while test ${D}# -gt 0; do
1298         case "${D}1" in
1299             -o )
1300                 shift
1301                 objfile=${D}1
1302             ;;
1303             -* )
1304             ;;
1305             * )
1306                 srcfile=${D}1
1307             ;;
1308         esac
1309         shift
1310     done
1311     depfile=\`basename ${D}srcfile | sed -e 's/\\..*${D}/.d/g'\`
1312     depobjname=\`echo ${D}depfile |sed -e 's/\\.d/.o/g'\`
1313     if test -f ${D}depfile ; then
1314         sed -e "s,${D}depobjname:,${D}objfile:,g" ${D}depfile >${D}{DEPSDIR}/${D}{objfile}.d
1315         rm -f ${D}depfile
1316     else
1317         # "g++ -MMD -o fooobj.o foosrc.cpp" produces fooobj.d
1318         depfile=\`basename ${D}objfile | sed -e 's/\\..*${D}/.d/g'\`
1319         if test ! -f ${D}depfile ; then
1320             # "cxx -MD -o fooobj.o foosrc.cpp" creates fooobj.o.d (Compaq C++)
1321             depfile="${D}objfile.d"
1322         fi
1323         if test -f ${D}depfile ; then
1324             sed -e "/^${D}objfile/!s,${D}depobjname:,${D}objfile:,g" ${D}depfile >${D}{DEPSDIR}/${D}{objfile}.d
1325             rm -f ${D}depfile
1326         fi
1327     fi
1328     exit 0
1329 elif test ${D}DEPSMODE = mwcc ; then
1330     ${D}* || exit ${D}?
1331     # Run mwcc again with -MM and redirect into the dep file we want
1332     # NOTE: We can't use shift here because we need ${D}* to be valid
1333     prevarg=
1334     for arg in ${D}* ; do
1335         if test "${D}prevarg" = "-o"; then
1336             objfile=${D}arg
1337         else
1338             case "${D}arg" in
1339                 -* )
1340                 ;;
1341                 * )
1342                     srcfile=${D}arg
1343                 ;;
1344             esac
1345         fi
1346         prevarg="${D}arg"
1347     done
1348     ${D}* ${D}DEPSFLAG >${D}{DEPSDIR}/${D}{objfile}.d
1349     exit 0
1350 elif test ${D}DEPSMODE = unixcc; then
1351     ${D}* || exit ${D}?
1352     # Run compiler again with deps flag and redirect into the dep file.
1353     # It doesn't work if the '-o FILE' option is used, but without it the
1354     # dependency file will contain the wrong name for the object. So it is
1355     # removed from the command line, and the dep file is fixed with sed.
1356     cmd=""
1357     while test ${D}# -gt 0; do
1358         case "${D}1" in
1359             -o )
1360                 shift
1361                 objfile=${D}1
1362             ;;
1363             * )
1364                 eval arg${D}#=\\${D}1
1365                 cmd="${D}cmd \\${D}arg${D}#"
1366             ;;
1367         esac
1368         shift
1369     done
1370     eval "${D}cmd ${D}DEPSFLAG" | sed "s|.*:|${D}objfile:|" >${D}{DEPSDIR}/${D}{objfile}.d
1371     exit 0
1372 else
1373     ${D}*
1374     exit ${D}?
1375 fi
1376 EOF
1377 dnl ===================== bk-deps ends here =====================
1378 ])
1379
1380 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_SHARED_LD_SH],
1381 [
1382 dnl ===================== shared-ld-sh begins here =====================
1383 dnl    (Created by merge-scripts.py from shared-ld-sh
1384 dnl     file do not edit here!)
1385 D='$'
1386 cat <<EOF >shared-ld-sh
1387 #!/bin/sh
1388 #-----------------------------------------------------------------------------
1389 #-- Name:        distrib/mac/shared-ld-sh
1390 #-- Purpose:     Link a mach-o dynamic shared library for Darwin / Mac OS X
1391 #-- Author:      Gilles Depeyrot
1392 #-- Copyright:   (c) 2002 Gilles Depeyrot
1393 #-- Licence:     any use permitted
1394 #-----------------------------------------------------------------------------
1395
1396 verbose=0
1397 args=""
1398 objects=""
1399 linking_flag="-dynamiclib"
1400 ldargs="-r -keep_private_externs -nostdlib"
1401
1402 while test ${D}# -gt 0; do
1403     case ${D}1 in
1404
1405        -v)
1406         verbose=1
1407         ;;
1408
1409        -o|-compatibility_version|-current_version|-framework|-undefined|-install_name)
1410         # collect these options and values
1411         args="${D}{args} ${D}1 ${D}2"
1412         shift
1413         ;;
1414        
1415        -s|-Wl,*)
1416         # collect these load args
1417         ldargs="${D}{ldargs} ${D}1"
1418         ;;
1419
1420        -l*|-L*|-flat_namespace|-headerpad_max_install_names)
1421         # collect these options
1422         args="${D}{args} ${D}1"
1423         ;;
1424
1425        -dynamiclib|-bundle)
1426         linking_flag="${D}1"
1427         ;;
1428
1429        -*)
1430         echo "shared-ld: unhandled option '${D}1'"
1431         exit 1
1432         ;;
1433
1434         *.o | *.a | *.dylib)
1435         # collect object files
1436         objects="${D}{objects} ${D}1"
1437         ;;
1438
1439         *)
1440         echo "shared-ld: unhandled argument '${D}1'"
1441         exit 1
1442         ;;
1443
1444     esac
1445     shift
1446 done
1447
1448 status=0
1449
1450 #
1451 # Link one module containing all the others
1452 #
1453 if test ${D}{verbose} = 1; then
1454     echo "c++ ${D}{ldargs} ${D}{objects} -o master.${D}${D}.o"
1455 fi
1456 c++ ${D}{ldargs} ${D}{objects} -o master.${D}${D}.o
1457 status=${D}?
1458
1459 #
1460 # Link the shared library from the single module created, but only if the
1461 # previous command didn't fail:
1462 #
1463 if test ${D}{status} = 0; then
1464     if test ${D}{verbose} = 1; then
1465         echo "c++ ${D}{linking_flag} master.${D}${D}.o ${D}{args}"
1466     fi
1467     c++ ${D}{linking_flag} master.${D}${D}.o ${D}{args}
1468     status=${D}?
1469 fi
1470
1471 #
1472 # Remove intermediate module
1473 #
1474 rm -f master.${D}${D}.o
1475
1476 exit ${D}status
1477 EOF
1478 dnl ===================== shared-ld-sh ends here =====================
1479 ])
1480
1481 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_BK_MAKE_PCH],
1482 [
1483 dnl ===================== bk-make-pch begins here =====================
1484 dnl    (Created by merge-scripts.py from bk-make-pch
1485 dnl     file do not edit here!)
1486 D='$'
1487 cat <<EOF >bk-make-pch
1488 #!/bin/sh
1489
1490 # This script is part of Bakefile (http://bakefile.sourceforge.net) autoconf
1491 # script. It is used to generated precompiled headers.
1492 #
1493 # Permission is given to use this file in any way.
1494
1495 outfile="${D}{1}"
1496 header="${D}{2}"
1497 shift
1498 shift
1499
1500 compiler=""
1501 headerfile=""
1502
1503 while test ${D}{#} -gt 0; do
1504     add_to_cmdline=1
1505     case "${D}{1}" in
1506         -I* )
1507             incdir=\`echo ${D}{1} | sed -e 's/-I\\(.*\\)/\\1/g'\`
1508             if test "x${D}{headerfile}" = "x" -a -f "${D}{incdir}/${D}{header}" ; then
1509                 headerfile="${D}{incdir}/${D}{header}"
1510             fi
1511         ;;
1512         -use-pch|-use_pch )
1513             shift
1514             add_to_cmdline=0
1515         ;;
1516     esac
1517     if test ${D}add_to_cmdline = 1 ; then
1518         compiler="${D}{compiler} ${D}{1}"
1519     fi
1520     shift
1521 done
1522
1523 if test "x${D}{headerfile}" = "x" ; then
1524     echo "error: can't find header ${D}{header} in include paths" >&2
1525 else
1526     if test -f ${D}{outfile} ; then
1527         rm -f ${D}{outfile}
1528     else
1529         mkdir -p \`dirname ${D}{outfile}\`
1530     fi
1531     depsfile=".deps/\`echo ${D}{outfile} | tr '/.' '__'\`.d"
1532     mkdir -p .deps
1533     if test "x${GCC_PCH}" = "x1" ; then
1534         # can do this because gcc is >= 3.4:
1535         ${D}{compiler} -o ${D}{outfile} -MMD -MF "${D}{depsfile}" "${D}{headerfile}"
1536     elif test "x${ICC_PCH}" = "x1" ; then
1537         filename=pch_gen-${D}${D}
1538         file=${D}{filename}.c
1539         dfile=${D}{filename}.d
1540         cat > ${D}file <<EOT
1541 #include "${D}header"
1542 EOT
1543         # using -MF icc complains about differing command lines in creation/use
1544         ${D}compiler -c -create_pch ${D}outfile -MMD ${D}file && \\
1545           sed -e "s,^.*:,${D}outfile:," -e "s, ${D}file,," < ${D}dfile > ${D}depsfile && \\
1546           rm -f ${D}file ${D}dfile ${D}{filename}.o
1547     fi
1548     exit ${D}{?}
1549 fi
1550 EOF
1551 dnl ===================== bk-make-pch ends here =====================
1552 ])