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