1
#!/bin/sh
2
3
# Time-stamp: <09/01/09 12:08:03 ptr>
4
5
#
6
# Copyright (c) 2003-2010
7
# Petr Ovtchenkov
8
#
9
# This material is provided "as is", with absolutely no warranty expressed# or implied. Any use is at your own risk.
10
#
11
# Permission to use or copy this software for any purpose is hereby granted
12
# without fee, provided the above notices are retained on all copies.
13
# Permission to modify the code and to distribute modified code is granted,
14
# provided the above notices are retained, and a notice that the code was
15
# modified is included with the above copyright notice.
16
#
17
18
base=`cd \`dirname $0\`; echo $PWD`
19
20
configmak=$base/Makefiles/gmake/config.mak
21
22
write_option() {
23
  target=`echo $1 | sed -e 's/^[^=]*=//'`
24
  echo $2 := $3$target >> ${configmak}
25
}
26
27
write_over_option() {
28
  target=`echo $1 | sed -e 's/^[^=]*=//'`
29
  echo $2 ?= $target >> ${configmak}
30
}
31
32
write_raw_option() {
33
  echo $2 := $3$1 >> ${configmak}
34
}
35
36
print_help() {
37
  cat <<EOF
38
Configuration utility.
39
40
Usage:
41
42
  configure [options]
43
44
Available options:
45
46
  --prefix=<dir>        base install path (/usr/local/)
47
  --bindir=<dir>        install path for executables (PREFIX/bin)
48
  --libdir=<dir>        install path for libraries (PREFIX/lib)
49
  --includedir=<dir>    install path for headers (PREFIX/include)
50
51
  --target=<target>     target platform (cross-compiling)
52
53
  --help                print this help message and exit
54
55
  --with-stlport=<dir>  use STLport in catalog <dir>
56
  --without-stlport     compile without STLport
57
  --with-boost=<dir>    use boost headers in catalog <dir>
58
  --with-system-boost   use boost installed on this system
59
  --with-msvc=<dir>     use MS VC from this catalog
60
  --with-mssdk=<dir>    use MS SDK from this catalog
61
  --with-extra-cxxflags=<options>
62
                        pass extra options to C++ compiler
63
  --with-extra-cflags=<options>
64
                        pass extra options to C compiler
65
  --with-extra-ldflags=<options>
66
                        pass extra options to linker (via C/C++)
67
  --use-static-gcc      use static gcc libs instead of shared libgcc_s (useful for gcc compiler,
68
                        that was builded with --enable-shared [default]; if compiler was builded
69
                        with --disable-shared, static libraries will be used in any case)
70
  --clean               remove custom settings (file ${configmak})
71
                        and use default values
72
  --with-cxx=<name>     use <name> as C++ compiler (use --target= for cross-compilation)
73
  --with-cc=<name>      use <name> as C compiler (use --target= for cross-compilation)
74
  --use-compiler-family=<name> use compiler family; one of:
75
                        gcc      GNU compilers (default)
76
                        icc      Intel compilers
77
                        aCC      HP's aCC compilers
78
                        CC       SunPro's CC compilers
79
                        bcc      Borland's compilers
80
  --without-debug       don't build debug variant
81
  --without-stldebug    don't build STLport's STLP_DEBUG mode
82
  --enable-static       build static
83
  --disable-shared      don't build shared 
84
  --with-lib-motif=<motif>
85
                        Use this option to customize the generated library name.
86
                        The motif will be used in the last place before version information,
87
                        separated by an underscore, ex:
88
                        stlportd_MOTIF.5.0.lib
89
                        stlportstld_static_MOTIF.5.1.lib
90
  --without-thread      Per default STLport libraries are built in order to be usable
91
                        in a multithreaded context. If you don't need this you can ask
92
                        for a not thread safe version with this option.
93
  --without-rtti        Disable RTTI when building libraries.
94
  --with-static-rtl
95
  --with-dynamic-rtl
96
                        Enables usage of static (libc.lib family) or dynamic (msvcrt.lib family)
97
                        C/C++ runtime library when linking with STLport. If you want your appli/dll
98
                        to link statically with STLport but using the dynamic C runtime use
99
                        --with-dynamic-rtl; if you want to link dynamicaly with STLport but using the
100
                        static C runtime use --with-static-rtl. See README.options for details.
101
                        Don't forget to signal the link method when building your appli or dll, in
102
                        stlport/stl/config/host.h set the following macro depending on the configure
103
                        option:
104
                        --with-static-rtl  -> _STLP_USE_DYNAMIC_LIB"
105
                        --with-dynamic-rtl -> _STLP_USE_STATIC_LIB"
106
  --windows-platform=<name>
107
                        Targetted OS when building for Windows; one of:
108
                        win95   Windows 95
109
                        win98   Windows 98
110
                        winxp   Windows XP and later (default)
111
112
Environment variables:
113
114
  \$CXX                 C++ compiler name (use --target= for cross-compilation)
115
  \$CC                  C compiler name (use --target= for cross-compilation)
116
  \$CXXFLAGS            pass extra options to C++ compiler
117
  \$CFLAGS              pass extra options to C compiler
118
  \$LDFLAGS             pass extra options to linker (via C/C++)
119
120
  Options has preference over environment variables.
121
122
EOF
123
}
124
125
default_settings () {
126
  # if [ "$boost_set" = "" ]; then
127
  #   write_option "${PWD}/external/boost" BOOST_DIR
128
  # fi
129
130
  # if [ -z "${stlport_set}" ]; then
131
  #   write_over_option "$base" STLPORT_DIR
132
  # fi
133
134
  # Set in Makefiles/gmake/top.mak
135
  if [ -z "${compiler_family_set}" ]; then
136
  #  write_option gcc COMPILER_NAME
137
    ln -sf Makefiles/gcc.mak ${base}/src/Makefile
138
    ln -sf Makefiles/gcc.mak ${base}/test/cmp_unit/Makefile
139
    ln -sf Makefiles/gcc.mak ${base}/test/unit/Makefile
140
    ln -sf Makefiles/gcc.mak ${base}/test/eh/Makefile
141
  fi
142
143
  # Set in Makefiles/gmake/targetdirs.mak
144
  # if [ -z "${prefix_set}" ]; then
145
  #   write_option "/usr/local" BASE_INSTALL_DIR '${DESTDIR}'
146
  # fi
147
}
148
149
for a in $@ ; do
150
  case $a in
151
    --help)
152
      print_help
153
      exit 0
154
      ;;
155
    --clean)
156
      rm -f ${configmak}
157
      exit 0
158
      ;;
159
  esac
160
done
161
162
>${configmak}
163
164
while :
165
do
166
  case $# in
167
    0)
168
      break
169
      ;;
170
  esac
171
  option="$1"
172
  shift
173
  case $option in
174
    --target=*)
175
      write_option "$option" TARGET_OS
176
      target_set=y
177
      ;;
178
    --with-stlport=*)
179
      write_option "$option" STLPORT_DIR
180
      stlport_set=y
181
      ;;
182
    --without-stlport)
183
      write_option 1 WITHOUT_STLPORT
184
      stlport_set=y
185
      ;;
186
    --with-boost=*)
187
      write_option "$option" BOOST_DIR
188
      ;;
189
    --with-system-boost)
190
      write_option 1 USE_SYSTEM_BOOST
191
      ;;
192
    --with-msvc=*)
193
      write_option "$option" MSVC_DIR
194
      ;;
195
    --with-mssdk=*)
196
      write_option "$option" MSSDK_DIR
197
      ;;
198
    --with-extra-cxxflags=*)
199
      write_option "$option" EXTRA_CXXFLAGS
200
      cxxflags_set=y
201
      ;;
202
    --with-extra-cflags=*)
203
      write_option "$option" EXTRA_CFLAGS
204
      cflags_set=y
205
      ;;
206
    --with-extra-ldflags=*)
207
      write_option "$option" EXTRA_LDFLAGS
208
      ldflags_set=y
209
      ;;
210
    --with-lib-motif=*)
211
      echo "Using $option in generated library names"
212
      write_option "$option" LIB_MOTIF
213
      ;;
214
    --without-thread)
215
      write_option 1 WITHOUT_THREAD
216
      ;;
217
    --without-rtti)
218
      write_option 1 WITHOUT_RTTI
219
      ;;
220
    --with-dynamic-rtl)
221
      write_option 1 WITH_DYNAMIC_RTL
222
      ;;
223
    --with-static-rtl)
224
      write_option 1 WITH_STATIC_RTL
225
      ;;
226
    --use-static-gcc)
227
      write_option 1 USE_STATIC_LIBGCC
228
      ;;
229
    --without-debug)
230
      write_option 1 _NO_DBG_BUILD
231
      ;;
232
    --without-stldebug)
233
      write_option 1 _NO_STLDBG_BUILD
234
      ;;
235
    --enable-static)
236
      write_option 1 _STATIC_BUILD
237
      ;;
238
    --disable-shared)
239
      write_option 1 _NO_SHARED_BUILD
240
      ;;
241
    --with-cxx=*)
242
      write_option "$option" _FORCE_CXX
243
      cxx_set=y
244
      ;;
245
    --with-cc=*)
246
      write_option "$option" _FORCE_CC
247
      cc_set=y
248
      ;;
249
    --use-compiler-family=*)
250
      case `echo $option | sed -e 's/^[^=]*=//'` in
251
        gcc|icc|aCC|CC|bcc|dmc)
252
          target=`echo $option | sed -e 's/^[^=]*=//'`
253
          echo COMPILER_NAME := $target >> ${configmak}
254
          ln -sf Makefiles/$target.mak ${base}/src/Makefile
255
          ln -sf Makefiles/$target.mak ${base}/test/cmp_unit/Makefile
256
          ln -sf Makefiles/$target.mak ${base}/test/unit/Makefile
257
          ln -sf Makefiles/$target.mak ${base}/test/eh/Makefile
258
          ;;
259
        *)
260
          echo "Not supported compilers family"
261
          exit -1
262
          ;;
263
      esac
264
      compiler_family_set=y
265
      ;;
266
    --prefix=*)
267
      write_option "$option" BASE_INSTALL_DIR '${DESTDIR}'
268
      prefix_set=y
269
      ;;
270
    --bindir=*)
271
      write_option "$option" INSTALL_BIN_DIR '${DESTDIR}'
272
      ;;
273
    --libdir=*)
274
      write_option "$option" INSTALL_LIB_DIR '${DESTDIR}'
275
      ;;
276
    --includedir=*)
277
      write_option "$option" INSTALL_HDR_DIR '${DESTDIR}'
278
      ;;
279
    --windows-platform=*)
280
      case `echo $option | sed -e 's/^[^=]*=//'` in
281
        win95)
282
          write_option 0x0400 WINVER
283
          ;;
284
        win98)
285
          write_option 0x0410 WINVER
286
          ;;
287
        winxp)
288
          write_option 0x0501 WINVER
289
          ;;
290
        *)
291
          echo "Not supported windows platform"
292
          exit -1
293
          ;;
294
      esac
295
      ;;
296
    '')
297
      ;;
298
    *)
299
      echo "Unknown configuration option '$option'"
300
      exit -1
301
      ;;
302
  esac
303
done
304
305
if [ -n "${CXX}" ]; then
306
  if [ -n "${cxx_set}" ]; then
307
    echo "Both --with-cxx and \$CXX set, using the first"
308
  elif [ -z "${target_set}" ]; then
309
    write_raw_option "${CXX}" _FORCE_CXX
310
  else
311
    echo "For cross-compilation with gcc use --target option only"
312
  fi
313
  if [ -z "${CC}" -a -z "${cc_set}" ]; then
314
    echo "\$CXX set, but I don't see \$CC!"
315
  fi
316
fi
317
318
if [ -n "${CC}" ]; then
319
  if [ -n "${cxx_set}" ]; then
320
    echo "Both --with-cc and \$CC set, using the first"
321
  else
322
    write_raw_option "${CC}" _FORCE_CC
323
  fi
324
fi
325
326
if [ -n "${CXXFLAGS}" ]; then
327
  if [ -z "${cxxflags_set}" ]; then
328
    write_raw_option "${CXXFLAGS}" EXTRA_CXXFLAGS
329
  else
330
    echo "Both --with-extra-cxxflags and \$CXXFLAGS set, using the first"
331
  fi
332
fi
333
334
if [ -n "${CFLAGS}" ]; then
335
  if [ -z "${cflags_set}" ]; then
336
    write_raw_option "${CFLAGS}" EXTRA_CFLAGS
337
  else
338
    echo "Both --with-extra-cflags and \$CFLAGS set, using the first"
339
  fi
340
fi
341
342
if [ -n "${LDFLAGS}" ]; then
343
  if [ -z "${ldflags_set}" ]; then
344
    write_raw_option "${LDFLAGS}" EXTRA_LDFLAGS
345
  else
346
    echo "Both --with-extra-ldflags and \$LDFLAGS set, using the first"
347
  fi
348
fi
349
350
default_settings