disable PCH under cygwin, it doesn't work even with the very latest cygwin gcc
[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                         #error 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                        #error 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_MSG_CHECKING([for dependency tracking method])
518     DEPS_TRACKING=1
519
520     if test "x$GCC" = "xyes"; then
521         DEPSMODE=gcc
522         case "${BAKEFILE_HOST}" in
523             *-*-darwin* )
524                 dnl -cpp-precomp (the default) conflicts with -MMD option
525                 dnl used by bk-deps (see also http://developer.apple.com/documentation/Darwin/Conceptual/PortingUnix/compiling/chapter_4_section_3.html)
526                 DEPSFLAG="-no-cpp-precomp -MMD"
527             ;;
528             * )
529                 DEPSFLAG="-MMD"
530             ;;
531         esac
532         AC_MSG_RESULT([gcc])
533     elif test "x$MWCC" = "xyes"; then
534         DEPSMODE=mwcc
535         DEPSFLAG="-MM"
536         AC_MSG_RESULT([mwcc])
537     elif test "x$SUNCC" = "xyes"; then
538         DEPSMODE=unixcc
539         DEPSFLAG="-xM1"
540         AC_MSG_RESULT([Sun cc])
541     elif test "x$SGICC" = "xyes"; then
542         DEPSMODE=unixcc
543         DEPSFLAG="-M"
544         AC_MSG_RESULT([SGI cc])
545     elif test "x$HPCC" = "xyes"; then
546         DEPSMODE=unixcc
547         DEPSFLAG="+make"
548         AC_MSG_RESULT([HP cc])
549     elif test "x$COMPAQCC" = "xyes"; then
550         DEPSMODE=gcc
551         DEPSFLAG="-MD"
552         AC_MSG_RESULT([Compaq cc])
553     else
554         DEPS_TRACKING=0
555         AC_MSG_RESULT([none])
556     fi
557
558     if test $DEPS_TRACKING = 1 ; then
559         AC_BAKEFILE_CREATE_FILE_BK_DEPS
560         chmod +x bk-deps
561     fi
562
563     AC_SUBST(DEPS_TRACKING)
564 ])
565
566 dnl ---------------------------------------------------------------------------
567 dnl AC_BAKEFILE_CHECK_BASIC_STUFF
568 dnl
569 dnl Checks for presence of basic programs, such as C and C++ compiler, "ranlib"
570 dnl or "install"
571 dnl ---------------------------------------------------------------------------
572
573 AC_DEFUN([AC_BAKEFILE_CHECK_BASIC_STUFF],
574 [
575     AC_PROG_RANLIB
576     AC_PROG_INSTALL
577     AC_PROG_LN_S
578
579     AC_PROG_MAKE_SET
580     AC_SUBST(MAKE_SET)
581     
582     AC_CHECK_TOOL(AR, ar, ar)
583     AC_CHECK_TOOL(STRIP, strip, :)
584     AC_CHECK_TOOL(NM, nm, :)
585
586     case ${BAKEFILE_HOST} in
587         *-hp-hpux* )
588             dnl HP-UX install doesn't handle the "-d" switch so don't
589             dnl use it there
590             INSTALL_DIR="mkdir -p"
591             ;;
592         *)  INSTALL_DIR="$INSTALL -d"
593             ;;
594     esac
595     AC_SUBST(INSTALL_DIR)
596
597     LDFLAGS_GUI=
598     case ${BAKEFILE_HOST} in
599         *-*-cygwin* | *-*-mingw32* )
600         LDFLAGS_GUI="-mwindows"
601     esac
602     AC_SUBST(LDFLAGS_GUI)
603 ])
604
605
606 dnl ---------------------------------------------------------------------------
607 dnl AC_BAKEFILE_RES_COMPILERS
608 dnl
609 dnl Checks for presence of resource compilers for win32 or mac
610 dnl ---------------------------------------------------------------------------
611
612 AC_DEFUN([AC_BAKEFILE_RES_COMPILERS],
613 [
614     RESCOMP=
615     SETFILE=
616
617     case ${BAKEFILE_HOST} in 
618         *-*-cygwin* | *-*-mingw32* )
619             dnl Check for win32 resources compiler:
620             if test "$build" != "$host" ; then
621                 RESCOMP=$host_alias-windres
622             else
623                 AC_CHECK_PROG(RESCOMP, windres, windres, windres)
624             fi
625          ;;
626  
627       *-*-darwin* | powerpc-apple-macos* )
628             AC_CHECK_PROG(RESCOMP, Rez, Rez, /Developer/Tools/Rez)
629             AC_CHECK_PROG(SETFILE, SetFile, SetFile, /Developer/Tools/SetFile)
630         ;;
631     esac
632
633     AC_SUBST(RESCOMP)
634     AC_SUBST(SETFILE)
635 ])
636
637 dnl ---------------------------------------------------------------------------
638 dnl AC_BAKEFILE_PRECOMP_HEADERS
639 dnl
640 dnl Check for precompiled headers support (GCC >= 3.4)
641 dnl ---------------------------------------------------------------------------
642
643 AC_DEFUN([AC_BAKEFILE_PRECOMP_HEADERS],
644 [
645
646     AC_ARG_ENABLE([precomp-headers],
647                   AS_HELP_STRING([--disable-precomp-headers],
648                                  [don't use precompiled headers even if compiler can]),
649                   [bk_use_pch="$enableval"])
650
651     GCC_PCH=0
652
653     case ${BAKEFILE_HOST} in 
654         *-*-cygwin* )
655             dnl PCH support is broken in cygwin gcc because of unportable
656             dnl assumptions about mmap() in gcc code which make PCH generation
657             dnl fail erratically; disable PCH completely until this is fixed
658             bk_use_pch="no"
659             ;;
660     esac
661
662     if test "x$bk_use_pch" = "x" -o "x$bk_use_pch" = "xyes" ; then
663         if test "x$GCC" = "xyes"; then
664             dnl test if we have gcc-3.4:
665             AC_MSG_CHECKING([if the compiler supports precompiled headers])
666             AC_TRY_COMPILE([],
667                 [
668                     #if !defined(__GNUC__) || !defined(__GNUC_MINOR__)
669                         #error "no pch support"
670                     #endif
671                     #if (__GNUC__ < 3)
672                         #error "no pch support"
673                     #endif
674                     #if (__GNUC__ == 3) && \
675                        ((!defined(__APPLE_CC__) && (__GNUC_MINOR__ < 4)) || \
676                        ( defined(__APPLE_CC__) && (__GNUC_MINOR__ < 3)))
677                         #error "no pch support"
678                     #endif
679                 ],
680                 [
681                     AC_MSG_RESULT([yes])
682                     GCC_PCH=1
683                 ],
684                 [
685                     AC_MSG_RESULT([no])
686                 ])
687             if test $GCC_PCH = 1 ; then
688                 AC_BAKEFILE_CREATE_FILE_BK_MAKE_PCH
689                 chmod +x bk-make-pch
690             fi
691         fi
692     fi
693
694     AC_SUBST(GCC_PCH)
695 ])
696
697
698
699 dnl ---------------------------------------------------------------------------
700 dnl AC_BAKEFILE([autoconf_inc.m4 inclusion])
701 dnl
702 dnl To be used in configure.in of any project using Bakefile-generated mks
703 dnl
704 dnl Behaviour can be modified by setting following variables:
705 dnl    BAKEFILE_CHECK_BASICS    set to "no" if you don't want bakefile to
706 dnl                             to perform check for basic tools like ranlib
707 dnl    BAKEFILE_HOST            set this to override host detection, defaults
708 dnl                             to ${host}
709 dnl    BAKEFILE_FORCE_PLATFORM  set to override platform detection
710 dnl
711 dnl Example usage:
712 dnl
713 dnl   AC_BAKEFILE([FOO(autoconf_inc.m4)])
714 dnl
715 dnl (replace FOO with m4_include above, aclocal would die otherwise)
716 dnl (yes, it's ugly, but thanks to a bug in aclocal, it's the only thing
717 dnl we can do...)
718 dnl ---------------------------------------------------------------------------
719
720 AC_DEFUN([AC_BAKEFILE],
721 [
722     AC_PREREQ(2.58)
723
724     if test "x$BAKEFILE_HOST" = "x"; then
725         BAKEFILE_HOST="${host}"
726     fi
727
728     if test "x$BAKEFILE_CHECK_BASICS" != "xno"; then
729         AC_BAKEFILE_CHECK_BASIC_STUFF
730     fi
731     AC_BAKEFILE_GNUMAKE
732     AC_BAKEFILE_PLATFORM
733     AC_BAKEFILE_PLATFORM_SPECIFICS
734     AC_BAKEFILE_SUFFIXES
735     AC_BAKEFILE_SHARED_LD
736     AC_BAKEFILE_SHARED_VERSIONS
737     AC_BAKEFILE_DEPS
738     AC_BAKEFILE_RES_COMPILERS
739
740     BAKEFILE_BAKEFILE_M4_VERSION="0.1.9"
741    
742     dnl includes autoconf_inc.m4:
743     $1
744     
745     if test "$BAKEFILE_AUTOCONF_INC_M4_VERSION" = "" ; then
746         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)?])
747     fi
748     
749     if test "$BAKEFILE_BAKEFILE_M4_VERSION" != "$BAKEFILE_AUTOCONF_INC_M4_VERSION" ; then
750         AC_MSG_ERROR([Versions of Bakefile used to generate makefiles ($BAKEFILE_AUTOCONF_INC_M4_VERSION) and configure ($BAKEFILE_BAKEFILE_M4_VERSION) do not match.])
751     fi
752 ])
753         
754
755 dnl ---------------------------------------------------------------------------
756 dnl              Embedded copies of helper scripts follow:
757 dnl ---------------------------------------------------------------------------
758
759 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_DLLAR_SH],
760 [
761 dnl ===================== dllar.sh begins here =====================
762 dnl    (Created by merge-scripts.py from dllar.sh
763 dnl     file do not edit here!)
764 D='$'
765 cat <<EOF >dllar.sh
766 #!/bin/sh
767 #
768 # dllar - a tool to build both a .dll and an .a file
769 # from a set of object (.o) files for EMX/OS2.
770 #
771 #  Written by Andrew Zabolotny, bit@freya.etu.ru
772 #  Ported to Unix like shell by Stefan Neis, Stefan.Neis@t-online.de
773 #
774 #  This script will accept a set of files on the command line.
775 #  All the public symbols from the .o files will be exported into
776 #  a .DEF file, then linker will be run (through gcc) against them to
777 #  build a shared library consisting of all given .o files. All libraries
778 #  (.a) will be first decompressed into component .o files then act as
779 #  described above. You can optionally give a description (-d "description")
780 #  which will be put into .DLL. To see the list of accepted options (as well
781 #  as command-line format) simply run this program without options. The .DLL
782 #  is built to be imported by name (there is no guarantee that new versions
783 #  of the library you build will have same ordinals for same symbols).
784 #
785 #  dllar is free software; you can redistribute it and/or modify
786 #  it under the terms of the GNU General Public License as published by
787 #  the Free Software Foundation; either version 2, or (at your option)
788 #  any later version.
789 #
790 #  dllar is distributed in the hope that it will be useful,
791 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
792 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
793 #  GNU General Public License for more details.
794 #
795 #  You should have received a copy of the GNU General Public License
796 #  along with dllar; see the file COPYING.  If not, write to the Free
797 #  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
798 #  02111-1307, USA.
799
800 # To successfuly run this program you will need:
801 #  - Current drive should have LFN support (HPFS, ext2, network, etc)
802 #    (Sometimes dllar generates filenames which won't fit 8.3 scheme)
803 #  - gcc
804 #    (used to build the .dll)
805 #  - emxexp
806 #    (used to create .def file from .o files)
807 #  - emximp
808 #    (used to create .a file from .def file)
809 #  - GNU text utilites (cat, sort, uniq)
810 #    used to process emxexp output
811 #  - GNU file utilities (mv, rm)
812 #  - GNU sed
813 #  - lxlite (optional, see flag below)
814 #    (used for general .dll cleanup)
815 #
816
817 flag_USE_LXLITE=1;
818
819 #
820 # helper functions
821 # basnam, variant of basename, which does _not_ remove the path, _iff_
822 #                              second argument (suffix to remove) is given
823 basnam(){
824     case ${D}# in
825     1)
826         echo ${D}1 | sed 's/.*\\///' | sed 's/.*\\\\//'
827         ;;
828     2)
829         echo ${D}1 | sed 's/'${D}2'${D}//'
830         ;;
831     *)
832         echo "error in basnam ${D}*"
833         exit 8
834         ;;
835     esac
836 }
837
838 # Cleanup temporary files and output
839 CleanUp() {
840     cd ${D}curDir
841     for i in ${D}inputFiles ; do
842         case ${D}i in
843         *!)
844             rm -rf \`basnam ${D}i !\`
845             ;;
846         *)
847             ;;
848         esac
849     done
850
851     # Kill result in case of failure as there is just to many stupid make/nmake
852     # things out there which doesn't do this.
853     if @<:@ ${D}# -eq 0 @:>@; then
854         rm -f ${D}arcFile ${D}arcFile2 ${D}defFile ${D}dllFile
855     fi
856 }
857
858 # Print usage and exit script with rc=1.
859 PrintHelp() {
860  echo 'Usage: dllar.sh @<:@-o@<:@utput@:>@ output_file@:>@ @<:@-i@<:@mport@:>@ importlib_name@:>@'
861  echo '       @<:@-name-mangler-script script.sh@:>@'
862  echo '       @<:@-d@<:@escription@:>@ "dll descrption"@:>@ @<:@-cc "CC"@:>@ @<:@-f@<:@lags@:>@ "CFLAGS"@:>@'
863  echo '       @<:@-ord@<:@inals@:>@@:>@ -ex@<:@clude@:>@ "symbol(s)"'
864  echo '       @<:@-libf@<:@lags@:>@ "{INIT|TERM}{GLOBAL|INSTANCE}"@:>@ @<:@-nocrt@<:@dll@:>@@:>@ @<:@-nolxl@<:@ite@:>@@:>@'
865  echo '       @<:@*.o@:>@ @<:@*.a@:>@'
866  echo '*> "output_file" should have no extension.'
867  echo '   If it has the .o, .a or .dll extension, it is automatically removed.'
868  echo '   The import library name is derived from this and is set to "name".a,'
869  echo '   unless overridden by -import'
870  echo '*> "importlib_name" should have no extension.'
871  echo '   If it has the .o, or .a extension, it is automatically removed.'
872  echo '   This name is used as the import library name and may be longer and'
873  echo '   more descriptive than the DLL name which has to follow the old '
874  echo '   8.3 convention of FAT.'
875  echo '*> "script.sh may be given to override the output_file name by a'
876  echo '   different name. It is mainly useful if the regular make process'
877  echo '   of some package does not take into account OS/2 restriction of'
878  echo '   DLL name lengths. It takes the importlib name as input and is'
879  echo '   supposed to procude a shorter name as output. The script should'
880  echo '   expect to get importlib_name without extension and should produce'
881  echo '   a (max.) 8 letter name without extension.'
882  echo '*> "cc" is used to use another GCC executable.   (default: gcc.exe)'
883  echo '*> "flags" should be any set of valid GCC flags. (default: -s -Zcrtdll)'
884  echo '   These flags will be put at the start of GCC command line.'
885  echo '*> -ord@<:@inals@:>@ tells dllar to export entries by ordinals. Be careful.'
886  echo '*> -ex@<:@clude@:>@ defines symbols which will not be exported. You can define'
887  echo '   multiple symbols, for example -ex "myfunc yourfunc _GLOBAL*".'
888  echo '   If the last character of a symbol is "*", all symbols beginning'
889  echo '   with the prefix before "*" will be exclude, (see _GLOBAL* above).'
890  echo '*> -libf@<:@lags@:>@ can be used to add INITGLOBAL/INITINSTANCE and/or'
891  echo '   TERMGLOBAL/TERMINSTANCE flags to the dynamically-linked library.'
892  echo '*> -nocrt@<:@dll@:>@ switch will disable linking the library against emx''s'
893  echo '   C runtime DLLs.'
894  echo '*> -nolxl@<:@ite@:>@ switch will disable running lxlite on the resulting DLL.'
895  echo '*> All other switches (for example -L./ or -lmylib) will be passed'
896  echo '   unchanged to GCC at the end of command line.'
897  echo '*> If you create a DLL from a library and you do not specify -o,'
898  echo '   the basename for DLL and import library will be set to library name,'
899  echo '   the initial library will be renamed to 'name'_s.a (_s for static)'
900  echo '   i.e. "dllar gcc.a" will create gcc.dll and gcc.a, and the initial'
901  echo '   library will be renamed into gcc_s.a.'
902  echo '--------'
903  echo 'Example:'
904  echo '   dllar -o gcc290.dll libgcc.a -d "GNU C runtime library" -ord'
905  echo '    -ex "__main __ctordtor*" -libf "INITINSTANCE TERMINSTANCE"'
906  CleanUp
907  exit 1
908 }
909
910 # Execute a command.
911 # If exit code of the commnad <> 0 CleanUp() is called and we'll exit the script.
912 # @Uses    Whatever CleanUp() uses.
913 doCommand() {
914     echo "${D}*"
915     eval ${D}*
916     rcCmd=${D}?
917
918     if @<:@ ${D}rcCmd -ne 0 @:>@; then
919         echo "command failed, exit code="${D}rcCmd
920         CleanUp
921         exit ${D}rcCmd
922     fi
923 }
924
925 # main routine
926 # setup globals
927 cmdLine=${D}*
928 outFile=""
929 outimpFile=""
930 inputFiles=""
931 renameScript=""
932 description=""
933 CC=gcc.exe
934 CFLAGS="-s -Zcrtdll"
935 EXTRA_CFLAGS=""
936 EXPORT_BY_ORDINALS=0
937 exclude_symbols=""
938 library_flags=""
939 curDir=\`pwd\`
940 curDirS=curDir
941 case ${D}curDirS in
942 */)
943   ;;
944 *)
945   curDirS=${D}{curDirS}"/"
946   ;;
947 esac
948 # Parse commandline
949 libsToLink=0
950 omfLinking=0
951 while @<:@ ${D}1 @:>@; do
952     case ${D}1 in
953     -ord*)
954         EXPORT_BY_ORDINALS=1;
955         ;;
956     -o*)
957         shift
958         outFile=${D}1
959         ;;
960     -i*)
961         shift
962         outimpFile=${D}1
963         ;;
964     -name-mangler-script)
965         shift
966         renameScript=${D}1
967         ;;
968     -d*)
969         shift
970         description=${D}1
971         ;;
972     -f*)
973         shift
974         CFLAGS=${D}1
975         ;;
976     -c*)
977         shift
978         CC=${D}1
979         ;;
980     -h*)
981         PrintHelp
982         ;;
983     -ex*)
984         shift
985         exclude_symbols=${D}{exclude_symbols}${D}1" "
986         ;;
987     -libf*)
988         shift
989         library_flags=${D}{library_flags}${D}1" "
990         ;;
991     -nocrt*)
992         CFLAGS="-s"
993         ;;
994     -nolxl*)
995         flag_USE_LXLITE=0
996         ;;
997     -* | /*)
998         case ${D}1 in
999         -L* | -l*)
1000             libsToLink=1
1001             ;;
1002         -Zomf)
1003             omfLinking=1
1004             ;;
1005         *)
1006             ;;
1007         esac
1008         EXTRA_CFLAGS=${D}{EXTRA_CFLAGS}" "${D}1
1009         ;;
1010     *.dll)
1011         EXTRA_CFLAGS="${D}{EXTRA_CFLAGS} \`basnam ${D}1 .dll\`"
1012         if @<:@ ${D}omfLinking -eq 1 @:>@; then
1013             EXTRA_CFLAGS="${D}{EXTRA_CFLAGS}.lib"
1014         else
1015             EXTRA_CFLAGS="${D}{EXTRA_CFLAGS}.a"
1016         fi
1017         ;;
1018     *)
1019         found=0;
1020         if @<:@ ${D}libsToLink -ne 0 @:>@; then
1021             EXTRA_CFLAGS=${D}{EXTRA_CFLAGS}" "${D}1
1022         else
1023             for file in ${D}1 ; do
1024                 if @<:@ -f ${D}file @:>@; then
1025                     inputFiles="${D}{inputFiles} ${D}file"
1026                     found=1
1027                 fi
1028             done
1029             if @<:@ ${D}found -eq 0 @:>@; then
1030                 echo "ERROR: No file(s) found: "${D}1
1031                 exit 8
1032             fi
1033         fi
1034       ;;
1035     esac
1036     shift
1037 done # iterate cmdline words
1038
1039 #
1040 if @<:@ -z "${D}inputFiles" @:>@; then
1041     echo "dllar: no input files"
1042     PrintHelp
1043 fi
1044
1045 # Now extract all .o files from .a files
1046 newInputFiles=""
1047 for file in ${D}inputFiles ; do
1048     case ${D}file in
1049     *.a | *.lib)
1050         case ${D}file in
1051         *.a)
1052             suffix=".a"
1053             AR="ar"
1054             ;;
1055         *.lib)
1056             suffix=".lib"
1057             AR="emxomfar"
1058             EXTRA_CFLAGS="${D}EXTRA_CFLAGS -Zomf"
1059             ;;
1060         *)
1061             ;;
1062         esac
1063         dirname=\`basnam ${D}file ${D}suffix\`"_%"
1064         mkdir ${D}dirname
1065         if @<:@ ${D}? -ne 0 @:>@; then
1066             echo "Failed to create subdirectory ./${D}dirname"
1067             CleanUp
1068             exit 8;
1069         fi
1070         # Append '!' to indicate archive
1071         newInputFiles="${D}newInputFiles ${D}{dirname}!"
1072         doCommand "cd ${D}dirname; ${D}AR x ../${D}file"
1073         cd ${D}curDir
1074         found=0;
1075         for subfile in ${D}dirname/*.o* ; do
1076             if @<:@ -f ${D}subfile @:>@; then
1077                 found=1
1078                 if @<:@ -s ${D}subfile @:>@; then
1079                     # FIXME: This should be: is file size > 32 byte, _not_ > 0!
1080                     newInputFiles="${D}newInputFiles ${D}subfile"
1081                 fi
1082             fi
1083         done
1084         if @<:@ ${D}found -eq 0 @:>@; then
1085             echo "WARNING: there are no files in archive \\'${D}file\\'"
1086         fi
1087         ;;
1088     *)
1089         newInputFiles="${D}{newInputFiles} ${D}file"
1090         ;;
1091     esac
1092 done
1093 inputFiles="${D}newInputFiles"
1094
1095 # Output filename(s).
1096 do_backup=0;
1097 if @<:@ -z ${D}outFile @:>@; then
1098     do_backup=1;
1099     set outFile ${D}inputFiles; outFile=${D}2
1100 fi
1101
1102 # If it is an archive, remove the '!' and the '_%' suffixes
1103 case ${D}outFile in
1104 *_%!)
1105     outFile=\`basnam ${D}outFile _%!\`
1106     ;;
1107 *)
1108     ;;
1109 esac
1110 case ${D}outFile in
1111 *.dll)
1112     outFile=\`basnam ${D}outFile .dll\`
1113     ;;
1114 *.DLL)
1115     outFile=\`basnam ${D}outFile .DLL\`
1116     ;;
1117 *.o)
1118     outFile=\`basnam ${D}outFile .o\`
1119     ;;
1120 *.obj)
1121     outFile=\`basnam ${D}outFile .obj\`
1122     ;;
1123 *.a)
1124     outFile=\`basnam ${D}outFile .a\`
1125     ;;
1126 *.lib)
1127     outFile=\`basnam ${D}outFile .lib\`
1128     ;;
1129 *)
1130     ;;
1131 esac
1132 case ${D}outimpFile in
1133 *.a)
1134     outimpFile=\`basnam ${D}outimpFile .a\`
1135     ;;
1136 *.lib)
1137     outimpFile=\`basnam ${D}outimpFile .lib\`
1138     ;;
1139 *)
1140     ;;
1141 esac
1142 if @<:@ -z ${D}outimpFile @:>@; then
1143     outimpFile=${D}outFile
1144 fi
1145 defFile="${D}{outFile}.def"
1146 arcFile="${D}{outimpFile}.a"
1147 arcFile2="${D}{outimpFile}.lib"
1148
1149 #create ${D}dllFile as something matching 8.3 restrictions,
1150 if @<:@ -z ${D}renameScript @:>@ ; then
1151     dllFile="${D}outFile"
1152 else
1153     dllFile=\`${D}renameScript ${D}outimpFile\`
1154 fi
1155
1156 if @<:@ ${D}do_backup -ne 0 @:>@ ; then
1157     if @<:@ -f ${D}arcFile @:>@ ; then
1158         doCommand "mv ${D}arcFile ${D}{outFile}_s.a"
1159     fi
1160     if @<:@ -f ${D}arcFile2 @:>@ ; then
1161         doCommand "mv ${D}arcFile2 ${D}{outFile}_s.lib"
1162     fi
1163 fi
1164
1165 # Extract public symbols from all the object files.
1166 tmpdefFile=${D}{defFile}_%
1167 rm -f ${D}tmpdefFile
1168 for file in ${D}inputFiles ; do
1169     case ${D}file in
1170     *!)
1171         ;;
1172     *)
1173         doCommand "emxexp -u ${D}file >> ${D}tmpdefFile"
1174         ;;
1175     esac
1176 done
1177
1178 # Create the def file.
1179 rm -f ${D}defFile
1180 echo "LIBRARY \`basnam ${D}dllFile\` ${D}library_flags" >> ${D}defFile
1181 dllFile="${D}{dllFile}.dll"
1182 if @<:@ ! -z ${D}description @:>@; then
1183     echo "DESCRIPTION  \\"${D}{description}\\"" >> ${D}defFile
1184 fi
1185 echo "EXPORTS" >> ${D}defFile
1186
1187 doCommand "cat ${D}tmpdefFile | sort.exe | uniq.exe > ${D}{tmpdefFile}%"
1188 grep -v "^ *;" < ${D}{tmpdefFile}% | grep -v "^ *${D}" >${D}tmpdefFile
1189
1190 # Checks if the export is ok or not.
1191 for word in ${D}exclude_symbols; do
1192     grep -v ${D}word < ${D}tmpdefFile >${D}{tmpdefFile}%
1193     mv ${D}{tmpdefFile}% ${D}tmpdefFile
1194 done
1195
1196
1197 if @<:@ ${D}EXPORT_BY_ORDINALS -ne 0 @:>@; then
1198     sed "=" < ${D}tmpdefFile | \\
1199     sed '
1200       N
1201       : loop
1202       s/^\\(@<:@0-9@:>@\\+\\)\\(@<:@^;@:>@*\\)\\(;.*\\)\\?/\\2 @\\1 NONAME/
1203       t loop
1204     ' > ${D}{tmpdefFile}%
1205     grep -v "^ *${D}" < ${D}{tmpdefFile}% > ${D}tmpdefFile
1206 else
1207     rm -f ${D}{tmpdefFile}%
1208 fi
1209 cat ${D}tmpdefFile >> ${D}defFile
1210 rm -f ${D}tmpdefFile
1211
1212 # Do linking, create implib, and apply lxlite.
1213 gccCmdl="";
1214 for file in ${D}inputFiles ; do
1215     case ${D}file in
1216     *!)
1217         ;;
1218     *)
1219         gccCmdl="${D}gccCmdl ${D}file"
1220         ;;
1221     esac
1222 done
1223 doCommand "${D}CC ${D}CFLAGS -Zdll -o ${D}dllFile ${D}defFile ${D}gccCmdl ${D}EXTRA_CFLAGS"
1224 touch "${D}{outFile}.dll"
1225
1226 doCommand "emximp -o ${D}arcFile ${D}defFile"
1227 if @<:@ ${D}flag_USE_LXLITE -ne 0 @:>@; then
1228     add_flags="";
1229     if @<:@ ${D}EXPORT_BY_ORDINALS -ne 0 @:>@; then
1230         add_flags="-ynd"
1231     fi
1232     doCommand "lxlite -cs -t: -mrn -mln ${D}add_flags ${D}dllFile"
1233 fi
1234 doCommand "emxomf -s -l ${D}arcFile"
1235
1236 # Successful exit.
1237 CleanUp 1
1238 exit 0
1239 EOF
1240 dnl ===================== dllar.sh ends here =====================
1241 ])
1242
1243 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_BK_DEPS],
1244 [
1245 dnl ===================== bk-deps begins here =====================
1246 dnl    (Created by merge-scripts.py from bk-deps
1247 dnl     file do not edit here!)
1248 D='$'
1249 cat <<EOF >bk-deps
1250 #!/bin/sh
1251
1252 # This script is part of Bakefile (http://bakefile.sourceforge.net) autoconf
1253 # script. It is used to track C/C++ files dependencies in portable way.
1254 #
1255 # Permission is given to use this file in any way.
1256
1257 DEPSMODE=${DEPSMODE}
1258 DEPSDIR=.deps
1259 DEPSFLAG="${DEPSFLAG}"
1260
1261 mkdir -p ${D}DEPSDIR
1262
1263 if test ${D}DEPSMODE = gcc ; then
1264     ${D}* ${D}{DEPSFLAG}
1265     status=${D}?
1266     if test ${D}{status} != 0 ; then
1267         exit ${D}{status}
1268     fi
1269     # move created file to the location we want it in:
1270     while test ${D}# -gt 0; do
1271         case "${D}1" in
1272             -o )
1273                 shift
1274                 objfile=${D}1
1275             ;;
1276             -* )
1277             ;;
1278             * )
1279                 srcfile=${D}1
1280             ;;
1281         esac
1282         shift
1283     done
1284     depfile=\`basename ${D}srcfile | sed -e 's/\\..*${D}/.d/g'\`
1285     depobjname=\`echo ${D}depfile |sed -e 's/\\.d/.o/g'\`
1286     if test -f ${D}depfile ; then
1287         sed -e "s,${D}depobjname:,${D}objfile:,g" ${D}depfile >${D}{DEPSDIR}/${D}{objfile}.d
1288         rm -f ${D}depfile
1289     else
1290         # "g++ -MMD -o fooobj.o foosrc.cpp" produces fooobj.d
1291         depfile=\`basename ${D}objfile | sed -e 's/\\..*${D}/.d/g'\`
1292         if test ! -f ${D}depfile ; then
1293             # "cxx -MD -o fooobj.o foosrc.cpp" creates fooobj.o.d (Compaq C++)
1294             depfile="${D}objfile.d"
1295         fi
1296         if test -f ${D}depfile ; then
1297             sed -e "/^${D}objfile/!s,${D}depobjname:,${D}objfile:,g" ${D}depfile >${D}{DEPSDIR}/${D}{objfile}.d
1298             rm -f ${D}depfile
1299         fi
1300     fi
1301     exit 0
1302 elif test ${D}DEPSMODE = mwcc ; then
1303     ${D}* || exit ${D}?
1304     # Run mwcc again with -MM and redirect into the dep file we want
1305     # NOTE: We can't use shift here because we need ${D}* to be valid
1306     prevarg=
1307     for arg in ${D}* ; do
1308         if test "${D}prevarg" = "-o"; then
1309             objfile=${D}arg
1310         else
1311             case "${D}arg" in
1312                 -* )
1313                 ;;
1314                 * )
1315                     srcfile=${D}arg
1316                 ;;
1317             esac
1318         fi
1319         prevarg="${D}arg"
1320     done
1321     ${D}* ${D}DEPSFLAG >${D}{DEPSDIR}/${D}{objfile}.d
1322     exit 0
1323 elif test ${D}DEPSMODE = unixcc; then
1324     ${D}* || exit ${D}?
1325     # Run compiler again with deps flag and redirect into the dep file.
1326     # It doesn't work if the '-o FILE' option is used, but without it the
1327     # dependency file will contain the wrong name for the object. So it is
1328     # removed from the command line, and the dep file is fixed with sed.
1329     cmd=""
1330     while test ${D}# -gt 0; do
1331         case "${D}1" in
1332             -o )
1333                 shift
1334                 objfile=${D}1
1335             ;;
1336             * )
1337                 eval arg${D}#=\\${D}1
1338                 cmd="${D}cmd \\${D}arg${D}#"
1339             ;;
1340         esac
1341         shift
1342     done
1343     eval "${D}cmd ${D}DEPSFLAG" | sed "s|.*:|${D}objfile:|" >${D}{DEPSDIR}/${D}{objfile}.d
1344     exit 0
1345 else
1346     ${D}*
1347     exit ${D}?
1348 fi
1349 EOF
1350 dnl ===================== bk-deps ends here =====================
1351 ])
1352
1353 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_SHARED_LD_SH],
1354 [
1355 dnl ===================== shared-ld-sh begins here =====================
1356 dnl    (Created by merge-scripts.py from shared-ld-sh
1357 dnl     file do not edit here!)
1358 D='$'
1359 cat <<EOF >shared-ld-sh
1360 #!/bin/sh
1361 #-----------------------------------------------------------------------------
1362 #-- Name:        distrib/mac/shared-ld-sh
1363 #-- Purpose:     Link a mach-o dynamic shared library for Darwin / Mac OS X
1364 #-- Author:      Gilles Depeyrot
1365 #-- Copyright:   (c) 2002 Gilles Depeyrot
1366 #-- Licence:     any use permitted
1367 #-----------------------------------------------------------------------------
1368
1369 verbose=0
1370 args=""
1371 objects=""
1372 linking_flag="-dynamiclib"
1373 ldargs="-r -keep_private_externs -nostdlib"
1374
1375 while test ${D}# -gt 0; do
1376     case ${D}1 in
1377
1378        -v)
1379         verbose=1
1380         ;;
1381
1382        -o|-compatibility_version|-current_version|-framework|-undefined|-install_name)
1383         # collect these options and values
1384         args="${D}{args} ${D}1 ${D}2"
1385         shift
1386         ;;
1387        
1388        -s|-Wl,*)
1389         # collect these load args
1390         ldargs="${D}{ldargs} ${D}1"
1391         ;;
1392
1393        -l*|-L*|-flat_namespace|-headerpad_max_install_names)
1394         # collect these options
1395         args="${D}{args} ${D}1"
1396         ;;
1397
1398        -dynamiclib|-bundle)
1399         linking_flag="${D}1"
1400         ;;
1401
1402        -*)
1403         echo "shared-ld: unhandled option '${D}1'"
1404         exit 1
1405         ;;
1406
1407         *.o | *.a | *.dylib)
1408         # collect object files
1409         objects="${D}{objects} ${D}1"
1410         ;;
1411
1412         *)
1413         echo "shared-ld: unhandled argument '${D}1'"
1414         exit 1
1415         ;;
1416
1417     esac
1418     shift
1419 done
1420
1421 status=0
1422
1423 #
1424 # Link one module containing all the others
1425 #
1426 if test ${D}{verbose} = 1; then
1427     echo "c++ ${D}{ldargs} ${D}{objects} -o master.${D}${D}.o"
1428 fi
1429 c++ ${D}{ldargs} ${D}{objects} -o master.${D}${D}.o
1430 status=${D}?
1431
1432 #
1433 # Link the shared library from the single module created, but only if the
1434 # previous command didn't fail:
1435 #
1436 if test ${D}{status} = 0; then
1437     if test ${D}{verbose} = 1; then
1438         echo "c++ ${D}{linking_flag} master.${D}${D}.o ${D}{args}"
1439     fi
1440     c++ ${D}{linking_flag} master.${D}${D}.o ${D}{args}
1441     status=${D}?
1442 fi
1443
1444 #
1445 # Remove intermediate module
1446 #
1447 rm -f master.${D}${D}.o
1448
1449 exit ${D}status
1450 EOF
1451 dnl ===================== shared-ld-sh ends here =====================
1452 ])
1453
1454 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_BK_MAKE_PCH],
1455 [
1456 dnl ===================== bk-make-pch begins here =====================
1457 dnl    (Created by merge-scripts.py from bk-make-pch
1458 dnl     file do not edit here!)
1459 D='$'
1460 cat <<EOF >bk-make-pch
1461 #!/bin/sh
1462
1463 # This script is part of Bakefile (http://bakefile.sourceforge.net) autoconf
1464 # script. It is used to generated precompiled headers.
1465 #
1466 # Permission is given to use this file in any way.
1467
1468 outfile="${D}{1}"
1469 header="${D}{2}"
1470 shift
1471 shift
1472
1473 compiler=
1474 headerfile=
1475 while test ${D}{#} -gt 0; do
1476     case "${D}{1}" in
1477         -I* )
1478             incdir=\`echo ${D}{1} | sed -e 's/-I\\(.*\\)/\\1/g'\`
1479             if test "x${D}{headerfile}" = "x" -a -f "${D}{incdir}/${D}{header}" ; then
1480                 headerfile="${D}{incdir}/${D}{header}"
1481             fi
1482         ;;
1483     esac
1484     compiler="${D}{compiler} ${D}{1}"
1485     shift
1486 done
1487
1488 if test "x${D}{headerfile}" = "x" ; then
1489     echo "error: can't find header ${D}{header} in include paths" >2
1490 else
1491     if test -f ${D}{outfile} ; then
1492         rm -f ${D}{outfile}
1493     else
1494         mkdir -p \`dirname ${D}{outfile}\`
1495     fi
1496     depsfile=".deps/\`echo ${D}{outfile} | tr '/.' '__'\`.d"
1497     mkdir -p .deps
1498     # can do this because gcc is >= 3.4:
1499     ${D}{compiler} -o ${D}{outfile} -MMD -MF "${D}{depsfile}" "${D}{headerfile}"
1500     exit ${D}{?}
1501 fi
1502 EOF
1503 dnl ===================== bk-make-pch ends here =====================
1504 ])