Home | History | Annotate | Download | only in source
      1 # Copyright (c) 1999-2013, International Business Machines Corporation and
      2 # others. All Rights Reserved.
      3 # acinclude.m4 for ICU
      4 # Don't edit aclocal.m4, do edit acinclude.m4
      5 # Stephen F. Booth
      6 
      7 # @TOP@
      8 
      9 # ICU_CHECK_MH_FRAG
     10 AC_DEFUN([ICU_CHECK_MH_FRAG], [
     11 	AC_CACHE_CHECK(
     12 		[which Makefile fragment to use for ${host}],
     13 		[icu_cv_host_frag],
     14 		[
     15 case "${host}" in
     16 *-*-solaris*)
     17 	if test "$GCC" = yes; then	
     18 		icu_cv_host_frag=mh-solaris-gcc
     19 	else
     20 		icu_cv_host_frag=mh-solaris
     21 	fi ;;
     22 alpha*-*-linux-gnu)
     23 	if test "$GCC" = yes; then
     24 		icu_cv_host_frag=mh-alpha-linux-gcc
     25 	else
     26 		icu_cv_host_frag=mh-alpha-linux-cc
     27 	fi ;;
     28 powerpc*-*-linux*)
     29 	if test "$GCC" = yes; then
     30 		icu_cv_host_frag=mh-linux
     31 	else
     32 		icu_cv_host_frag=mh-linux-va
     33 	fi ;;
     34 *-*-linux*|*-*-gnu|*-*-k*bsd*-gnu|*-*-kopensolaris*-gnu) icu_cv_host_frag=mh-linux ;;
     35 *-*-cygwin|*-*-mingw32|*-*-mingw64)
     36 	if test "$GCC" = yes; then
     37 		AC_TRY_COMPILE([
     38 #ifndef __MINGW32__
     39 #error This is not MinGW
     40 #endif], [], AC_TRY_COMPILE([
     41 #ifndef __MINGW64__
     42 #error This is not MinGW64
     43 #endif], [], icu_cv_host_frag=mh-mingw64, icu_cv_host_frag=mh-mingw), icu_cv_host_frag=mh-cygwin)
     44 	else
     45 		icu_cv_host_frag=mh-cygwin-msvc
     46 	fi ;;
     47 *-*-*bsd*|*-*-dragonfly*) 	icu_cv_host_frag=mh-bsd-gcc ;;
     48 *-*-aix*)
     49 	if test "$GCC" = yes; then
     50 		icu_cv_host_frag=mh-aix-gcc
     51 	else
     52 		icu_cv_host_frag=mh-aix-va
     53 	fi ;;
     54 *-*-hpux*)
     55 	if test "$GCC" = yes; then
     56 		icu_cv_host_frag=mh-hpux-gcc
     57 	else
     58 		case "$CXX" in
     59 		*aCC)    icu_cv_host_frag=mh-hpux-acc ;;
     60 		esac
     61 	fi ;;
     62 *-*ibm-openedition*|*-*-os390*)	icu_cv_host_frag=mh-os390 ;;
     63 *-*-os400*)	icu_cv_host_frag=mh-os400 ;;
     64 *-apple-rhapsody*)	icu_cv_host_frag=mh-darwin ;;
     65 *-apple-darwin*)	icu_cv_host_frag=mh-darwin ;;
     66 *-*-beos)       icu_cv_host_frag=mh-beos ;; 
     67 *-*-haiku)      icu_cv_host_frag=mh-haiku ;; 
     68 *-*-irix*)	icu_cv_host_frag=mh-irix ;;
     69 *-dec-osf*) icu_cv_host_frag=mh-alpha-osf ;;
     70 *-*-nto*)	icu_cv_host_frag=mh-qnx ;;
     71 *-ncr-*)	icu_cv_host_frag=mh-mpras ;;
     72 *) 		icu_cv_host_frag=mh-unknown ;;
     73 esac
     74 		]
     75 	)
     76 ])
     77 
     78 # ICU_CONDITIONAL - similar example taken from Automake 1.4
     79 AC_DEFUN([ICU_CONDITIONAL],
     80 [AC_SUBST($1_TRUE)
     81 if $2; then
     82   $1_TRUE=
     83 else
     84   $1_TRUE='#'
     85 fi])
     86 
     87 # ICU_PROG_LINK - Make sure that the linker is usable
     88 AC_DEFUN([ICU_PROG_LINK],
     89 [
     90 case "${host}" in
     91     *-*-cygwin*|*-*-mingw*)
     92         if test "$GCC" != yes && test -n "`link --version 2>&1 | grep 'GNU coreutils'`"; then
     93             AC_MSG_ERROR([link.exe is not a valid linker. Your PATH is incorrect.
     94                   Please follow the directions in ICU's readme.])
     95         fi;;
     96     *);;
     97 esac])
     98 
     99 # AC_SEARCH_LIBS_FIRST(FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND
    100 #            [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
    101 # Search for a library defining FUNC, then see if it's not already available.
    102 
    103 AC_DEFUN([AC_SEARCH_LIBS_FIRST],
    104 [AC_PREREQ([2.13])
    105 AC_CACHE_CHECK([for library containing $1], [ac_cv_search_$1],
    106 [ac_func_search_save_LIBS="$LIBS"
    107 ac_cv_search_$1="no"
    108 for i in $2; do
    109 LIBS="-l$i $5 $ac_func_search_save_LIBS"
    110 AC_TRY_LINK_FUNC([$1],
    111 [ac_cv_search_$1="-l$i"
    112 break])
    113 done
    114 if test "$ac_cv_search_$1" = "no"; then
    115 AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="none required"])
    116 fi
    117 LIBS="$ac_func_search_save_LIBS"])
    118 if test "$ac_cv_search_$1" != "no"; then
    119   test "$ac_cv_search_$1" = "none required" || LIBS="$ac_cv_search_$1 $LIBS"
    120   $3
    121 else :
    122   $4
    123 fi])
    124 
    125 
    126 
    127 # Check if we can build and use 64-bit libraries
    128 AC_DEFUN([AC_CHECK_64BIT_LIBS],
    129 [
    130     BITS_REQ=nochange
    131     ENABLE_64BIT_LIBS=unknown
    132     ## revisit this for cross-compile.
    133     
    134     AC_ARG_ENABLE(64bit-libs,
    135         [  --enable-64bit-libs     (deprecated, use --with-library-bits) build 64-bit libraries [default= platform default]],
    136         [echo "note, use --with-library-bits instead of --*-64bit-libs"
    137          case "${enableval}" in
    138             no|false|32) with_library_bits=32;  ;;
    139             yes|true|64) with_library_bits=64else32 ;;
    140             nochange) with_library_bits=nochange; ;;
    141             *) AC_MSG_ERROR(bad value ${enableval} for '--*-64bit-libs') ;;
    142             esac]    )
    143     
    144 
    145     AC_ARG_WITH(library-bits,
    146         [  --with-library-bits=bits specify how many bits to use for the library (32, 64, 64else32, nochange) [default=nochange]],
    147         [case "${withval}" in
    148             ""|nochange) BITS_REQ=$withval ;;
    149             32|64|64else32) BITS_REQ=$withval ;;
    150             *) AC_MSG_ERROR(bad value ${withval} for --with-library-bits) ;;
    151             esac])
    152         
    153     # don't use these for cross compiling
    154     if test "$cross_compiling" = "yes" -a "${BITS_REQ}" != "nochange"; then
    155         AC_MSG_ERROR([Don't specify bitness when cross compiling. See readme.html for help with cross compilation., and set compiler options manually.])
    156     fi
    157     AC_CHECK_SIZEOF([void *])
    158     AC_MSG_CHECKING([whether runnable 64 bit binaries are built by default])
    159     case $ac_cv_sizeof_void_p in
    160         8) DEFAULT_64BIT=yes ;;
    161         4) DEFAULT_64BIT=no ;;
    162         *) DEFAULT_64BIT=unknown
    163     esac
    164     BITS_GOT=unknown
    165     
    166     # 'OK' here means, we can exit any further checking, everything's copa
    167     BITS_OK=yes
    168 
    169     # do we need to check for buildable/runnable 32 or 64 bit?
    170     BITS_CHECK_32=no
    171     BITS_CHECK_64=no
    172     
    173     # later, can we run the 32/64 bit binaries so made?
    174     BITS_RUN_32=no
    175     BITS_RUN_64=no
    176     
    177     if test "$DEFAULT_64BIT" = "yes"; then
    178         # we get 64 bits by default.
    179         BITS_GOT=64
    180         case "$BITS_REQ" in
    181             32) 
    182                 # need to look for 32 bit support. 
    183                 BITS_CHECK_32=yes
    184                 # not copa.
    185                 BITS_OK=no;;
    186             # everyone else is happy.
    187             nochange) ;;
    188             *) ;;
    189         esac
    190     elif test "$DEFAULT_64BIT" = "no"; then
    191         # not 64 bit by default.
    192         BITS_GOT=32
    193         case "$BITS_REQ" in
    194             64|64else32)
    195                 BITS_CHECK_64=yes
    196                 #BITS_CHECK_32=yes
    197                 BITS_OK=no;;
    198             nochange) ;;
    199             *) ;;
    200         esac
    201     elif test "$DEFAULT_64BIT" = "unknown"; then
    202         # cross compiling.
    203         BITS_GOT=unknown
    204         case "$BITS_REQ" in
    205             64|64else32) BITS_OK=no
    206             BITS_CHECK_32=yes
    207             BITS_CHECK_64=yes ;;
    208             32) BITS_OK=no;;
    209             nochange) ;;
    210             *) ;;
    211         esac
    212     fi
    213             
    214     AC_MSG_RESULT($DEFAULT_64BIT);
    215 
    216     if test "$BITS_OK" != "yes"; then
    217         # not copa. back these up.
    218         CFLAGS_OLD="${CFLAGS}"
    219         CXXFLAGS_OLD="${CXXFLAGS}"
    220         LDFLAGS_OLD="${LDFLAGS}"
    221         ARFLAGS_OLD="${ARFLAGS}"        
    222         
    223         CFLAGS_32="${CFLAGS}"
    224         CXXFLAGS_32="${CXXFLAGS}"
    225         LDFLAGS_32="${LDFLAGS}"
    226         ARFLAGS_32="${ARFLAGS}"        
    227         
    228         CFLAGS_64="${CFLAGS}"
    229         CXXFLAGS_64="${CXXFLAGS}"
    230         LDFLAGS_64="${LDFLAGS}"
    231         ARFLAGS_64="${ARFLAGS}"        
    232         
    233         CAN_BUILD_64=unknown
    234         CAN_BUILD_32=unknown
    235         # These results can't be cached because is sets compiler flags.
    236         if test "$BITS_CHECK_64" = "yes"; then
    237             AC_MSG_CHECKING([how to build 64-bit executables])
    238             CAN_BUILD_64=no
    239             ####
    240             # Find out if we think we can *build* for 64 bit. Doesn't check whether we can run it.
    241             #  Note, we don't have to actually check if the options work- we'll try them before using them.
    242             #  So, only try actually testing the options, if you are trying to decide between multiple options.
    243             # On exit from the following clauses:
    244             # if CAN_BUILD_64=yes:
    245             #    *FLAGS are assumed to contain the right settings for 64bit
    246             # else if CAN_BUILD_64=no: (default)
    247             #    *FLAGS are assumed to be trashed, and will be reset from *FLAGS_OLD
    248             
    249             if test "$GCC" = yes; then
    250                 CFLAGS="${CFLAGS} -m64"
    251                 CXXFLAGS="${CXXFLAGS} -m64"
    252                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==64)?0:1;}])],
    253                    CAN_BUILD_64=yes, CAN_BUILD_64=no)
    254             else
    255                 case "${host}" in
    256                 sparc*-*-solaris*)
    257                     # 1. try -m64
    258                     CFLAGS="${CFLAGS} -m64"
    259                     CXXFLAGS="${CXXFLAGS} -m64"
    260                     AC_RUN_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==64)?0:1;}])],
    261                        CAN_BUILD_64=yes, CAN_BUILD_64=no, CAN_BUILD_64=unknown)
    262                     if test "$CAN_BUILD_64" != yes; then
    263                         # Nope. back out changes.
    264                         CFLAGS="${CFLAGS_OLD}"
    265                         CXXFLAGS="${CFLAGS_OLD}"
    266                         # 2. try xarch=v9 [deprecated]
    267                         ## TODO: cross compile: the following won't work.
    268                         SPARCV9=`isainfo -n 2>&1 | grep sparcv9`
    269                         SOL64=`$CXX -xarch=v9 2>&1 && $CC -xarch=v9 2>&1 | grep -v usage:`
    270                         # "Warning: -xarch=v9 is deprecated, use -m64 to create 64-bit programs"
    271                         if test -z "$SOL64" && test -n "$SPARCV9"; then
    272                             CFLAGS="${CFLAGS} -xtarget=ultra -xarch=v9"
    273                             CXXFLAGS="${CXXFLAGS} -xtarget=ultra -xarch=v9"
    274                             LDFLAGS="${LDFLAGS} -xtarget=ultra -xarch=v9"
    275                             CAN_BUILD_64=yes
    276                         fi
    277                     fi
    278                     ;;
    279                 i386-*-solaris*)
    280                     # 1. try -m64
    281                     CFLAGS="${CFLAGS} -m64"
    282                     CXXFLAGS="${CXXFLAGS} -m64"
    283                     AC_RUN_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==64)?0:1;}])],
    284                        CAN_BUILD_64=yes, CAN_BUILD_64=no, CAN_BUILD_64=unknown)
    285                     if test "$CAN_BUILD_64" != yes; then
    286                         # Nope. back out changes.
    287                         CFLAGS="${CFLAGS_OLD}"
    288                         CXXFLAGS="${CXXFLAGS_OLD}"
    289                         # 2. try the older compiler option
    290                         ## TODO: cross compile problem
    291                         AMD64=`isainfo -n 2>&1 | grep amd64`
    292                         SOL64=`$CXX -xtarget=generic64 2>&1 && $CC -xtarget=generic64 2>&1 | grep -v usage:`
    293                         if test -z "$SOL64" && test -n "$AMD64"; then
    294                             CFLAGS="${CFLAGS} -xtarget=generic64"
    295                             CXXFLAGS="${CXXFLAGS} -xtarget=generic64"
    296                             CAN_BUILD_64=yes
    297                         fi
    298                     fi
    299                     ;;
    300                 ia64-*-linux*)
    301                     # check for ecc/ecpc compiler support
    302                     ## TODO: cross compiler problem
    303                     if test -n "`$CXX --help 2>&1 && $CC --help 2>&1 | grep -v Intel`"; then
    304                         if test -n "`$CXX --help 2>&1 && $CC --help 2>&1 | grep -v Itanium`"; then
    305                             CAN_BUILD_64=yes
    306                         fi
    307                     fi
    308                     ;;
    309                 *-*-cygwin)
    310                     # vcvarsamd64.bat should have been used to enable 64-bit builds.
    311                     # We only do this check to display the correct answer.
    312                     ## TODO: cross compiler problem
    313                     if test -n "`$CXX -help 2>&1 | grep 'for x64'`"; then
    314                         CAN_BUILD_64=yes
    315                     fi
    316                     ;;
    317                 *-*-aix*|powerpc64-*-linux*)
    318                     CFLAGS="${CFLAGS} -q64"
    319                     CXXFLAGS="${CXXFLAGS} -q64"
    320                     LDFLAGS="${LDFLAGS} -q64"
    321                     AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==64)?0:1;}])],
    322                        CAN_BUILD_64=yes, CAN_BUILD_64=no)
    323                     if test "$CAN_BUILD_64" = yes; then
    324                         # worked- set other options.
    325                         case "${host}" in
    326                         *-*-aix*)
    327                             # tell AIX what executable mode to use.
    328                             ARFLAGS="${ARFLAGS} -X64"
    329                         esac
    330                     fi
    331                     ;;
    332                 *-*-hpux*)
    333                     # First we try the newer +DD64, if that doesn't work,
    334                     # try other options.
    335 
    336                     CFLAGS="${CFLAGS} +DD64"
    337                     CXXFLAGS="${CXXFLAGS} +DD64"
    338                     AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==64)?0:1;}])],
    339                         CAN_BUILD_64=yes, CAN_BUILD_64=no)
    340                     if test "$CAN_BUILD_64" != yes; then
    341                         # reset
    342                         CFLAGS="${CFLAGS_OLD}"
    343                         CXXFLAGS="${CXXFLAGS_OLD}"
    344                         # append
    345                         CFLAGS="${CFLAGS} +DA2.0W"
    346                         CXXFLAGS="${CXXFLAGS} +DA2.0W"
    347                         AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==64)?0:1;}])],
    348                             CAN_BUILD_64=yes, CAN_BUILD_64=no)
    349                     fi
    350                     ;;
    351                 *-*ibm-openedition*|*-*-os390*)
    352                     CFLAGS="${CFLAGS} -Wc,lp64"
    353                     CXXFLAGS="${CXXFLAGS} -Wc,lp64"
    354                     LDFLAGS="${LDFLAGS} -Wl,lp64"
    355                     AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==64)?0:1;}])],
    356                        CAN_BUILD_64=yes, CAN_BUILD_64=no)
    357                     ;;
    358                 *)
    359                     # unknown platform.
    360                     ;;
    361                 esac
    362             fi
    363             AC_MSG_RESULT($CAN_BUILD_64)
    364             if test "$CAN_BUILD_64" = yes; then
    365                 AC_MSG_CHECKING([whether runnable 64-bit binaries are being built ])
    366                 AC_RUN_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==64)?0:1;}])],
    367                    BITS_RUN_64=yes, BITS_RUN_64=no, BITS_RUN_64=unknown)
    368                 AC_MSG_RESULT($BITS_RUN_64);
    369 
    370                 CFLAGS_64="${CFLAGS}"
    371                 CXXFLAGS_64="${CXXFLAGS}"
    372                 LDFLAGS_64="${LDFLAGS}"
    373                 ARFLAGS_64="${ARFLAGS}"        
    374             fi
    375             # put it back.
    376             CFLAGS="${CFLAGS_OLD}"
    377             CXXFLAGS="${CXXFLAGS_OLD}"
    378             LDFLAGS="${LDFLAGS_OLD}"
    379             ARFLAGS="${ARFLAGS_OLD}"     
    380         fi
    381         if test "$BITS_CHECK_32" = "yes"; then
    382             # see comment under 'if BITS_CHECK_64', above.
    383             AC_MSG_CHECKING([how to build 32-bit executables])
    384             if test "$GCC" = yes; then
    385                 CFLAGS="${CFLAGS} -m32"
    386                 CXXFLAGS="${CXXFLAGS} -m32"
    387                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==32)?0:1;}])],
    388                    CAN_BUILD_32=yes, CAN_BUILD_32=no)
    389             fi
    390             AC_MSG_RESULT($CAN_BUILD_32)
    391             if test "$CAN_BUILD_32" = yes; then
    392                 AC_MSG_CHECKING([whether runnable 32-bit binaries are being built ])
    393                 AC_RUN_IFELSE([AC_LANG_SOURCE([int main(void) {return (sizeof(void*)*8==32)?0:1;}])],
    394                    BITS_RUN_32=yes, BITS_RUN_32=no, BITS_RUN_32=unknown)
    395                 AC_MSG_RESULT($BITS_RUN_32);
    396                 CFLAGS_32="${CFLAGS}"
    397                 CXXFLAGS_32="${CXXFLAGS}"
    398                 LDFLAGS_32="${LDFLAGS}"
    399                 ARFLAGS_32="${ARFLAGS}"        
    400             fi
    401             # put it back.
    402             CFLAGS="${CFLAGS_OLD}"
    403             CXXFLAGS="${CXXFLAGS_OLD}"
    404             LDFLAGS="${LDFLAGS_OLD}"
    405             ARFLAGS="${ARFLAGS_OLD}"     
    406         fi
    407         
    408         ##
    409         # OK. Now, we've tested for 32 and 64 bitness. Let's see what we'll do.
    410         #
    411         
    412         # First, implement 64else32
    413         if test "$BITS_REQ" = "64else32"; then
    414             if test "$BITS_RUN_64" = "yes"; then
    415                 BITS_REQ=64
    416             else
    417                 # no changes.
    418                 BITS_OK=yes 
    419             fi
    420         fi
    421         
    422         # implement.
    423         if test "$BITS_REQ" = "32" -a "$BITS_RUN_32" = "yes"; then
    424             CFLAGS="${CFLAGS_32}"
    425             CXXFLAGS="${CXXFLAGS_32}"
    426             LDFLAGS="${LDFLAGS_32}"
    427             ARFLAGS="${ARFLAGS_32}"     
    428             BITS_OK=yes
    429         elif test "$BITS_REQ" = "64" -a "$BITS_RUN_64" = "yes"; then
    430             CFLAGS="${CFLAGS_64}"
    431             CXXFLAGS="${CXXFLAGS_64}"
    432             LDFLAGS="${LDFLAGS_64}"
    433             ARFLAGS="${ARFLAGS_64}"     
    434             BITS_OK=yes
    435         elif test "$BITS_OK" != "yes"; then
    436             AC_MSG_ERROR([Requested $BITS_REQ bit binaries but could not compile and execute them. See readme.html for help with cross compilation., and set compiler options manually.])
    437         fi
    438      fi
    439 ])
    440 
    441 # Strict compilation options.
    442 AC_DEFUN([AC_CHECK_STRICT_COMPILE],
    443 [
    444     AC_MSG_CHECKING([whether strict compiling is on])
    445     AC_ARG_ENABLE(strict,[  --enable-strict         compile with strict compiler options [default=yes]], [
    446         if test "$enableval" = no
    447         then
    448             ac_use_strict_options=no
    449         else
    450             ac_use_strict_options=yes
    451         fi
    452       ], [ac_use_strict_options=yes])
    453     AC_MSG_RESULT($ac_use_strict_options)
    454 
    455     if test "$ac_use_strict_options" = yes
    456     then
    457         if test "$GCC" = yes
    458         then
    459             case "${host}" in
    460             *-*-solaris*)
    461                 # Don't use -std=c99 option on Solaris/GCC
    462                 ;;
    463             *)
    464                 # Do not use -ansi. It limits us to C90, and it breaks some platforms.
    465                 # We use -std=c99 to disable the gnu99 defaults and its associated warnings
    466                 CFLAGS="$CFLAGS -std=c99"
    467                 ;;
    468             esac
    469             
    470             CFLAGS="$CFLAGS -Wall -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings"
    471         else
    472             case "${host}" in
    473             *-*-cygwin)
    474                 if test "`$CC /help 2>&1 | head -c9`" = "Microsoft"
    475                 then
    476                     CFLAGS="$CFLAGS /W4"
    477                 fi
    478             esac
    479         fi
    480         if test "$GXX" = yes
    481         then
    482             CXXFLAGS="$CXXFLAGS -W -Wall -pedantic -Wpointer-arith -Wwrite-strings -Wno-long-long"
    483         else
    484             case "${host}" in
    485             *-*-cygwin)
    486                 if test "`$CXX /help 2>&1 | head -c9`" = "Microsoft"
    487                 then
    488                     CXXFLAGS="$CXXFLAGS /W4"
    489                 fi
    490             esac
    491         fi
    492     fi
    493 ])
    494 
    495 
    496