# GDC -- D front-end for GCC # Copyright (C) 2004 David Friedman # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl Parts taken from libobjc configure.in AC_PREREQ(2.59) AC_INIT(libphobos, version-unused) AC_CONFIG_SRCDIR(gcc/builtins.d) AC_CONFIG_HEADERS(config.h) AC_CANONICAL_SYSTEM target_alias=${target_alias-$target} AC_SUBST(target_alias) AM_INIT_AUTOMAKE([1.9.4 foreign no-dependencies]) AM_ENABLE_MULTILIB(,[$d_mlcd]) # libphobos is usually a symlink to gcc/d/phobos, so libphobos/.. # is not the toplevel GCC directory. gcc/d may also be a symlink. # Find the correct top-level directory by removing "/libphobos" # from $srcdir. dnl NOTE: This assumes that AM_ENABLE_MULTILIB uses $multi_basedir if test ! -r "$multi_basedir/config-ml.in"; then better_dir=`echo "$srcdir" | sed -e 's|/libphobos||'` if test -r "$better_dir/config-ml.in"; then multi_basedir=$better_dir fi fi if test "$build" != "$host"; then # We are being configured with some form of cross compiler. #GLIBCXX_IS_NATIVE=false #GCC_NO_EXECUTABLES d_cross_comp=yes else d_cross_comp= fi dnl Copied from libstdc++-v3/acinclude.m4. Indeed, multilib will not work dnl correctly without this. # We're almost certainly being configured before anything else which uses # C++, so all of our AC_PROG_* discoveries will be cached. It's vital that # we not cache the value of CXX that we "discover" here, because it's set # to something unique for us and libjava. Other target libraries need to # find CXX for themselves. We yank the rug out from under the normal AC_* # process by sneakily renaming the cache variable. This also lets us debug # the value of "our" CXX in postmortems. # # We must also force CXX to /not/ be a precious variable, otherwise the # wrong (non-multilib-adjusted) value will be used in multilibs. This # little trick also affects CPPFLAGS, CXXFLAGS, and LDFLAGS. And as a side # effect, CXXFLAGS is no longer automagically subst'd, so we have to do # that ourselves. Un-preciousing AC_PROG_CC also affects CC and CFLAGS. # # -fno-builtin must be present here so that a non-conflicting form of # std::exit can be guessed by AC_PROG_CXX, and used in later tests. m4_define([ac_cv_prog_CXX],[glibcxx_cv_prog_CXX]) m4_rename([_AC_ARG_VAR_PRECIOUS],[glibcxx_PRECIOUS]) m4_define([_AC_ARG_VAR_PRECIOUS],[]) save_CXXFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS -fno-builtin" # --- Extra hack for Phobos --- # AC_PROG_CC, if not "cross-compiling", tries to run a simple C program. # However, a given multilib variant may not be executable on the current # system. Example: Building for x86_64 on IA-32. This is technically # cross-compiling, but we don't want cross-compiling directory layouts # and we still need link tests. Solution is to make autoconf think it # is cross compiling only when it tests the compilers. d_save_cross_compiling=$cross_compiling cross_compiling=yes AC_PROG_CC AC_PROG_CXX cross_compiling=$d_save_cross_compiling CXXFLAGS="$save_CXXFLAGS" m4_rename([glibcxx_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) AC_SUBST(CFLAGS) AC_SUBST(CXXFLAGS) dnl -- End of copy from libstdc++-v3/acinclude.m4 dnl These should be inherited in the recursive make, but ensure they are dnl defined: test "$AR" || AR=ar AC_SUBST(AR) if test "$RANLIB"; then : AC_SUBST(RANLIB) else AC_PROG_RANLIB fi AC_PROG_INSTALL AC_PROG_MAKE_SET dnl GNU_SOURCE needed for fpclassify on Linux AC_GNU_SOURCE dnl AC_PROG_LIBTOOL AC_ARG_ENABLE(thread-lib, AC_HELP_STRING([--enable-thread-lib=], [specify linker option for the system thread library (default: autodetect)]), [d_thread_lib=$enableval],[d_thread_lib=""]) AC_ARG_ENABLE(unix, AC_HELP_STRING([--enable-unix], [enables Unix runtime (default: yes, for Unix targets)]), :,[enable_unix=auto]) dnl If Phobos is built as a shared library, the loader module may add a library dnl dependency (-ldl on Linux). So, make it optional for now. AC_ARG_ENABLE(loader, AC_HELP_STRING([--enable-loader], [builds the std.loader module (default: yes, if supported on taret)]), :,[enable_loader=yes]) AC_ARG_ENABLE(proc-maps, AC_HELP_STRING([--enable-proc-maps], [use /proc/self/maps to find data segments for garbage collection (default: yes, if supported on target)]), [case "${enableval}" in yes) echo 'TODO: If cross, warn that there is no check that this works' ;; auto|no) ;; *) AC_MSG_ERROR([--enable-proc-maps argument must be "yes", "no", or "auto"]) ;; esac],[enable_proc_maps=auto]) AC_ARG_ENABLE(phobos-config-dir, AC_HELP_STRING([--enable-phobos-config-dir=], [use source file fragments in ]), [if test -z "${enableval}"; then AC_MSG_ERROR([must specify a value for --enable-phobos-config-dir]) fi], :) if test ${multilib} = yes; then multilib_arg="--enable-multilib" else multilib_arg= fi d_target_os=`echo $target_os | sed 's/^\([A-Za-z_]+\)/\1/'` # SkyOS uses i386-skyos-pe case "$target" in *-skyos*-pe*) d_target_os=skyos ;; esac dnl if test -z "$GDC"; then dnl #GDC=gdc dnl GDC=$CC dnl fi dnl if test -z "$" dnl AC_CHECK_PROG(d_have_dmd,$GDC,yes,no) dnl if test "$d_have_dmd" = "no"; then dnl AC_MSG_ERROR([can't find the D compiler!]) dnl fi GDC=$CC GDC=`echo $CC | sed s/xgcc/gdc/` AC_MSG_CHECKING([If $GDC can compile D sources]) echo "int function(int) test;" > actest.d $GDC -c -x d -I "$srcdir" actest.d r=$? rm -f actest.[do] if test $r -eq 0; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) AC_MSG_ERROR([can't compile D sources!]) fi AC_SUBST(GDC) AC_MSG_CHECKING([D GCC version]) d_gcc_ver=`$GDC -dumpversion` AC_MSG_RESULT($d_gcc_ver) dnl Eventually need to include everything from libstdc++-v3/acinclude.m4 dnl (# Default case for install directory for include files.) and on # include dir .. need to support --enable-version-specific.. but # will have to modify gcc/configure.ac .. gdc_include_dir='${prefix}'/include/d/${d_gcc_ver} AC_SUBST(gdc_include_dir) AC_ARG_WITH([cross-host], AC_HELP_STRING([--with-cross-host=HOST], [configuring with a cross compiler])) if test -n "$with_cross_host" && test x"$with_cross_host" != x"no"; then phobos_toolexecdir='${exec_prefix}/${host_alias}' phobos_toolexeclibdir='${toolexecdir}/lib' else phobos_toolexecdir='${libdir}/gcc/${host_alias}' phobos_toolexeclibdir='${libdir}' fi # The norm would be to use $GDC -print-multi-os-directory, but # that would require modifying config-ml.in multi_os_directory=`$CC -print-multi-os-directory` case $multi_os_directory in .) ;; # Avoid trailing /. *) phobos_toolexeclibdir=$phobos_toolexeclibdir/$multi_os_directory ;; esac AC_SUBST(phobos_toolexecdir) AC_SUBST(phobos_toolexeclibdir) dnl Checks for header files. # Sanity check for the cross-compilation case: AC_CHECK_HEADER(stdio.h,:, [AC_MSG_ERROR([can't find stdio.h.])]) dnl TODO: there's a more complete check for direct vs dirent... dnl Checks for header files. # Sanity check for the cross-compilation case: AC_CHECK_HEADER(dirent.h,:, [AC_MSG_ERROR([can't find dirent.h.])]) dnl AC_HEADER_STDC # TODO... dnl There was some target on sizeof(FILE) didn't work. dnl Also, anything less than 4 bytes is probably a lie. AC_MSG_CHECKING([for sizeof(FILE)]) AC_TRY_COMPILE([#include ],[ struct Test { int x: sizeof(FILE)>4; };], [AC_MSG_RESULT([yes]) AC_DEFINE(HAVE_SIZEOF_FILE,1,[Define to 1 if it is possible to determine the size of the FILE struct])], [AC_MSG_RESULT([no])]) AC_MSG_CHECKING([for sizeof(DIR)]) AC_TRY_COMPILE([#include ],[ struct Test { int x: sizeof(DIR)>4; };], [AC_MSG_RESULT([yes]) AC_DEFINE(HAVE_SIZEOF_DIR,1,[Define to 1 if it is possible to determine the size of the DIR struct])], [AC_MSG_RESULT([no])]) AC_CHECK_LIB(m,cos) case "$d_target_os" in aix*) AC_CHECK_LIB(C,sqrtf) ;; esac case "$target_os" in darwin6*) DCFG_LONG_DOUBLE_FUNCS=config/noldfuncs ;; darwin*) DCFG_LONG_DOUBLE_FUNCS=config/ldfuncs-darwin ;; linux*) case "$target_cpu" in powerpc*) DCFG_LONG_DOUBLE_FUNCS=config/ldfuncs-ppclinux # Libc without nldbl not supported... AC_CHECK_FUNC(__nldbl_printf,d_have_nldbl_funcs=1,:) if test "$d_have_nldbl_funcs" = 1; then : fi ;; esac esac if test -z "$DCFG_LONG_DOUBLE_FUNCS"; then AC_CHECK_FUNC(acosl,have_ldf_a=1,:) AC_CHECK_FUNC(truncl,have_ldf_b=1,:) if test "${have_ldf_a}${have_ldf_b}" = "11"; then DCFG_LONG_DOUBLE_FUNCS=config/ldfuncs else DCFG_LONG_DOUBLE_FUNCS=config/noldfuncs fi DCFG_LONG_DOUBLE_FUNCS="$DCFG_LONG_DOUBLE_FUNCS" fi D_EXTRA_OBJS= AC_SUBST(D_EXTRA_OBJS) D_PREREQ_SRCS='$(config_d_src)' AC_SUBST(D_PREREQ_SRCS) DCFG_LONG_DOUBLE_FUNCS="$srcdir/$DCFG_LONG_DOUBLE_FUNCS" AC_SUBST_FILE(DCFG_LONG_DOUBLE_FUNCS) # on darwin, we don't seem to have sqrtf, even though it's in math.h AC_CHECK_FUNC(sqrtf,DCFG_SQRTF=config/sqrtf,DCFG_SQRTF=config/nosqrtf) DCFG_SQRTF="$srcdir/$DCFG_SQRTF" AC_SUBST_FILE(DCFG_SQRTF) # on freebsd, trunc,exp2,log2 are not provided # This is "need" and not "have" to mesh better with non-GNU. Othrewise, it # would be version(GNU)version(GNU_Have_trunc).... AC_CHECK_FUNC(trunc,DCFG_TRUNC="",DCFG_TRUNC="GNU_Need_trunc") AC_SUBST(DCFG_TRUNC) AC_CHECK_FUNC(nearbyint,DCFG_NEARBYINT="",DCFG_NEARBYINT="GNU_Need_nearbyint") AC_SUBST(DCFG_NEARBYINT) AC_CHECK_FUNC(round,DCFG_ROUND="",DCFG_ROUND="GNU_Need_round") AC_SUBST(DCFG_ROUND) AC_CHECK_FUNC(tgamma,DCFG_TGAMMA="",[ DCFG_TGAMMA="GNU_Need_tgamma" D_EXTRA_OBJS="$D_EXTRA_OBJS etc/gamma.o" ]) AC_SUBST(DCFG_TGAMMA) AC_CHECK_FUNC(nan,DCFG_NAN="",DCFG_NAN="GNU_Need_nan") AC_SUBST(DCFG_NAN) AC_CHECK_FUNCS(exp2 log2,:,:) if test "$ac_cv_func_exp2" = "yes" && test "$ac_cv_func_log2" = "yes"; then DCFG_EXP2_LOG2="" else DCFG_EXP2_LOG2="GNU_Need_exp2_log2" fi AC_SUBST(DCFG_EXP2_LOG2) AC_MSG_CHECKING([for fpclassify and signbit]) AC_TRY_COMPILE([ #ifndef fpclassify static void fpclassify(int x, int y) { } #endif #ifndef signbit static void signbit(int x, int y) { } #endif #include ], [int x = fpclassify(4.2); int y = signbit(1.1); int z = FP_NAN + FP_INFINITE + FP_ZERO + FP_SUBNORMAL + FP_NORMAL;], [AC_MSG_RESULT([yes]) d_have_fpsb=1], [AC_MSG_RESULT([no])]) case "$d_target_os" in # use fpmath on Linux linux*) d_have_fpsb='' ;; esac if test -n "$d_have_fpsb"; then AC_DEFINE(HAVE_FP_CLASSIFY_SIGNBIT,1,[Define to 1 fpclassify and signbit are available]) D_EXTRA_OBJS="$D_EXTRA_OBJS gcc/cbridge_math.o" else case "$target_cpu" in i*86 ) ;; powerpc* ) ;; ppc* ) ;; x86_64 ) ;; *) AC_MSG_ERROR([Missing fpclassify and signbit]) ;; esac D_EXTRA_OBJS="$D_EXTRA_OBJS internal/fpmath.o" fi # no expm1 on mingw (msvcrt) # AC_CHECK_FUNCS(expm1,DCFG_EXPM1="",DCFG_EXPM1="GNU_Need_expm1") # AC_SUBST(DCFG_EXPM1) # also erf, erfc AC_CHECK_FUNC(execvpe,DCFG_EXECVPE="",DCFG_EXECVPE="GNU_Need_execvpe") AC_SUBST(DCFG_EXECVPE) AC_CHECK_FUNC(spawnvp,DCFG_SPAWNVP="",DCFG_SPAWNVP="GNU_Need_spawnvp") AC_SUBST(DCFG_SPAWNVP) AC_CHECK_FUNC(fwide,[DCFG_FWIDE=1],[DCFG_FWIDE=0]) AC_SUBST(DCFG_FWIDE) AC_CHECK_FUNC(getdelim,[DCFG_HAVE_GETDELIM=1],[DCFG_HAVE_GETDELIM=0]) AC_SUBST(DCFG_HAVE_GETDELIM) AC_CHECK_FUNC(fgetln,[DCFG_HAVE_FGETLN=1],[DCFG_HAVE_FGETLN=0]) AC_SUBST(DCFG_HAVE_FGETLN) AC_CHECK_FUNC(fgetline,[DCFG_HAVE_FGETLINE=1],[DCFG_HAVE_FGETLINE=0]) AC_SUBST(DCFG_HAVE_FGETLINE) DCFG_HAVE_UNLOCKED_STDIO=1 AC_CHECK_FUNCS([flockfile funlockfile putc_unlocked getc_unlocked], [],[DCFG_HAVE_UNLOCKED_STDIO=0]) AC_SUBST(DCFG_HAVE_UNLOCKED_STDIO) DCFG_HAVE_UNLOCKED_WIDE_STDIO=$DCFG_HAVE_UNLOCKED_STDIO AC_CHECK_FUNCS([putwc_unlocked getwc_unlocked], [],[DCFG_HAVE_UNLOCKED_WIDE_STDIO=0]) AC_SUBST(DCFG_HAVE_UNLOCKED_WIDE_STDIO) AC_CHECK_FUNC(strtold,DCFG_STRTOLD="GNU_Have_strtold",DCFG_STRTOLD="") AC_SUBST(DCFG_STRTOLD) dnl Check for BSD(?) specific fields in struct tm dnl Maybe test fields separately AC_MSG_CHECKING([for tm_gmtoff]) AC_TRY_COMPILE([#include ],[ struct tm t; t.tm_gmtoff = t.tm_gmtoff; t.tm_zone = t.tm_zone;], [AC_MSG_RESULT([yes]) AC_DEFINE(HAVE_TM_GMTOFF_AND_ZONE,1,[Extra fields in struct tm])], [AC_MSG_RESULT([no])]) dnl The '* 42' is to ensure a type error occurs if timezone is not a dnl number. Simple assignment will not do this. AC_MSG_CHECKING([for timezone]) AC_TRY_COMPILE([#include ],[ time_t t = timezone * 42;], [AC_MSG_RESULT([yes]) AC_DEFINE(HAVE_TIMEZONE,1,[Global timezone variable])], [AC_MSG_RESULT([no])]) AC_MSG_CHECKING([for _timezone]) AC_TRY_COMPILE([#include ],[ time_t t = _timezone * 42;], [AC_MSG_RESULT([yes]) AC_DEFINE(HAVE__TIMEZONE,1,[Another global timezone variable])], [AC_MSG_RESULT([no])]) AC_CHECK_FUNCS(snprintf _snprintf,break,[AC_MSG_ERROR([No variant of snprintf.])]) AC_CHECK_FUNCS(vsnprintf _vsnprintf,break,[AC_MSG_ERROR([No variant of vsnprintf.])]) AC_MSG_CHECKING([if std.boxer will work]) cat > conftest.d </dev/null 2>&1 if test $? = 0; then AC_MSG_RESULT([yes]) D_EXTRA_OBJS="$D_EXTRA_OBJS std/boxer.o" else AC_MSG_RESULT([no]) fi rm -f conftest.d conftest.$ac_objext case "$d_target_os" in aix*|*bsd*|cygwin*|darwin*|linux*|skyos*|solaris*|sysv*) d_have_unix=1 ;; esac DCFG_CBRIDGE_STDIO= AC_SUBST(DCFG_CBRIDGE_STDIO) case "$d_target_os" in aix*) d_is_aix=1 ;; darwin*) d_module_mach=1 d_sem_impl="mach" d_have_loader=1 ;; freebsd*) d_have_loader=1 D_EXTRA_OBJS="$D_EXTRA_OBJS gcc/cbridge_stdio.o" DCFG_CBRIDGE_STDIO=GNU_CBridge_Stdio ;; linux*) #D_EXTRA_OBJS="$D_EXTRA_OBJS std/c/linux/linux.o" d_sem_impl="posix" d_have_loader=1 # should check for , and use verion(GNU_Have_dlopen) ;; cygwin*) D_EXTRA_OBJS="$D_EXTRA_OBJS gcc/cbridge_stdio.o" DCFG_CBRIDGE_STDIO=GNU_CBridge_Stdio ;; mingw*) #D_EXTRA_OBJS="$D_EXTRA_OBJS gcc/cbridge_stdio.o" D_EXTRA_OBJS="$D_EXTRA_OBJS \$(WINDOWS_OBJS)" #DCFG_CBRIDGE_STDIO=GNU_CBridge_Stdio DCFG_UNIX=Windows d_have_loader=1 ;; skyos*) d_sem_impl="skyos" D_EXTRA_OBJS="$D_EXTRA_OBJS gcc/cbridge_stdio.o" DCFG_CBRIDGE_STDIO=GNU_CBridge_Stdio AC_DEFINE(PTHREAD_MUTEX_ALREADY_RECURSIVE,1,[Define if mutexes are recursive by default]) ;; *) D_EXTRA_OBJS="$D_EXTRA_OBJS gcc/cbridge_stdio.o" DCFG_CBRIDGE_STDIO=GNU_CBridge_Stdio ;; esac # = D_EXTRA_OBJS="$D_EXTRA_OBJS \$(WINDOWS_OBJS)" # for cygw: WINDOWS_DFLAGS=-mno-cygwin # # in Make: .win.o maybe... to get a separate rule if test -n "$d_module_mach"; then D_EXTRA_OBJS="$D_EXTRA_OBJS std/c/mach/mach.o" fi if test -n "$d_have_unix" && test "$enable_unix" = auto ; then enable_unix=yes fi if test "$enable_unix" = "yes"; then DPHOBOS_CONFIGURE_UNIX fi dnl can these be moved to acinclude.m4? AC_SUBST(DCFG_SA_LEN) AC_SUBST(DCFG_SEMAPHORE_IMPL) AC_SUBST(DCFG_MMAP) AC_SUBST(DCFG_GETPWNAM_R) AC_SUBST(DCFG_UNIX) if test -z "$DFLAGS"; then DFLAGS="-g -frelease -O2" fi AC_SUBST(DFLAGS) if test -n "$d_have_loader" && test "$enable_loader" = yes; then D_EXTRA_OBJS="$D_EXTRA_OBJS std/loader.o" fi dnl TODO: change this to using pthreads? if so, define usepthreads dnl and configure semaphore # phobose_use_pthreads was here... d_subdirs=`( cd $srcdir && find . -type d ) | sed -e 's/^.\///'` d_subdirs="$d_subdirs gcc" for i in $d_subdirs; do mkdir -p $i; done AC_SUBST(srcdir) # Cross stuff # if test -n "$d_cross_comp"; then # # fi # Garbage collection configuration D_GC_MODULES= D_GC_FLAGS= case "$target_os" in mingw*) D_GC_MODULES=internal/gc/win32.o need_to_cfgr_gc='' ;; *) need_to_cfgr_gc=yes ;; esac if test "$need_to_cfgr_gc" = yes; then DPHOBOS_CONFIGURE_GC fi AC_SUBST(D_GC_FLAGS) AC_SUBST(D_GC_MODULES) if test -n "$enable_phobos_config_dir"; then D_GENERATE_FRAGMENTS='' D_FRAGMENT_SRCDIR=$enable_phobos_config_dir else # In multilib environments it may not be possible to run all of # the gen* programs even if building a native compiler. The following # is a fix for darwin8 (i.e. building on Core Duo hardware, can't run x86_64 # programs). This is a general problem, but won't be fixed until there # is a better way to translate the C headers. case "$d_target_os" in darwin8*) d_no_gen_progs=1 ;; esac if test -z "$d_no_gen_progs" && test "$d_cross_comp" != "yes"; then D_GENERATE_FRAGMENTS='yes' D_FRAGMENT_SRCDIR='' else D_GENERATE_FRAGMENTS='' case "$d_target_os" in darwin8*) D_FRAGMENT_SRCDIR='$(srcdir)/config/darwin8' ;; mingw*) D_FRAGMENT_SRCDIR='$(srcdir)/config/mingw' ;; skyos*) D_FRAGMENT_SRCDIR='$(srcdir)/config/skyos' ;; *) AC_MSG_ERROR([Sorry, you must provide the target-specific configure fragments (--enable-phobos-config-dir)]) esac fi fi AM_CONDITIONAL(D_GENERATE_FRAGMENTS, test "$D_GENERATE_FRAGMENTS" = "yes") AC_SUBST(D_FRAGMENT_SRCDIR) AC_OUTPUT([Makefile frag-ac phobos-ver-syms])