1#!/bin/sh
2# Copyright (c) 1999-2015, International Business Machines Corporation and
3# others. All Rights Reserved.
4
5# runConfigureICU: This script will run the "configure" script for the appropriate platform
6# Only supported platforms are recognized
7
8me=`basename $0`
9OPTS=
10
11usage()
12{
13    ec=0$1
14    if test $ec -eq 0
15    then
16        uletter=U
17    else
18        uletter=u
19    fi
20
21    echo "${uletter}sage: $me [ -h, --help ]  [ --enable-debug | --disable-release ] platform [ configurearg ... ]"
22    if test $ec -eq 0
23    then
24        cat <<EOE
25
26Options: -h, --help         Print this message and exit
27         --enable-debug     Enable support for debugging
28         --disable-release  Disable presetting optimization flags
29
30If you want to add custom CFLAGS or CXXFLAGS or similar, provide them _before_
31the runConfigureICU command:
32
33    CXXFLAGS=xyz path/to/runConfigureICU --enable-debug ...
34
35The following names can be supplied as the argument for platform:
36
37    AIX                 Use the IBM Visual Age xlc_r/xlC_r compilers on AIX
38    AIX/GCC             Use the GNU gcc/g++ compilers on AIX
39    Cygwin              Use the GNU gcc/g++ compilers on Cygwin
40    Cygwin/MSVC         Use the Microsoft Visual C++ compiler on Cygwin
41    Cygwin/MSVC2005     Use the Microsoft Visual C++ 2005 compiler on Cygwin
42    Cygwin/ICL          Use the Intel C++ compiler on Cygwin
43    FreeBSD             Use the clang/clang++ or GNU gcc/g++ compilers on FreeBSD
44    HP-UX/ACC           Use the HP ANSI C/Advanced C++ compilers on HP-UX 11
45    IBMi                Use the iCC compilers on IBM i, i5/OS, OS/400
46    Linux               Use the clang/clang++ or GNU gcc/g++ compilers on Linux
47    Linux/gcc           Use the GNU gcc/g++ compilers on Linux
48    Linux/ECC           Use the Intel ECC compiler on Linux
49    Linux/ICC           Use the Intel ICC compiler on Linux
50    Linux/VA            Use the IBM Visual Age compiler on Power PC Linux
51    MacOSX              Use the default compilers on MacOS X (Darwin)
52    MacOSX/GCC          Use the GNU gcc/g++ compilers on MacOSX (Darwin)
53    MinGW               Use the GNU gcc/g++ compilers on MinGW
54    MSYS/MSVC           Use the Microsoft Visual C++ computer on MSYS
55    QNX                 Use the QNX QCC compiler on QNX/Neutrino
56    Solaris             Use the Sun cc/CC compilers on Solaris
57    Solaris/GCC         Use the GNU gcc/g++ compilers on Solaris
58    SolarisX86          Use the Sun cc/CC compilers on Solaris x86
59    TRU64V5.1/CXX       Use the Compaq cxx compiler on Tru64 (OSF)
60    zOS                 Use the IBM cxx compiler on z/OS (os/390)
61    zOSV1R2             Use the IBM cxx compiler for z/OS 1.2
62EOE
63    fi
64
65    exit $ec
66}
67
68# Parse arguments
69
70platform=
71debug=0
72release=1
73
74while test $# -ne 0
75do
76    case "$1" in
77    -h|--help)
78        usage 0
79        ;;
80    --enable-debug)
81        debug=1
82        OPTS="$OPTS --enable-debug"
83        ;;
84    --disable-release)
85        release=0
86        OPTS="$OPTS --disable-release"
87        ;;
88    *)
89        platform="$1"
90        shift
91        break
92        ;;
93    esac
94    shift
95done
96
97if test x$platform = x
98then
99   usage 1
100fi
101
102# Go.
103
104rm -f config.cache
105rm -f config.log
106rm -f config.status
107
108DEBUG_CFLAGS='-g'
109DEBUG_CXXFLAGS='-g'
110
111if test x$configure = x
112then
113    if test -f ./configure
114    then
115        configuredir=.
116    else
117        configuredir=`echo $0 | sed 's,[^/]*$,,'`
118        if test x$configuredir = x$0
119        then
120            configuredir=.
121        fi
122    fi
123
124    if test x$configuredir = x
125    then
126        configuredir=.
127    fi
128
129    configure=$configuredir/configure
130fi
131
132case $platform in
133    AIX)
134        THE_OS=AIX
135        THE_COMP="xlC_r"
136        CC=`which xlc_r`; export CC
137        if [ ! -x $CC ]; then
138           echo "ERROR: xlc_r was not found, please check the PATH to make sure it is correct."; exit 1
139        fi
140        CXX=`which xlC_r`; export CXX
141        if [ ! -x $CXX ]; then
142           echo "ERROR: xlC_r was not found, please check the PATH to make sure it is correct."; exit 1
143        fi
144        RELEASE_CFLAGS="-O2 -qmaxmem=-1"
145        RELEASE_CXXFLAGS="-O2 -qmaxmem=-1"
146        ;;
147    AIX/GCC)
148        THE_OS=AIX
149        THE_COMP="the GNU C++"
150        CC=gcc; export CC
151        CXX=g++; export CXX
152        DEBUG_CFLAGS='-g -O0'
153        DEBUG_CXXFLAGS='-g -O0'
154        ;;
155    Solaris)
156        THE_OS=SOLARIS
157        THE_COMP="Sun's CC"
158        CC=`which cc`; export CC
159        CXX=`which CC`; export CXX
160        RELEASE_CFLAGS="-xO1 -xlibmil"
161        RELEASE_CXXFLAGS="-O4 -xlibmil"
162        ;;
163    Solaris/GCC)
164        THE_OS=SOLARIS
165        THE_COMP="the GNU C++"
166        CC=gcc; export CC
167        CXX=g++; export CXX
168        RELEASE_CFLAGS=-O1
169        RELEASE_CXXFLAGS=-O2
170        ;;
171    SolarisX86)
172        THE_OS="SOLARIS X86"
173        THE_COMP="Sun's CC"
174        CC=`which cc`; export CC
175        CXX=`which CC`; export CXX
176        LDFLAGS="${LDFLAGS} -lCrun";export LDFLAGS
177        RELEASE_CFLAGS=-xO3
178        RELEASE_CXXFLAGS=-O3
179        ;;
180    HP-UX/ACC)
181        THE_OS="HP-UX 11"
182        THE_COMP="aCC"
183        CC=cc; export CC
184        CXX=aCC; export CXX
185        RELEASE_CFLAGS='+O2 +Ofltacc'
186        RELEASE_CXXFLAGS='+O2 +Ofltacc'
187        ;;
188    IBMi)
189        THE_OS="IBM i"
190        THE_COMP="the iCC C++"
191        CC=icc; export CC
192        CXX=icc; export CXX
193        CPP="$CC -c -qpponly"; export CPP
194        MAKE=gmake; export MAKE
195        U_MAKE=gmake; export U_MAKE
196        # gmake is a .pgm and may not be on the path.  Don't use a full path, just use gmake.
197        ac_cv_path_U_MAKE=gmake; export ac_cv_path_U_MAKE
198        RELEASE_CFLAGS='-O4'
199        RELEASE_CXXFLAGS='-O4'
200        ;;
201    Linux/ECC)
202        THE_OS="Linux"
203        THE_COMP="Intel ECC 7.1"
204        CC=ecc; export CC
205        CXX=ecpc; export CXX
206        RELEASE_CFLAGS='-O2'
207        RELEASE_CXXFLAGS='-O2'
208        ;;
209    Linux/ICC)
210        THE_OS="Linux"
211        CC=`which icc`; export CC
212        CXX=`which icpc`; export CXX
213	ICC_VER=`${CC} -v 2>&1`
214        RELEASE_CFLAGS='-O'
215        RELEASE_CXXFLAGS='-O'
216        export CFLAGS="-fp-model precise"
217        export CXXFLAGS="-fp-model precise"
218	if [ "${ICC_VER}" = "Version 9.0 " ]; then
219		RELEASE_CFLAGS=''
220		RELEASE_CXXFLAGS=''
221		export CFLAGS="${CFLAGS} -O0"
222		export CXXFLAGS="${CXXFLAGS} -O0"
223		echo "ICC 9.0 does not work with optimization- disabling optimizations"
224	fi
225        THE_COMP="Intel ${ICC_VER}"
226        ;;
227    Linux/VA)
228        THE_OS="Linux"
229        THE_COMP="IBM Visual Age C++ Compiler"
230        CC=`which xlc_r`; export CC
231        CXX=`which xlC_r`; export CXX
232        RELEASE_CFLAGS="-O2 -qmaxmem=-1"
233        RELEASE_CXXFLAGS="-O2 -qmaxmem=-1"
234        ;;
235    Linux/gcc)
236        THE_OS="Linux"
237        THE_COMP="the GNU C++"
238        CC=gcc; export CC
239        CXX=g++; export CXX
240        RELEASE_CFLAGS='-O3'
241        RELEASE_CXXFLAGS='-O3'
242        DEBUG_CFLAGS='-g'
243        DEBUG_CXXFLAGS='-g'
244        ;;
245    Linux*)
246        THE_OS="Linux"
247        THE_COMP="the clang or else GNU C++"
248        RELEASE_CFLAGS='-O3'
249        RELEASE_CXXFLAGS='-O3'
250        DEBUG_CFLAGS='-g'
251        DEBUG_CXXFLAGS='-g'
252        ;;
253    Cygwin)
254        THE_OS="Cygwin"
255        THE_COMP="the GNU C++"
256        RELEASE_CFLAGS='-O3'
257        RELEASE_CXXFLAGS='-O3'
258        ;;
259    Cygwin/MSVC)
260        THE_OS="Windows with Cygwin"
261        THE_COMP="Microsoft Visual C++"
262        CC=cl; export CC
263        CXX=cl; export CXX
264        RELEASE_CFLAGS='-Gy -MD'
265        RELEASE_CXXFLAGS='-Gy -MD'
266        DEBUG_CFLAGS='-Zi -MDd'
267        DEBUG_CXXFLAGS='-Zi -MDd'
268        DEBUG_LDFLAGS='-DEBUG'
269        ;;
270    Cygwin/MSVC2005)
271        THE_OS="Windows with Cygwin"
272        THE_COMP="Microsoft Visual C++ 2005"
273        CC=cl; export CC
274        CXX=cl; export CXX
275        RELEASE_CFLAGS='/Gy /MD'
276        RELEASE_CXXFLAGS='/Gy /MD'
277        DEBUG_CFLAGS='/Zi /MDd'
278        DEBUG_CXXFLAGS='/Zi /MDd'
279        DEBUG_LDFLAGS='/DEBUG'
280        ;;
281    Cygwin/ICL)
282        THE_OS="Windows with Cygwin"
283        THE_COMP="Intel C++"
284        CC=icl; export CC
285        CXX=icl; export CXX
286        # The Intel compiler has optimization bugs. So we disable optimization.
287        RELEASE_CFLAGS='/Od'
288        RELEASE_CXXFLAGS='/Od'
289        DEBUG_CFLAGS='/Zi'
290        DEBUG_CXXFLAGS='/Zi'
291        DEBUG_LDFLAGS='/DEBUG'
292        ;;
293    MacOSX)
294        THE_OS="MacOS X (Darwin)"
295        THE_COMP="the default"
296        RELEASE_CFLAGS='-O2'
297        RELEASE_CXXFLAGS='-O2'
298        DEBUG_CFLAGS='-g -O0'
299        DEBUG_CXXFLAGS='-g -O0'
300        ;;
301    MacOSX/GCC)
302        THE_OS="MacOS X (Darwin)"
303        THE_COMP="the GNU C++"
304        RELEASE_CFLAGS='-O2'
305        RELEASE_CXXFLAGS='-O2'
306        DEBUG_CFLAGS='-g -O0'
307        DEBUG_CXXFLAGS='-g -O0'
308        CC=gcc; export CC
309        CXX=g++; export CXX
310        ;;
311    MinGW)
312        THE_OS="MinGW"
313        THE_COMP="the GNU C++"
314        RELEASE_CFLAGS='-O3'
315        RELEASE_CXXFLAGS='-O3'
316        CXXFLAGS="--std=c++03"
317        export CXXFLAGS
318        ;;
319    MSYS/MSVC)
320        THE_OS="MSYS"
321        THE_COMP="Microsoft Visual C++"
322        CC=cl; export CC
323        CXX=cl; export CXX
324        RELEASE_CFLAGS='-Gy -MD'
325        RELEASE_CXXFLAGS='-Gy -MD'
326        DEBUG_CFLAGS='-Zi -MDd'
327        DEBUG_CXXFLAGS='-Zi -MDd'
328        DEBUG_LDFLAGS='-DEBUG'
329        ;;
330    *BSD)
331        THE_OS="BSD"
332        THE_COMP="the GNU C++"
333        DEBUG_CFLAGS='-g -O0'
334        DEBUG_CXXFLAGS='-g -O0'
335        ;;
336    TRU64V5.1/CXX)
337        THE_OS="OSF1"
338        THE_COMP="Compaq cxx"
339        CC=cc; export CC
340        CXX=cxx; export CXX
341        ;;
342    QNX)
343        THE_OS="QNX"
344        THE_COMP="QNX cc"
345        CC=qcc; export CC
346        CXX=QCC; export CXX
347        ;;
348    zOS)
349        THE_OS="z/OS (OS/390)"
350        THE_COMP="z/OS C/C++"
351        CC=xlc; export CC
352        CXX=xlC; export CXX
353        RELEASE_CFLAGS="-O2 -Wc,'inline(AUTO,NOREPORT,1000,8000)'"
354        RELEASE_CXXFLAGS="-O2 -Wc,'inline(AUTO,NOREPORT,1000,8000)'"
355        ;;
356    zOSV1R2)
357        THE_OS="z/OS 1.2"
358        THE_COMP="z/OS 1.2 C/C++"
359        CC=cc; export CC
360        CXX=cxx; export CXX
361        export COMPILE_LINK_ENVVAR='_CXX_CICC_VER}=0x41020000 _C89_CVERSION=0x41020000 _CC_CVERSION=0x41020000 _CXX_PVERSION=0x41020000 _C89_PVERSION=0x41020000 _CC_PVERSION=0x41020000'
362        export _CXX_CVERSION=0x41020000 _C89_CVERSION=0x41020000 _CC_CVERSION=0x41020000 _CXX_PVERSION=0x41020000 _C89_PVERSION=0x41020000 _CC_PVERSION=0x41020000
363        export LDFLAGS="-Wl,'compat=pm3'"
364        export CFLAGS="-Wc,'target(zOSV1R2)'"
365        export CXXFLAGS="-Wc,'target(zOSV1R2)'"
366        RELEASE_CFLAGS="-2 -Wc,'inline(auto,noreport,500,4000)'"
367        RELEASE_CXXFLAGS="-2 -Wc,'inline(auto,noreport,500,4000)'"
368        ;;
369    *)
370        >&2 echo "$me: unrecognized platform \"$platform\" (use --help for help)"
371        exit 1;;
372esac
373
374
375# Tweak flags
376
377if test $release -eq 1
378then
379    if test "$RELEASE_CFLAGS" = ""
380    then
381        case $CC in
382            gcc|*/gcc|*-gcc-*|*/*-gcc-*)
383                RELEASE_CFLAGS=-O3
384                ;;
385        esac
386    fi
387    if test "$RELEASE_CFLAGS" != ""
388    then
389        CFLAGS="$RELEASE_CFLAGS $CFLAGS"
390    fi
391    if test "$RELEASE_CXXFLAGS" = ""
392    then
393        case $CXX in
394            g++|*/g++|*-g++-*|*/*-g++-*)
395                RELEASE_CXXFLAGS=-O3
396                ;;
397        esac
398    fi
399    if test "$RELEASE_CXXFLAGS" != ""
400    then
401        CXXFLAGS="$RELEASE_CXXFLAGS $CXXFLAGS"
402    fi
403    if test "$RELEASE_LDFLAGS" != ""
404    then
405        LDFLAGS="$RELEASE_LDFLAGS $LDFLAGS"
406    fi
407fi
408
409if test $debug -eq 1
410then
411    if test "$DEBUG_CFLAGS" != ""
412    then
413        CFLAGS="$DEBUG_CFLAGS $CFLAGS"
414    fi
415    if test "$DEBUG_CXXFLAGS" != ""
416    then
417        CXXFLAGS="$DEBUG_CXXFLAGS $CXXFLAGS"
418    fi
419    if test "$DEBUG_LDFLAGS" != ""
420    then
421        LDFLAGS="$DEBUG_LDFLAGS $LDFLAGS"
422    fi
423fi
424
425export CFLAGS
426export CXXFLAGS
427export LDFLAGS
428
429# Run configure
430
431echo "export CPP=$CPP CC=$CC CXX=$CXX CPPFLAGS=$CPPFLAGS CFLAGS=$CFLAGS CXXFLAGS=$CXXFLAGS LDFLAGS=$LDFLAGS MAKE=$MAKE"
432echo "Running ./configure $OPTS $@ for $THE_OS using $THE_COMP compiler"
433echo
434if $configure $OPTS $@
435then
436	echo
437	echo If the result of the above commands looks okay to you, go to the directory
438	echo source in the ICU distribution to build ICU. Please remember that ICU needs
439	echo GNU make to build properly...
440else
441	echo $0: ./configure failed
442	exit 1
443fi
444