1dnl configure.ac for MCPP   2003/11, 2008/11  kmatsui
2dnl Process this file with autoconf to produce a configure script.
3
4dnl WARNING: This script does not assume cross-compiling.
5dnl To cross-compile you must edit here and there of this file.
6
7AC_INIT( mcpp, 2.7.2, kmatsui@t3.rim.or.jp)
8AC_CONFIG_SRCDIR( src/main.c)
9AM_CONFIG_HEADER( src/config.h)
10AC_CONFIG_AUX_DIR( config)
11AC_CANONICAL_TARGET
12AM_INIT_AUTOMAKE( no-dependencies)
13
14dnl Checks for programs.
15
16AC_PROG_CC
17AC_PROG_CPP
18AC_PROG_INSTALL
19AC_PROG_EGREP
20AC_LIBTOOL_WIN32_DLL
21AC_PROG_LIBTOOL
22
23dnl WARNING: Configure must check the characteristics of target compiler.
24dnl MCPP may modify the behavior of the target compiler-system.
25dnl You must uninstall MCPP before re-configuring.
26
27AC_MSG_CHECKING( [whether the cpp is target preprocessor])
28mcpp=`$CPP $CFLAGS -xc -v /dev/null 2>&1 | grep 'MCPP'`
29if test "x$mcpp" != x; then
30    AC_MSG_ERROR( Do 'make uninstall' before configuring again.)
31fi
32AC_MSG_RESULT( yes)
33
34dnl Define host system and target system
35
36case $host_os in
37linux*)
38    AC_DEFINE( [HOST_SYSTEM], [SYS_LINUX], [Define the host system.])
39    ac_c_define_HOST_SYSTEM=[SYS_LINUX]
40    ;;
41freebsd*)
42    AC_DEFINE( [HOST_SYSTEM], [SYS_FREEBSD])
43    ac_c_define_HOST_SYSTEM=[SYS_FREEBSD]
44    ;;
45darwin*)
46    AC_DEFINE( [HOST_SYSTEM], [SYS_MAC])
47    ac_c_define_HOST_SYSTEM=[SYS_MAC]
48    ;;
49cygwin*)
50    AC_DEFINE( [HOST_SYSTEM], [SYS_CYGWIN])
51    ac_c_define_HOST_SYSTEM=[SYS_CYGWIN]
52    ;;
53mingw*)
54    AC_DEFINE( [HOST_SYSTEM], [SYS_MINGW])
55    ac_c_define_HOST_SYSTEM=[SYS_MINGW]
56    ;;
57*)
58    AC_MSG_WARN( [Unsupported host OS, assuming to be an UNIX variant])
59    AC_DEFINE( [HOST_SYSTEM], [SYS_UNIX])
60    ac_c_define_HOST_SYSTEM=[SYS_UNIX]
61    ;;
62esac
63host_system=$ac_c_define_HOST_SYSTEM
64
65case $target_os in
66linux*)
67    AC_DEFINE( [SYSTEM], [SYS_LINUX], [Define the target system.])
68    ;;
69freebsd*)
70    AC_DEFINE( [SYSTEM], [SYS_FREEBSD])
71    ;;
72darwin*)
73    AC_DEFINE( [SYSTEM], [SYS_MAC])
74    ;;
75cygwin*)
76    AC_DEFINE( [SYSTEM], [SYS_CYGWIN])
77    ;;
78mingw*)
79    AC_DEFINE( [SYSTEM], [SYS_MINGW])
80    ;;
81*)
82    AC_MSG_WARN( Unsupported target OS, assuming to be an UNIX variant)
83    AC_DEFINE( [SYSTEM], [SYS_UNIX])
84    ;;
85esac
86
87## --enable-replace-cpp option
88AC_ARG_ENABLE( replace-cpp,
89    AC_HELP_STRING( [--enable-replace-cpp],
90        [Replace the resident preprocessor with mcpp]),
91    ,       ## the compiler name will be defined later
92    AC_DEFINE( [COMPILER], [INDEPENDENT], [Define the target compiler.])
93            ## else define COMPILER as INDEPENDENT
94)
95
96## Generally this configure does not support cross-compiling.
97## Nevertheless, it can configure cross-compiler of Apple-GCC (i686 vs ppc).
98if test x$enable_replace_cpp = xyes    \
99        && test $ac_c_define_HOST_SYSTEM = SYS_MAC    \
100        && test $host_cpu != $target_cpu; then
101## Enable to build mcpp into cross-compiler of Apple-GCC
102## --with-target-cc option
103AC_ARG_WITH( target_cc,
104    AC_HELP_STRING( [--with-target-cc],
105        [Specify the target compiler to build mcpp into on Mac OS X]),
106    if test x${withval+set} = xset; then
107        target_cc=$withval
108        target_name=`echo $target_cc | sed 's/-gcc.*$//'`
109        if test $target_name != $target_alias; then
110            AC_MSG_ERROR( [The argument of --with-target-cc option conflicts with --target option.])
111        fi
112        AC_SUBST( [target_cc])
113    fi
114)
115fi
116
117dnl Define a target specific macro.
118
119AC_MSG_CHECKING( for target cpu)
120
121## These are not predefined macros of MCPP.  MCPP will define predefined macros
122## on compile time based on the CPU macro, and possibly redefine them at an
123## execution time.
124
125case $target_cpu in
126x86_64|amd64)
127    Target_Cpu=x86_64
128    ;;
129i?86*)
130    Target_Cpu=i386
131    ;;
132powerpc64|ppc64)
133    Target_Cpu=ppc64
134    ;;
135powerpc|ppc|ppc7400)
136    Target_Cpu=ppc
137    ;;
138*)
139    Target_Cpu=$target_cpu
140    ;;
141esac
142
143AC_MSG_RESULT( $Target_Cpu)
144AC_DEFINE_UNQUOTED( [CPU], "$Target_Cpu", [Define the cpu-specific-macro.])
145
146## Build into cross-compiler on Mac OS
147if test x$enable_replace_cpp = xyes    \
148        && test $ac_c_define_HOST_SYSTEM = SYS_MAC    \
149        && test x${target_cc+set} = xset; then
150    arch_opt="-arch $Target_Cpu"
151fi
152
153dnl Checks for header files.
154
155AC_CHECK_HEADERS( [unistd.h, stdint.h, inttypes.h])
156
157dnl Checks for typedefs, and compiler characteristics.
158
159AC_CHECK_TYPES( [intmax_t, long long])
160
161dnl Check for library functions.
162
163AC_CHECK_FUNCS( [stpcpy])
164
165dnl Checks for some system characteristics.
166
167AC_CACHE_CHECK( if the cases of filename are folded,
168    ac_cv_fname_fold,
169    [touch hJkL
170    [ac_cv_fname_fold=no]
171    AC_RUN_IFELSE( [[
172#include    <stdio.h>
173#include    <errno.h>
174    void exit();
175int main( void)
176{
177    if (fopen( "HjKl", "r") == NULL)
178        exit( errno);
179    else
180        exit( 0);
181} ]],
182        [ac_cv_fname_fold=yes],
183        [],
184        AC_MSG_WARN( cannot run on cross-compiling so assumes that the cases of filename are not folded.)
185    )
186    rm hJkL],
187)
188if test x$ac_cv_fname_fold = xyes; then
189    AC_DEFINE( [FNAME_FOLD], 1,
190        [Define if the cases of file name are folded.])
191fi
192
193dnl Checks for some host compiler characteristics.
194
195AC_DEFINE_UNQUOTED( [OBJEXT], ["$ac_cv_objext"],
196    [Define the suffix of object file.])
197
198dnl Check printf length modifier of the longest integer.
199
200# AC_CHECK_MOD_LL( modifier, additional include header)
201# Try the printf length modifier for the longest integer.
202# The redundant sscanf() is for some compilers which cannot handle
203# long long integer token.
204AC_DEFUN([AC_CHECK_MOD_LL], [
205    AC_CACHE_CHECK( [printf length modifier for the longest integer],
206        [ac_cv_c_printf_modifier],
207        AC_RUN_IFELSE( [[
208#include    <stdio.h>
209#include    <assert.h>
210    int     strcmp();
211    void    exit();
212$3
213int main( void)
214{   char    buf@<:@ 20@:>@;
215    $1  num;
216    sscanf( "1234567890123456789", "%$2d", &num);
217    sprintf( buf, "%$2d", num);
218    assert( strcmp( buf, "1234567890123456789") == 0);
219    exit( 0);
220} ]],
221            [ac_cv_c_printf_modifier=$2],
222            ,
223            AC_MSG_WARN( cannot run on cross-compiling so assumes the length modifier of long long is "%ll")
224            AC_DEFINE( [LL_FORM], "ll",
225                [Define printf length modifier for the longest integer.])
226            [ac_cv_c_printf_modifier=ll]
227        )
228    )
229] )
230
231if test x$ac_cv_type_intmax_t = xyes; then
232    AC_CHECK_MOD_LL( [intmax_t], [j], [#include <stdint.h>])
233    if test $ac_c_define_HOST_SYSTEM = SYS_CYGWIN \
234            || test $ac_c_define_HOST_SYSTEM = SYS_MINGW; then
235        sleep 1         # wait for cleanup
236    fi
237fi
238
239if test x$ac_cv_type_long_long = xyes; then
240    for modifier in ll I64 q L
241    do
242        AC_CHECK_MOD_LL( [long long], ${modifier})
243        if test x${ac_cv_c_printf_modifier+set} = xset; then
244            break
245        fi
246        if test $ac_c_define_HOST_SYSTEM = SYS_CYGWIN \
247                || test $ac_c_define_HOST_SYSTEM = SYS_MINGW; then
248            sleep 1         # wait for cleanup
249        fi
250    done
251fi
252
253if test x${ac_cv_c_printf_modifier+set} = xset; then
254    AC_DEFINE_UNQUOTED( [LL_FORM], "$ac_cv_c_printf_modifier",
255        [Define printf length modifier for the longest integer.])
256fi
257
258if test $ac_c_define_HOST_SYSTEM = SYS_FREEBSD &&   \
259        test x$mcpp_ac_c_define_SYSTEM_SP_STD != x__FreeBSD__; then
260    fbsd_ver=`echo '__FreeBSD__' | $CPP - | sed 's/^ *//' | $EGREP -v '^#|^$' | sed 's/ .*//'`
261    AC_DEFINE_UNQUOTED( [SYSTEM_EXT_VAL], "$fbsd_ver",
262        [Define the version of FreeBSD.])
263fi
264
265if test x$ac_cv_c_compiler_gnu = xyes; then
266
267    AC_DEFINE( [HOST_COMPILER], [GNUC], [Define the host compiler.])
268
269    AC_DEFINE( [HOST_CMP_NAME], "GCC", [Define the host compiler name.])
270
271    AC_MSG_CHECKING( for value of __GNUC__)
272    gcc_maj_ver=`echo '__GNUC__' | $CPP - | sed 's/^ *//' | $EGREP -v '^#|^$' | sed 's/ *//'`
273    AC_MSG_RESULT( $gcc_maj_ver)
274    AC_DEFINE_UNQUOTED( [GCC_MAJOR_VERSION], "$gcc_maj_ver",
275        [Define gcc major version.])
276    AC_MSG_CHECKING( for value of __GNUC_MINOR__)
277    gcc_min_ver=`echo __GNUC_MINOR__ | $CPP - | sed 's/^ *//' | $EGREP -v '^#|^$' | sed 's/ *//'`
278    AC_MSG_RESULT( $gcc_min_ver)
279    AC_DEFINE_UNQUOTED( [GCC_MINOR_VERSION], "$gcc_min_ver",
280        [Define gcc minor version.])
281
282    cw=`pwd`
283    if test x$srcdir = "x." || test x$srcdir = x; then
284        src_dir=$cw
285    else
286        src_dir=$srcdir
287    fi
288    if test $ac_c_define_HOST_SYSTEM = SYS_CYGWIN; then
289        AC_CACHE_CHECK( the root directory,
290            ac_cv_cygwin_root,
291            [ac_cv_cygwin_root=`$src_dir/config/cygwin_root`]
292        )
293        AC_DEFINE_UNQUOTED( [CYGWIN_ROOT_DIRECTORY], "$ac_cv_cygwin_root",
294            [Define root directory of CYGWIN.])
295    fi
296    if test $ac_c_define_HOST_SYSTEM = SYS_MINGW; then
297        AC_CACHE_CHECK( the root directory,
298            ac_cv_msys_root,
299            cd /tmp
300            cat > getcwd.c <<\_EOF
301#include <stdio.h>
302#include <unistd.h>
303#include <limits.h>
304int main( int argc, char ** argv)
305{   char    buf@<:@ PATH_MAX@:>@;
306    getcwd( buf, PATH_MAX);
307    puts( buf);
308    return 0;
309}
310_EOF
311            $CC getcwd.c
312            cd /
313            [ac_cv_msys_root=`$src_dir/config/mingw_root`]
314        )
315        AC_CACHE_CHECK( the /mingw directory,
316            ac_cv_mingw_dir,
317            cd /mingw
318            [ac_cv_mingw_dir=`$src_dir/config/mingw_root`]
319        )
320        cd $cw
321        rm -f /tmp/getcwd.c /tmp/a.exe
322        AC_DEFINE_UNQUOTED( [MSYS_ROOT_DIRECTORY], "$ac_cv_msys_root",
323            [Define root directory of MSYS.])
324        AC_DEFINE_UNQUOTED( [MINGW_DIRECTORY], "$ac_cv_mingw_dir",
325            [Define /mingw directory.])
326    fi
327
328else    # not gcc
329
330# mcpp_AC_C_DEFINE( SYSTEM | CPU | COMPILER, STD | OLD, $enableval)
331# Specify the target-specific predefined macro.
332AC_DEFUN([mcpp_AC_C_DEFINE], [
333    name=`echo $3 | sed 's/=.*//'`
334    mcpp_macro=$1_SP_$2
335    stripped_mcpp_macro=`echo $mcpp_macro | sed 's/STD//'`
336    if test x$stripped_mcpp_macro != x$mcpp_macro; then
337        stripped_name=`echo $name | sed 's/^_//'`
338        if test x$stripped_name = x$name; then
339            AC_MSG_ERROR( The macro name '$name' should begin with '_'.)
340        fi
341    else
342        stripped_name=`echo $name | sed 's/^@<:@A-Za-z@:>@//'`
343        if test x$stripped_name = x$name; then
344            AC_MSG_ERROR( The macro name '$name' should begin with an alphabetic letter.)
345        fi
346    fi
347    if test x$name = x$3; then
348        [replace=1]
349    else
350        [replace=`echo $3 | sed 's/^.*=//'`]
351    fi
352    AC_DEFINE_UNQUOTED( [$mcpp_macro], "$name")
353    AC_DEFINE_UNQUOTED( [${mcpp_macro}_VAL], "$replace")
354    mcpp_ac_c_define_$1_$2=$name
355])
356
357# mcpp_AC_C_PREDEF( SYSTEM | CPU | COMPILER, STD | OLD, additional description)
358# Specify the target-specific predefined macro via mcpp_AC_C_DEFINE.
359AC_DEFUN([mcpp_AC_C_PREDEF], [
360    AC_ARG_ENABLE( $1-$2-macro,
361        AC_HELP_STRING( --enable-$1-$2-macro=name@<:@=replace@:>@,
362            [specify the $1-specific $2-style predefined macro.  $3]),
363        if test x$enableval = xyes || test x$enableval = xno; then
364            AC_MSG_ERROR( This option requires an argument as 'name@<:@=replace@:>@'.)
365        fi
366        mcpp_AC_C_DEFINE( $1, $2, $enableval)
367        AH_TEMPLATE( [$1_SP_$2],
368            [Define the name of $1-specific $2-style predefined macro.])
369        AH_TEMPLATE( [$1_SP_$2_VAL],
370            [Define the value of $1-specific $2-style predefined macro.])
371    )
372])
373
374mcpp_AC_C_PREDEF( [SYSTEM], [STD],
375    [In all this and the following 5 options,
376    'STD'-style name begins with an '_',
377    'OLD'-style name begins with an alphabetic and
378    if '=replace' is missing the macro is defined as 1.]
379)
380mcpp_AC_C_PREDEF( [SYSTEM], [OLD])
381mcpp_AC_C_PREDEF( [CPU], [STD])
382mcpp_AC_C_PREDEF( [CPU], [OLD])
383mcpp_AC_C_PREDEF( [COMPILER], [STD])
384mcpp_AC_C_PREDEF( [COMPILER], [OLD])
385
386fi
387
388## MacOS has "framework" directories.
389if test $ac_c_define_HOST_SYSTEM = SYS_MAC; then
390    AC_MSG_CHECKING( for the MacOS-specific framework directory)
391    frameworks=`$CPP $CFLAGS $arch_opt -xc -v /dev/null 2>&1 | sed 's/^ *//' | sed 's/ .*$//' | $EGREP '/Frameworks$'`
392    n=1
393    for dir in $frameworks
394    do
395        case $n in
396        1)  framework1=$dir;;
397        2)  framework2=$dir;;
398        3)  framework3=$dir;;
399        esac
400        let n=n+1
401    done
402    if test x${framework1+set} = xset; then
403        AC_DEFINE_UNQUOTED( [FRAMEWORK1], "$framework1",
404            [Define MacOS-specific framework directory 1.])
405        AC_MSG_RESULT( $framework1)
406    else
407        AC_MSG_RESULT( none)
408    fi
409    if test x${framework2+set} = xset; then
410        AC_DEFINE_UNQUOTED( [FRAMEWORK2], "$framework2",
411            [Define MacOS-specific framework directory 2.])
412        AC_MSG_RESULT( $framework2)
413    fi
414    if test x${framework3+set} = xset; then
415        AC_DEFINE_UNQUOTED( [FRAMEWORK3], "$framework3",
416            [Define MacOS-specific framework directory 3.])
417        AC_MSG_RESULT( $framework3)
418    fi
419fi  ## SYS_MAC
420
421## --enable-mcpplib option
422AC_ARG_ENABLE( mcpplib,
423    AC_HELP_STRING( [--enable-mcpplib],
424        [Build libmcpp rather than stand-alone mcpp])
425)
426
427if test x$enable_mcpplib = xyes; then               ## mcpplib mode
428    AC_DEFINE( [MCPP_LIB], 1, [Define if build libmcpp])
429    if test x$enable_replace_cpp = xyes; then
430        AC_MSG_WARN( Ignores enable-replace-cpp option)
431        [enable_replace_cpp=no]
432    fi
433
434else
435
436if test x$enable_replace_cpp = xyes; then           ## replace-cpp mode
437
438dnl Check the characteristics of target compiler.
439dnl Note: The following 3 hundred and more lines are for replace-cpp-mode.
440dnl Target-compiler-specific configuration need these lines.
441dnl These lines are not used in compiler-independent configuration.
442
443dnl Check which header file CPP includes,
444dnl relative to CURRENT or SOURCE directory.
445
446# AC_C_INCLUDE_PREF( CURRENT | SOURCE | NEXT)
447# Check the include preference ('NEXT' means CURRENT & SOURCE)
448AC_DEFUN([AC_C_INCLUDE_PREF], [
449    AC_EGREP_CPP( $1, [
450#include "../next/header.h"
451],
452        [ac_cv_c_include_pref=$1],
453    )
454])
455
456AC_CACHE_CHECK( include preference - relative to current or source directory,
457    ac_cv_c_include_pref,
458    mkdir mcpp-tmp
459    cd mcpp-tmp
460    mkdir dir ../next ../next/dir
461    echo '#include "dir/what.h"'    > ../next/header.h
462    echo '#include "next.h"'        >> ../next/header.h
463    echo 'CURRENT'  > dir/what.h
464    echo 'SOURCE'   > ../next/dir/what.h
465    echo 'NEXT'     > ../next/next.h
466    AC_C_INCLUDE_PREF( [SOURCE])
467    if test x$ac_cv_c_include_pref != xSOURCE; then
468        AC_C_INCLUDE_PREF( [CURRENT])
469        if test x$ac_cv_c_include_pref = xCURRENT; then
470            AC_C_INCLUDE_PREF( [NEXT])
471            if test x$ac_cv_c_include_pref = xNEXT; then
472                [ac_cv_c_include_pref="(CURRENT & SOURCE)"]
473            fi
474        else
475            AC_MSG_ERROR( Failed to include header file.)
476        fi
477    fi
478    cd ..
479    rm -rf mcpp-tmp next
480    if test $ac_c_define_HOST_SYSTEM = SYS_CYGWIN \
481            || test $ac_c_define_HOST_SYSTEM = SYS_MINGW; then
482        sleep 1         # wait for cleanup
483    fi
484)
485AC_DEFINE_UNQUOTED( [SEARCH_INIT], $ac_cv_c_include_pref,
486    [Define include preference.])
487
488AC_CACHE_CHECK( if the argument of pragma is macro expanded,
489    ac_cv_c_pragma_is_expanded,
490    AC_COMPILE_IFELSE( [[
491#define once
492#pragma once]],
493        [ac_cv_c_pragma_is_expanded=no],
494        [ac_cv_c_pragma_is_expanded=yes]
495    )
496)
497if test x$ac_cv_c_pragma_is_expanded = xyes; then
498    AC_DEFINE( [EXPAND_PRAGMA], 1,
499        [Define if the argument of pragma is macro expanded.])
500fi
501
502AC_CACHE_CHECK( if digraphs can be used,
503    ac_cv_c_digraph,
504    [AC_PREPROC_IFELSE( [
505%:if 1
506%:endif],
507        [ac_cv_c_digraph=yes],
508        [ac_cv_c_digraph=no]
509    )]
510)
511if test x$ac_cv_c_digraph = xyes; then
512    AC_DEFINE( [HAVE_DIGRAPHS], 1, [Define if digraphs are available.])
513fi
514
515AC_CACHE_CHECK( preprocessor output format of line directive,
516    ac_cv_c_line_format,
517    [ac_cv_c_line_format=\"`echo '#line 4321' | $CPP - | grep 432 | sed 's/432.*$//'`\"]
518## Note: the output line number may be 4320 on GCC 2.* or other preprocessors.
519)
520AC_DEFINE_UNQUOTED( [LINE_PREFIX], $ac_cv_c_line_format,
521    [Define output format of line directive.])
522if test "x$ac_cv_c_line_format" = "x\"#line \""; then
523    ac_cv_c_std_line_prefix=1
524else
525    ac_cv_c_std_line_prefix=0
526fi
527AC_DEFINE_UNQUOTED( [STD_LINE_PREFIX], $ac_cv_c_std_line_prefix,
528    [Define whether output format of line directive is C source style.])
529
530AC_CACHE_CHECK( default value of __STDC__,
531    ac_cv_c_stdc,
532    [stdc=`echo '__STDC__' | $CPP - | sed 's/^ *//' | $EGREP -v '^#|^$' | sed 's/ .*//'`]
533    if test x"$stdc" = x"__STDC__"; then
534        [ac_cv_c_stdc=0]
535    else
536        [ac_cv_c_stdc=$stdc]
537    fi
538)
539AC_DEFINE_UNQUOTED( [STDC], $ac_cv_c_stdc,
540    [Define the default value of __STDC__.])
541
542AC_CACHE_CHECK( default value of __STDC_VERSION__,
543    ac_cv_c_stdc_ver,
544    [stdc_ver=`echo '__STDC_VERSION__' | $CPP - | sed 's/^ *//' | $EGREP -v '^#|^$' | sed 's/ .*//'`]
545    if test x"$stdc_ver" = x"__STDC_VERSION__"; then
546        [ac_cv_c_stdc_ver=0]
547    else
548        [ac_cv_c_stdc_ver=$stdc_ver]
549    fi
550)
551AC_DEFINE_UNQUOTED( [STDC_VERSION], $ac_cv_c_stdc_ver,
552    [Define the default value of __STDC_VERSION__.])
553
554if test x${ac_cv_c_compiler_gnu} != xyes; then
555
556# Specify the compiler's name
557AC_ARG_WITH( compiler-name,
558    AC_HELP_STRING( [--with-compiler-name=NAME],
559        [specify the compiler name which is used as the definition of COMPILER macro]),
560    AC_DEFINE_UNQUOTED( [COMPILER], $compiler_name, [specify the compiler name]),
561    AC_MSG_ERROR( --with-compiler-name=NAME option should be specified to define [COMPILER] macro.)
562)
563
564# Specify the C++ header file directory
565AC_ARG_WITH( cxx-include-dir,
566    AC_HELP_STRING( [--with-cxx-include-dir=directory],
567        [specify the C++ include directory by absolute path [[none]]]),
568    [case "${withval}" in
569    [\\/]* | [A-Za-z]:[\\/]*)
570        cxx_include_dir=`echo $withval | sed 's,/$,,'; 's,\\$,,'`
571        AC_DEFINE_UNQUOTED( [CPLUS_INCLUDE_DIR1], $cxx_include_dir,
572            [Define the C++ include directory.])
573        ;;
574    *)  AC_MSG_ERROR( $withval should be an absolute path.) ;;
575    esac]
576)
577
578fi  # not gcc
579
580dnl Define compiler specific elements.
581
582AC_MSG_NOTICE( checking for some compiler specific elements)
583
584# Define GCC specific elements.
585if test x$ac_cv_c_compiler_gnu = xyes; then
586
587    AC_DEFINE( [COMPILER], [GNUC], [Define the target compiler.])
588
589    cpp_call=`$CPP $CFLAGS $arch_opt -xc -v /dev/null 2>&1 | $EGREP '/cpp|/cc1' | sed 's/^ *//; s/ .*//'`
590    AC_MSG_CHECKING( for the directory to install mcpp)
591    cpp_name=`expr $cpp_call : '.*/\(.*\)'`
592    bindir=`expr $cpp_call : "\(.*\)/$cpp_name"`
593    AC_MSG_RESULT( $bindir)
594
595    AC_PATH_PROG( [gcc_path], [$CC], , [$PATH])
596    cc_path=`echo $CC | $EGREP "/"`
597    if test x$cc_path != x; then
598        AC_MSG_ERROR( [Environment variables CC and CXX for GCC-specific-build should not contain a directory part.]);
599    fi
600    ## force to set $prefix to GCC's prefix
601    ## (i.e. "/usr/local" of "/usr/local/bin/gcc")
602    gcc_prefix=`echo $gcc_path | $EGREP "/bin/$CC\$" | sed "s,/bin/$CC\$,,"`
603    if test "x$gcc_prefix" != xNONE; then
604        if test "x$prefix" != xNONE && "x$gcc_prefix" != "x$prefix"; then
605            AC_MSG_WARN( [Ignored --prefix option, since it conflicts with GCC path])
606        fi
607        prefix=$gcc_prefix
608    else
609        if test "x$prefix" = xNONE; then
610            prefix=$ac_default_prefix
611        fi
612    fi
613    lang_save=$LANG
614    export LANG=C
615
616    AC_MSG_CHECKING( for the compiler-specific C include directory)
617    exclude="^/usr(/local|)/include\$|^${prefix}(/local|)/include\$|/Frameworks|End of search list"
618    c_include_dirs=`$CPP $CFLAGS $arch_opt -xc -v /dev/null 2>&1 | sed '1,/<...> search starts here/d' | sed '/End of search list/q' | sed 's/^ *//' | $EGREP -v "$exclude"`
619    n=1
620    for dir in $c_include_dirs
621    do
622        case $n in
623        1)  c_include_dir1=$dir;;
624        2)  c_include_dir2=$dir;;
625        3)  c_include_dir3=$dir;;
626        esac
627        let n=n+1
628    done
629    if test x${c_include_dir1+set} = xset; then
630        AC_DEFINE_UNQUOTED( [C_INCLUDE_DIR1], "$c_include_dir1",
631            [Define compiler-specific C include directory 1.])
632        AC_MSG_RESULT( $c_include_dir1)
633    else
634        AC_MSG_RESULT( none)
635    fi
636    if test x${c_include_dir2+set} = xset; then
637        AC_DEFINE_UNQUOTED( [C_INCLUDE_DIR2], "$c_include_dir2",
638            [Define compiler-specific C include directory 2.])
639        AC_MSG_RESULT( $c_include_dir2)
640    fi
641    if test x${c_include_dir3+set} = xset; then
642        AC_DEFINE_UNQUOTED( [C_INCLUDE_DIR3], "$c_include_dir3",
643            [Define compiler-specific C include directory 3.])
644        AC_MSG_RESULT( $c_include_dir3)
645    fi
646
647    AC_PROG_CXX
648    AC_PROG_CXXCPP
649    AC_LANG_PUSH( C++)
650    AC_MSG_CHECKING( for the compiler-specific C++ include directory)
651    exclude="^/usr(/local|)/include\$|^${prefix}(/local|)/include\$|/Frameworks|^${c_include_dir1}\$|^${c_include_dir2}\$|^${c_include_dir3}\$"
652    cxx_include_dirs=`${CXXCPP} ${CXXFLAGS} $arch_opt -xc++ -v /dev/null 2>&1 | sed '1,/<...> search starts here/d' | sed '/End of search list/q' | sed '/End of search list/d' | sed 's/^ *//' | $EGREP -v "$exclude"`
653    n=1
654    for dir in ${cxx_include_dirs}
655    do
656        case $n in
657        1)  cxx_include_dir1=$dir;;
658        2)  cxx_include_dir2=$dir;;
659        3)  cxx_include_dir3=$dir;;
660        4)  cxx_include_dir4=$dir;;
661        esac
662        let n=n+1
663    done
664    if test x${cxx_include_dir1+set} = xset; then
665        AC_DEFINE_UNQUOTED( [CPLUS_INCLUDE_DIR1], "$cxx_include_dir1",
666            [Define compiler-specific C++ include directory 1.])
667        AC_MSG_RESULT( $cxx_include_dir1)
668    fi
669    if test x${cxx_include_dir2+set} = xset; then
670        AC_DEFINE_UNQUOTED( [CPLUS_INCLUDE_DIR2], "$cxx_include_dir2",
671            [Define compiler-specific C++ include directory 2.])
672        AC_MSG_RESULT( $cxx_include_dir2)
673    fi
674    if test x${cxx_include_dir3+set} = xset; then
675        AC_DEFINE_UNQUOTED( [CPLUS_INCLUDE_DIR3], "$cxx_include_dir3",
676            [Define compiler-specific C++ include directory 3.])
677        AC_MSG_RESULT( $cxx_include_dir3)
678    fi
679    if test x${cxx_include_dir4+set} = xset; then
680        AC_DEFINE_UNQUOTED( [CPLUS_INCLUDE_DIR4], "$cxx_include_dir4",
681            [Define compiler-specific C++ include directory 4.])
682        AC_MSG_RESULT( $cxx_include_dir4)
683    fi
684    AC_LANG_POP( C++)
685
686    export LANG=$lang_save
687
688    ## the directory into which mcpp_g*.h header files are generated
689    ## '/mcpp-gcc' will be appended to 'inc_dir'
690    if test $ac_c_define_HOST_SYSTEM = SYS_MINGW; then
691        inc_dir=$c_include_dir2
692    else
693        if test x${c_include_dir1+set} = xset; then
694            inc_dir=$c_include_dir1
695        else
696            inc_dir="$prefix"/include
697        fi
698    fi
699    AC_DEFINE_UNQUOTED( [INC_DIR], "$inc_dir",
700        [Define include directory to install mcpp_g*.h header files.])
701
702    AC_SUBST( [CPPFLAGS])
703    AC_SUBST( [host_system])
704    AC_SUBST( [Target_Cpu])
705    AC_SUBST( [inc_dir])
706    AC_SUBST( [gcc_maj_ver])
707    AC_SUBST( [gcc_min_ver])
708    AC_SUBST( [cpp_call])
709    AC_PROG_LN_S
710
711    if test x$gcc_maj_ver = x2; then
712
713        AC_CACHE_CHECK( for value of predefined macro '__SIZE_TYPE__',
714            size_type,
715            [size_type=`echo '__SIZE_TYPE__' | $CPP - | sed 's/^ *//' | $EGREP -v '^#|^$' | sed 's/ *//'`]
716        )
717        AC_DEFINE_UNQUOTED( [COMPILER_SP1_VAL], "$size_type",
718            [Define the type of size_t.])
719
720        AC_CACHE_CHECK( for value of predefined macro '__PTRDIFF_TYPE__',
721            ptrdiff_type,
722            [ptrdiff_type=`echo '__PTRDIFF_TYPE__' | $CPP - | sed 's/^ *//' | $EGREP -v '^#|^$' | sed 's/ *$//'`]
723        )
724        AC_DEFINE_UNQUOTED( [COMPILER_SP2_VAL], "$ptrdiff_type",
725            [Define the type of ptrdiff_t.])
726
727        AC_CACHE_CHECK( for value of predefined macro '__WCHAR_TYPE__',
728            wchar_type,
729            [wchar_type=`echo '__WCHAR_TYPE__' | $CPP - | sed 's/^ *//' | $EGREP -v '^#|^$' | sed 's/ *$//'`]
730        )
731        AC_DEFINE_UNQUOTED( [COMPILER_SP3_VAL], "$wchar_type",
732        [Define the type of wchar_t.])
733
734    fi
735fi
736
737## Handling of multi-byte characters containing '0x5c' codes:
738## These tests cannot be executed without appropriate options for the
739## compiler.  So, here we define all of these macros as FALSE.
740## User should edit config.h by hand after executing this script.
741## These should be 0 for GCC at least upto V.4.1.
742    AC_DEFINE( [SJIS_IS_ESCAPE_FREE], 0,
743        [Define if '0x5c' in SJIS multi-byte character is safe.])
744    AC_DEFINE( [ISO2022_JP_IS_ESCAPE_FREE], 0,
745        [Define if '0x5c' in ISO2022-JP multi-byte character is safe.])
746    AC_DEFINE( [BIGFIVE_IS_ESCAPE_FREE], 0,
747        [Define if '0x5c' in BIG5 multi-byte character is safe.])
748
749fi ## replace-cpp mode
750fi ## build-cpp mode or replace-cpp mode
751
752AC_ARG_WITH( [gcc-testsuite-dir],
753    AC_HELP_STRING( [--with-gcc-testsuite-dir=directory],
754        [specify the gcc testsuite directory to do make check.
755        e.g. /usr/src/rpm/SOURCES/gcc-2.95.4/gcc/testsuite,
756        /usr/local/src/gcc-3.2/gcc/testsuite, etc.
757        The testsuite of mcpp uses gcc testsuite, hence needs gcc source
758        or at least gcc testsuite.
759        This option needs --enable-replace-cpp option.]),
760    if test x${withval+set} = xset; then
761        if test x$enable_replace_cpp = xyes; then
762            [gcc_testsuite_dir=`echo $withval | sed 's,/$,,'`]
763        else
764            AC_MSG_ERROR( [--with-gcc-testsuite-dir option requires --enable-replace-cpp option.])
765        fi
766    else
767        AC_MSG_ERROR( [--with-gcc-testsuite-dir option requires an argument.])
768    fi
769)
770AC_SUBST( [gcc_testsuite_dir])
771AM_CONDITIONAL( [GNUC], test x$ac_cv_c_compiler_gnu = xyes)
772AM_CONDITIONAL( [MCPP_LIB], test x$enable_mcpplib = xyes)
773AM_CONDITIONAL( [REPLACE_CPP], test x$enable_replace_cpp = xyes)
774AM_CONDITIONAL( [MINGW], test $ac_c_define_HOST_SYSTEM = SYS_MINGW)
775
776dnl Final output.
777
778AC_OUTPUT( Makefile src/Makefile tests/Makefile)
779