|
1 #!/bin/sh |
|
2 |
|
3 # create temporary directory |
|
4 TEMP_DIR=".tmp-`uname -n`" |
|
5 rm -Rf "$TEMP_DIR" |
|
6 if mkdir -p "$TEMP_DIR"; then |
|
7 : |
|
8 else |
|
9 echo "Cannot create tmp dir $TEMP_DIR" |
|
10 echo "Abort" |
|
11 exit 1 |
|
12 fi |
|
13 touch "$TEMP_DIR/options" |
|
14 touch "$TEMP_DIR/features" |
|
15 |
|
16 # define standard variables |
|
17 PREFIX=/usr |
|
18 EPREFIX= |
|
19 BINDIR= |
|
20 SBINDIR= |
|
21 LIBDIR= |
|
22 LIBEXECDIR= |
|
23 DATADIR= |
|
24 SYSCONFDIR= |
|
25 SHAREDSTATEDIR= |
|
26 LOCALSTATEDIR= |
|
27 INCLUDEDIR= |
|
28 INFODIR= |
|
29 MANDIR= |
|
30 |
|
31 # custom variables |
|
32 MKDIR="mkdir -p" |
|
33 RMDIR="rm -fR" |
|
34 |
|
35 # features |
|
36 |
|
37 # clean abort |
|
38 abort_configure() |
|
39 { |
|
40 rm -Rf "$TEMP_DIR" |
|
41 exit 1 |
|
42 } |
|
43 |
|
44 # help text |
|
45 printhelp() |
|
46 { |
|
47 echo "Usage: $0 [OPTIONS]..." |
|
48 cat << __EOF__ |
|
49 Installation directories: |
|
50 --prefix=PREFIX path prefix for architecture-independent files |
|
51 [/usr] |
|
52 --exec-prefix=EPREFIX path prefix for architecture-dependent files |
|
53 [PREFIX] |
|
54 |
|
55 --bindir=DIR user executables [EPREFIX/bin] |
|
56 --sbindir=DIR system admin executables [EPREFIX/sbin] |
|
57 --libexecdir=DIR program executables [EPREFIX/libexec] |
|
58 --sysconfdir=DIR system configuration files [PREFIX/etc] |
|
59 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] |
|
60 --localstatedir=DIR modifiable single-machine data [PREFIX/var] |
|
61 --libdir=DIR object code libraries [EPREFIX/lib] |
|
62 --includedir=DIR C header files [PREFIX/include] |
|
63 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] |
|
64 --datadir=DIR read-only architecture-independent data [DATAROOTDIR] |
|
65 --infodir=DIR info documentation [DATAROOTDIR/info] |
|
66 --mandir=DIR man documentation [DATAROOTDIR/man] |
|
67 |
|
68 __EOF__ |
|
69 } |
|
70 |
|
71 # |
|
72 # parse arguments |
|
73 # |
|
74 BUILD_TYPE="default" |
|
75 for ARG in "$@" |
|
76 do |
|
77 case "$ARG" in |
|
78 "--prefix="*) PREFIX=${ARG#--prefix=} ;; |
|
79 "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;; |
|
80 "--bindir="*) BINDIR=${ARG#----bindir=} ;; |
|
81 "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;; |
|
82 "--libdir="*) LIBDIR=${ARG#--libdir=} ;; |
|
83 "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;; |
|
84 "--datadir="*) DATADIR=${ARG#--datadir=} ;; |
|
85 "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;; |
|
86 "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;; |
|
87 "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;; |
|
88 "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;; |
|
89 "--infodir="*) INFODIR=${ARG#--infodir=} ;; |
|
90 "--mandir"*) MANDIR=${ARG#--mandir} ;; |
|
91 "--help"*) printhelp; abort_configure ;; |
|
92 "--debug") BUILD_TYPE="debug" ;; |
|
93 "--release") BUILD_TYPE="release" ;; |
|
94 "-"*) echo "unknown option: $ARG"; abort_configure ;; |
|
95 esac |
|
96 done |
|
97 |
|
98 |
|
99 # set dir variables |
|
100 : ${EPREFIX:="$PREFIX"} |
|
101 : ${BINDIR:="$EPREFIX/bin"} |
|
102 : ${SBINDIR:="$EPREFIX/sbin"} |
|
103 : ${LIBDIR:="$EPREFIX/lib"} |
|
104 : ${LIBEXECDIR:="$EPREFIX/libexec"} |
|
105 : ${DATADIR:="$PREFIX/share"} |
|
106 : ${SYSCONFDIR:="$PREFIX/etc"} |
|
107 : ${SHAREDSTATEDIR:="$PREFIX/com"} |
|
108 : ${LOCALSTATEDIR:="$PREFIX/var"} |
|
109 : ${INCLUDEDIR:="$PREFIX/include"} |
|
110 : ${INFODIR:="$PREFIX/info"} |
|
111 : ${MANDIR:="$PREFIX/man"} |
|
112 |
|
113 # Test for availability of pkg-config |
|
114 PKG_CONFIG=`command -v pkg-config` |
|
115 : ${PKG_CONFIG:="false"} |
|
116 |
|
117 # Simple uname based platform detection |
|
118 # $PLATFORM is used for platform dependent dependency selection |
|
119 OS=`uname -s` |
|
120 OS_VERSION=`uname -r` |
|
121 printf "detect platform... " |
|
122 if [ "$OS" = "SunOS" ]; then |
|
123 PLATFORM="solaris sunos unix svr4" |
|
124 fi |
|
125 if [ "$OS" = "Linux" ]; then |
|
126 PLATFORM="linux unix" |
|
127 fi |
|
128 if [ "$OS" = "FreeBSD" ]; then |
|
129 PLATFORM="freebsd bsd unix" |
|
130 fi |
|
131 if [ "$OS" = "Darwin" ]; then |
|
132 PLATFORM="macos osx bsd unix" |
|
133 fi |
|
134 if echo "$OS" | grep -i "MINGW" > /dev/null; then |
|
135 PLATFORM="windows mingw" |
|
136 fi |
|
137 : ${PLATFORM:="unix"} |
|
138 |
|
139 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` |
|
140 echo "$PLATFORM_NAME" |
|
141 |
|
142 isplatform() |
|
143 { |
|
144 for p in $PLATFORM |
|
145 do |
|
146 if [ "$p" = "$1" ]; then |
|
147 return 0 |
|
148 fi |
|
149 done |
|
150 return 1 |
|
151 } |
|
152 notisplatform() |
|
153 { |
|
154 for p in $PLATFORM |
|
155 do |
|
156 if [ "$p" = "$1" ]; then |
|
157 return 1 |
|
158 fi |
|
159 done |
|
160 return 0 |
|
161 } |
|
162 |
|
163 |
|
164 # generate vars.mk |
|
165 cat > "$TEMP_DIR/vars.mk" << __EOF__ |
|
166 PREFIX="$PREFIX" |
|
167 EPREFIX="$EPREFIX" |
|
168 BINDIR="$BINDIR" |
|
169 SBINDIR="$SBINDIR" |
|
170 LIBDIR="$LIBDIR" |
|
171 LIBEXECDIR="$LIBEXECDIR" |
|
172 DATADIR="$DATADIR" |
|
173 SYSCONFDIR="$SYSCONFDIR" |
|
174 SHAREDSTATEDIR="$SHAREDSTATEDIR" |
|
175 LOCALSTATEDIR="$LOCALSTATEDIR" |
|
176 INCLUDEDIR="$INCLUDEDIR" |
|
177 INFODIR="$INFODIR" |
|
178 MANDIR="$MANDIR" |
|
179 MKDIR=$MKDIR |
|
180 RMDIR=$RMDIR |
|
181 __EOF__ |
|
182 sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk" |
|
183 |
|
184 |
|
185 # toolchain detection utilities |
|
186 . make/toolchain.sh |
|
187 |
|
188 # |
|
189 # DEPENDENCIES |
|
190 # |
|
191 |
|
192 # check languages |
|
193 lang_c= |
|
194 lang_cpp= |
|
195 if detect_c_compiler ; then |
|
196 lang_c=1 |
|
197 fi |
|
198 |
|
199 # create buffer for make variables required by dependencies |
|
200 echo > "$TEMP_DIR/make.mk" |
|
201 |
|
202 test_pkg_config() |
|
203 { |
|
204 if "$PKG_CONFIG" --exists "$1" ; then : |
|
205 else return 1 ; fi |
|
206 if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then : |
|
207 else return 1 ; fi |
|
208 if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then : |
|
209 else return 1 ; fi |
|
210 if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then : |
|
211 else return 1 ; fi |
|
212 return 0 |
|
213 } |
|
214 |
|
215 dependency_error_ucx() |
|
216 { |
|
217 printf "checking for ucx... " |
|
218 # dependency ucx |
|
219 while true |
|
220 do |
|
221 if check_lib ucx cx/list.h > /dev/null ; then |
|
222 : |
|
223 else |
|
224 break |
|
225 fi |
|
226 TEMP_LDFLAGS="$TEMP_LDFLAGS -lucx" |
|
227 echo yes |
|
228 return 1 |
|
229 done |
|
230 |
|
231 echo no |
|
232 return 0 |
|
233 } |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 # start collecting dependency information |
|
239 echo > "$TEMP_DIR/flags.mk" |
|
240 |
|
241 DEPENDENCIES_FAILED= |
|
242 ERROR=0 |
|
243 # unnamed dependencies |
|
244 TEMP_CFLAGS= |
|
245 TEMP_CXXFLAGS= |
|
246 TEMP_LDFLAGS= |
|
247 while true |
|
248 do |
|
249 while true |
|
250 do |
|
251 if [ -z "$lang_c" ] ; then |
|
252 ERROR=1 |
|
253 break |
|
254 fi |
|
255 |
|
256 break |
|
257 done |
|
258 break |
|
259 done |
|
260 |
|
261 # add general dependency flags to flags.mk |
|
262 echo "# general flags" >> "$TEMP_DIR/flags.mk" |
|
263 if [ -n "${TEMP_CFLAGS}" ]; then |
|
264 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
|
265 fi |
|
266 if [ -n "${TEMP_CXXFLAGS}" ]; then |
|
267 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
|
268 fi |
|
269 if [ -n "${TEMP_LDFLAGS}" ]; then |
|
270 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
|
271 fi |
|
272 |
|
273 # |
|
274 # OPTION VALUES |
|
275 # |
|
276 |
|
277 # |
|
278 # TARGETS |
|
279 # |
|
280 |
|
281 echo >> "$TEMP_DIR/flags.mk" |
|
282 # Target: default |
|
283 echo "# flags for target default" >> "$TEMP_DIR/flags.mk" |
|
284 TEMP_CFLAGS= |
|
285 TEMP_CXXFLAGS= |
|
286 TEMP_LDFLAGS= |
|
287 |
|
288 if dependency_error_ucx; then |
|
289 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ucx " |
|
290 ERROR=1 |
|
291 fi |
|
292 |
|
293 # Features |
|
294 |
|
295 |
|
296 if [ -n "${TEMP_CFLAGS}" ]; then |
|
297 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
|
298 fi |
|
299 if [ -n "${TEMP_CXXFLAGS}" ]; then |
|
300 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
|
301 fi |
|
302 if [ "$BUILD_TYPE" = "debug" ]; then |
|
303 echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
304 echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
305 fi |
|
306 if [ "$BUILD_TYPE" = "release" ]; then |
|
307 echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
308 echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
309 fi |
|
310 if [ -n "${TEMP_LDFLAGS}" ]; then |
|
311 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
|
312 fi |
|
313 |
|
314 |
|
315 # final result |
|
316 if [ $ERROR -ne 0 ]; then |
|
317 echo |
|
318 echo "Error: Unresolved dependencies" |
|
319 echo "$DEPENDENCIES_FAILED" |
|
320 abort_configure |
|
321 fi |
|
322 |
|
323 echo "configure finished" |
|
324 echo |
|
325 echo "Build Config:" |
|
326 echo " PREFIX: $PREFIX" |
|
327 echo " TOOLCHAIN: $TOOLCHAIN_NAME" |
|
328 echo |
|
329 |
|
330 # generate the config.mk file |
|
331 cat > "$TEMP_DIR/config.mk" << __EOF__ |
|
332 # |
|
333 # config.mk generated by configure |
|
334 # |
|
335 |
|
336 __EOF__ |
|
337 write_toolchain_defaults "$TEMP_DIR/toolchain.mk" |
|
338 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk |
|
339 rm -Rf "$TEMP_DIR" |
|
340 |
|
341 |