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