Debian Codegraph @

configure

raw ◀ ▶
1 Debian patch touch this file
1 #!/bin/sh
2 #
3 # Copyright © 2009-2013 Samy Al Bahra.
4 # Copyright © 2011 Devon H. O'Dell <[email protected]>
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # SUCH DAMAGE.
27 #
28
29 REQUIRE_HEADER="stdbool.h stddef.h stdint.h string.h"
30
31 EXIT_SUCCESS=0
32 EXIT_FAILURE=1
33 WANT_PIC=yes
34
35 BUILD_DIR=`pwd`
36 MAINTAINER='[email protected]'
37 VERSION=${VERSION:-'0.7.2'}
38 VERSION_MAJOR='0'
39 BUILD="$PWD/build/ck.build"
40 PREFIX=${PREFIX:-"/usr/local"}
41 LDNAME="libck.so"
42 LDNAME_VERSION="libck.so.$VERSION"
43 LDNAME_MAJOR="libck.so.$VERSION_MAJOR"
44 EXTRA_BUILD='doc'
45
46 OPTION_CHECKING=1
47
48 export CFLAGS
49 export PREFIX
50 LC_ALL=C
51 export LC_ALL
52
53 if test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
54 set -o posix
55 fi
56
57 trap epilog 1 2 3 6
58
59 epilog()
60 {
61 rm -f .1.c .1
62 }
63
64 assert()
65 {
66
67 if test "$#" -eq 2; then
68 fail=$2
69 print=true
70 elif test "$#" -eq 3; then
71 fail=$3
72 print=echo
73 else
74 echo "Usage: assert <test> <fail string> or assert <test> <success string> <fail string>" 1>&2
75 exit $EXIT_FAILURE
76 fi
77
78 if test -z "$1"; then
79 echo "failed [$fail]"
80 exit $EXIT_FAILURE
81 else
82 ${print} "success [$1]"
83 fi
84 }
85
86 get_git_sha()
87 {
88 # return a short SHA for the current HEAD
89 GIT_SHA=""
90 GIT_MSG="success"
91 gitcmd=`which git`
92 if test -n "$gitcmd"; then
93 GIT_SHA=`git rev-parse --short HEAD 2>/dev/null`
94 if ! test -n "$GIT_SHA"; then
95 GIT_MSG="not within a git repo"
96 fi
97 else
98 GIT_MSG="git not installed or executable"
99 fi
100 }
101
102 generate()
103 {
104 sed -e "s#@PROFILE@#$PROFILE#g" \
105 -e "s#@VERSION@#$VERSION#g" \
106 -e "s#@VERSION_MAJOR@#$VERSION_MAJOR#g" \
107 -e "s#@CC@#$CC#g" \
108 -e "s#@CFLAGS@#$CFLAGS#g" \
109 -e "s#@HEADERS@#$HEADERS#g" \
110 -e "s#@LIBRARY@#$LIBRARY#g" \
111 -e "s#@PREFIX@#$PREFIX#g" \
112 -e "s#@CORES@#$CORES#g" \
113 -e "s#@ALL_LIBS@#$ALL_LIBS#g" \
114 -e "s#@INSTALL_LIBS@#$INSTALL_LIBS#g" \
115 -e "s#@LD@#$LD#g" \
116 -e "s#@LDFLAGS@#$LDFLAGS#g" \
117 -e "s#@PTHREAD_CFLAGS@#$PTHREAD_CFLAGS#g" \
118 -e "s#@MANDIR@#$MANDIR#g" \
119 -e "s#@GZIP@#$GZIP#g" \
120 -e "s#@GZIP_SUFFIX@#$GZIP_SUFFIX#g" \
121 -e "s#@POINTER_PACK_ENABLE@#$POINTER_PACK_ENABLE#g" \
122 -e "s#@DISABLE_DOUBLE@#$DISABLE_DOUBLE#g" \
123 -e "s#@DISABLE_SHARED@#$DISABLE_SHARED#g" \
124 -e "s#@DISABLE_STATIC@#$DISABLE_STATIC#g" \
125 -e "s#@SSE_DISABLE@#$SSE_DISABLE#g" \
126 -e "s#@PPC32_LWSYNC_ENABLE@#$PPC32_LWSYNC_ENABLE#g" \
127 -e "s#@RTM_ENABLE@#$RTM_ENABLE#g" \
128 -e "s#@LSE_ENABLE@#$LSE_ENABLE#g" \
129 -e "s#@VMA_BITS@#$VMA_BITS_R#g" \
130 -e "s#@VMA_BITS_VALUE@#$VMA_BITS_VALUE_R#g" \
131 -e "s#@MM@#$MM#g" \
132 -e "s#@BUILD_DIR@#$BUILD_DIR#g" \
133 -e "s#@SRC_DIR@#$SRC_DIR#g" \
134 -e "s#@LDNAME@#$LDNAME#g" \
135 -e "s#@LDNAME_MAJOR@#$LDNAME_MAJOR#g" \
136 -e "s#@LDNAME_VERSION@#$LDNAME_VERSION#g" \
137 -e "s#@PC_CFLAGS@#$PC_CFLAGS#g" \
138 -e "s#@GIT_SHA@#$GIT_SHA#g" \
139 -e "s#@EXTRA_BUILD@#$EXTRA_BUILD#g" \
140 $1 > $2
141 }
142
143 generate_stdout()
144 {
145
146 echo
147 echo " VERSION = $VERSION"
148 echo " GIT_SHA = $GIT_SHA"
149 echo " BUILD_DIR = $BUILD_DIR"
150 echo " SRC_DIR = $SRC_DIR"
151 echo " SYSTEM = $SYSTEM"
152 echo " PROFILE = $PROFILE"
153 echo " AR = $AR"
154 echo " CC = $CC"
155 echo " COMPILER = $COMPILER"
156 echo " CFLAGS = $CFLAGS"
157 echo " PTHREAD_CFLAGS = $PTHREAD_CFLAGS"
158 echo " LD = $LD"
159 echo " LDNAME = $LDNAME"
160 echo " LDNAME_VERSION = $LDNAME_VERSION"
161 echo " LDNAME_MAJOR = $LDNAME_MAJOR"
162 echo " LDFLAGS = $LDFLAGS"
163 echo " SHARED_LIB = `expr $DISABLE_SHARED = 0`"
164 echo " STATIC_LIB = `expr $DISABLE_STATIC = 0`"
165 echo " EXTRA_BUILD = $EXTRA_BUILD"
166 echo " GZIP = $GZIP"
167 echo " CORES = $CORES"
168 echo " POINTER_PACK = $POINTER_PACK_ENABLE"
169 echo " PPC32_LWSYNC = $PPC32_LWSYNC_ENABLE"
170 echo " VMA_BITS = $VMA_BITS"
171 echo " MEMORY_MODEL = $MM"
172 echo " RTM = $RTM_ENABLE"
173 echo " LSE = $LSE_ENABLE"
174 echo " SSE = $SSE_DISABLE"
175 echo
176 echo "Headers will be installed in $HEADERS"
177 echo "Libraries will be installed in $LIBRARY"
178 echo "Documentation will be installed in $MANDIR"
179 }
180
181 for option; do
182 case "$option" in
183 --*=?*)
184 optname=`echo $option|cut -c 3-`
185 value=`expr "$optname" : '[^=]*=\(.*\)'`
186 ;;
187 --*=)
188 value=
189 ;;
190 --*)
191 value=yes
192 ;;
193 esac
194
195 case "$option" in
196 --help)
197 echo "Usage: $0 [OPTIONS]"
198 echo
199 echo "The following options may be used for cross-building."
200 echo " --profile=N Use custom build profile (use in conjunction with \$CC)"
201 echo
202 echo "The following options may be used to modify installation behavior."
203 echo " --includedir=N Headers directory (default is ${PREFIX}/include)"
204 echo " --libdir=N Libraries directory (default is ${PREFIX}/lib)"
205 echo " --mandir=N Manual pages directory (default is ${PREFIX}/man)"
206 echo " --prefix=N Installs library files in N (default is $PREFIX)"
207 echo
208 echo "The following options will affect generated code."
209 echo " --enable-pointer-packing Assumes address encoding is subset of pointer range"
210 echo " --memory-model=N Specify memory model (currently tso, pso or rmo)"
211 echo " --vma-bits=N Specify valid number of VMA bits"
212 echo " --platform=N Force the platform type, instead of relying on autodetection"
213 echo " --use-cc-builtins Use the compiler atomic builtin functions, instead of the CK implementation"
214 echo " --disable-double Don't generate any of the functions using the \"double\" type"
215 echo " --disable-static Don't compile a static version of the ck lib"
216 echo
217 echo "The following options will affect specific platform-dependent generated code."
218 echo " --disable-sse Do not use any SSE instructions (x86)"
219 echo " --enable-lse Enable large system extensions (arm64)"
220 echo " --enable-ppc32-lwsync Enable lwsync instruction usage (32-bit Power ISA)"
221 echo " --enable-rtm Enable restricted transactional memory (Power ISA, x86_64)"
222 echo
223 echo "The following options affect regression testing."
224 echo " --cores=N Specify number of cores available on target machine"
225 echo
226 echo "The following environment variables may be used:"
227 echo " AR AR archiver command"
228 echo " CC C compiler command"
229 echo " CFLAGS C compiler flags"
230 echo " LDFLAGS Linker flags"
231 echo " GZIP GZIP compression tool"
232 echo
233 echo "Report bugs to ${MAINTAINER}."
234 exit $EXIT_SUCCESS
235 ;;
236 --memory-model=*)
237 case "$value" in
238 "tso")
239 MM="CK_MD_TSO"
240 ;;
241 "rmo")
242 MM="CK_MD_RMO"
243 ;;
244 "pso")
245 MM="CK_MD_PSO"
246 ;;
247 *)
248 echo "./configure [--help]"
249 exit $EXIT_FAILURE
250 ;;
251 esac
252 ;;
253 --vma-bits=*)
254 VMA_BITS=$value
255 ;;
256 --enable-pointer-packing)
257 POINTER_PACK_ENABLE="CK_MD_POINTER_PACK_ENABLE"
258 ;;
259 --enable-ppc32-lwsync)
260 PPC32_LWSYNC_ENABLE="CK_MD_PPC32_LWSYNC"
261 ;;
262 --enable-rtm)
263 RTM_ENABLE_SET="CK_MD_RTM_ENABLE"
264 ;;
265 --enable-lse)
266 LSE_ENABLE_SET="CK_MD_LSE_ENABLE"
267 ;;
268 --disable-sse)
269 SSE_DISABLE="CK_MD_SSE_DISABLE"
270 ;;
271 --cores=*)
272 CORES=$value
273 ;;
274 --profile=*)
275 PROFILE=$value
276 ;;
277 --prefix=*)
278 PREFIX=$value
279 ;;
280 --includedir=*)
281 HEADERS=$value
282 ;;
283 --libdir=*)
284 LIBRARY=$value
285 ;;
286 --mandir=*)
287 MANDIR=$value
288 ;;
289 --with-pic)
290 WANT_PIC=yes
291 ;;
292 --without-pic)
293 WANT_PIC=no
294 ;;
295 --disable-option-checking)
296 OPTION_CHECKING=0
297 ;;
298 --use-cc-builtins)
299 USE_CC_BUILTINS=1
300 ;;
301 --disable-double)
302 DISABLE_DOUBLE="CK_PR_DISABLE_DOUBLE"
303 ;;
304 --disable-shared)
305 DISABLE_SHARED=1
306 ;;
307 --disable-static)
308 DISABLE_STATIC=1
309 ;;
310 --platform=*)
311 PLATFORM=$value
312 ;;
313 --build=*|--host=*|--target=*|--exec-prefix=*|--bindir=*|--sbindir=*|\
314 --sysconfdir=*|--datadir=*|--libexecdir=*|--localstatedir=*|\
315 --enable-static|\
316 --sharedstatedir=*|--infodir=*|--enable-shared|\
317 --cache-file=*|--srcdir=*)
318 # ignore for compat with regular configure
319 ;;
320 --*)
321 if test "$OPTION_CHECKING" -eq 1; then
322 echo "$0 [--help]"
323 echo "Unknown option $option"
324 exit $EXIT_FAILURE
325 fi
326 ;;
327 *=*)
328 value=`echo $option|cut -d '=' -f 2-`
329 NAME=`expr "$option" : '\([^=]*\)='`
330 eval "$NAME='$value'"
331 export $NAME
332 ;;
333 *)
334 echo "$0 [--help]"
335 echo "Unknown option $option"
336 exit $EXIT_FAILURE
337 ;;
338 esac
339 done
340
341 HEADERS=${HEADERS:-"${PREFIX}/include"}
342 LIBRARY=${LIBRARY:-"${PREFIX}/lib"}
343 MANDIR=${MANDIR:-"${PREFIX}/share/man"}
344 GZIP=${GZIP-"gzip -c"}
345 POINTER_PACK_ENABLE=${POINTER_PACK_ENABLE:-"CK_MD_POINTER_PACK_DISABLE"}
346 DISABLE_DOUBLE=${DISABLE_DOUBLE:-"CK_PR_ENABLE_DOUBLE"}
347 DISABLE_SHARED=${DISABLE_SHARED:-"0"}
348 DISABLE_STATIC=${DISABLE_STATIC:-"0"}
349 PPC32_LWSYNC_ENABLE=${PPC32_LWSYNC_ENABLE:-"CK_MD_PPC32_LWSYNC_DISABLE"}
350 RTM_ENABLE=${RTM_ENABLE_SET:-"CK_MD_RTM_DISABLE"}
351 SSE_DISABLE=${SSE_DISABLE:-"CK_MD_SSE_ENABLE"}
352 LSE_ENABLE=${LSE_ENABLE_SET:-"CK_MD_LSE_DISABLE"}
353 VMA_BITS=${VMA_BITS:-"unknown"}
354
355 DCORES=2
356 printf "Detecting operating system......."
357 SYSTEM=`uname -s 2> /dev/null`
358 case "$SYSTEM" in
359 "SunOS")
360 SYSTEM=solaris
361 ;;
362 "Linux"|"uClinux")
363 DCORES=`egrep '(^CPU[0-9]+|^processor.*:.*)' /proc/cpuinfo|wc -l`
364 SYSTEM=linux
365 ;;
366 "FreeBSD"|"GNU/kFreeBSD")
367 DCORES=`sysctl -n hw.ncpu`
368 SYSTEM=freebsd
369 ;;
370 "NetBSD")
371 DCORES=`sysctl -n hw.ncpu`
372 SYSTEM=netbsd
373 ;;
374 "OpenBSD")
375 DCORES=`sysctl -n hw.ncpu`
376 SYSTEM=openbsd
377 ;;
378 "DragonFly")
379 DCORES=`sysctl -n hw.ncpu`
380 SYSTEM=dragonflybsd
381 ;;
382 "Darwin")
383 DCORES=`sysctl -n hw.ncpu`
384 SYSTEM=darwin
385 ;;
386 MINGW32*|MSYS_NT*)
387 SYSTEM=mingw32
388 LDFLAGS="-mthreads $LDFLAGS"
389 ;;
390 MINGW64*)
391 SYSTEM=mingw64
392 LDFLAGS="-mthreads $LDFLAGS"
393 ;;
394 CYGWIN_NT*)
395 SYSTEM=cygwin
396 LDFLAGS="-mthreads $LDFLAGS"
397 ;;
398 *)
399 SYSTEM=
400 ;;
401 esac
402
403 assert "$SYSTEM" "$SYSTEM" "unsupported"
404
405 CORES=${CORES:-${DCORES}}
406 printf "Detecting machine architecture..."
407 if test "x$PLATFORM" = "x"; then
408 case $SYSTEM in
409 "freebsd")
410 PLATFORM=`uname -p 2> /dev/null`
411 ;;
412 *)
413 PLATFORM=`uname -m 2> /dev/null`
414 ;;
415 esac
416 fi
417
418 case $PLATFORM in
419 "macppc"|"Power Macintosh"|"powerpc"|"powerpcspe")
420 RTM_ENABLE="CK_MD_RTM_DISABLE"
421 LSE_ENABLE="CK_MD_LSE_DISABLE"
422 MM="${MM:-"CK_MD_RMO"}"
423 PLATFORM=ppc
424 ENVIRONMENT=32
425 LDFLAGS="-m32 $LDFLAGS"
426 ;;
427 "sun4u"|"sun4v"|"sparc64")
428 RTM_ENABLE="CK_MD_RTM_DISABLE"
429 LSE_ENABLE="CK_MD_LSE_DISABLE"
430 MM="${MM:-"CK_MD_TSO"}"
431 PLATFORM=sparcv9
432 ENVIRONMENT=64
433 LDFLAGS="-m64 $LDFLAGS"
434 ;;
435 i386|i486|i586|i686|i586_i686|pentium*|athlon*|k5|k6|k6_2|k6_3)
436 if test "${SSE_DISABLE}" = "CK_MD_SSE_ENABLE"; then
437 CFLAGS="$CFLAGS -msse -msse2"
438 fi
439 LSE_ENABLE="CK_MD_LSE_DISABLE"
440 MM="${MM:-"CK_MD_TSO"}"
441 case $SYSTEM in
442 darwin)
443 ENVIRONMENT=64
444 PLATFORM=x86_64
445 ;;
446 freebsd)
447 PLATFORM=x86
448 ENVIRONMENT=32
449
450 # FreeBSD doesn't give us a nice way to determine the CPU
451 # class of the running system, reporting any 32-bit x86
452 # architecture as i386. 486 is its minimum supported CPU
453 # class and cmpxchg8b was implemented first in i586.
454 dmesg | grep -q "486-class"
455 if test "$?" -eq 0; then
456 assert "" "" "Must have an i586 class or higher CPU"
457 fi
458
459 # FreeBSD still generates code for 486-class CPUs as its
460 # default 32-bit target, but we need 586 at the least.
461 echo "$CFLAGS" | grep -q 'march='
462 if test "$?" -ne 0; then
463 # Needed for cmpxchg8b
464 CFLAGS="$CFLAGS -march=i586"
465 fi
466 ;;
467 linux)
468 case $PLATFORM in
469 i386|i486)
470 assert "" "" "Must have an i586 class or higher CPU"
471 ;;
472 esac
473
474 PLATFORM=x86
475 ENVIRONMENT=32
476 ;;
477
478 *)
479 PLATFORM=x86
480 ENVIRONMENT=32
481 assert "$PLATFORM $ENVIRONMENT" "$PLATFORM $ENVIRONMENT" "unsupported"
482 ;;
483 esac
484 ;;
485 "amd64"|"x86_64")
486 LSE_ENABLE="CK_MD_LSE_DISABLE"
487 PLATFORM=x86_64
488 ENVIRONMENT=64
489 LDFLAGS="-m64 $LDFLAGS"
490 MM="${MM:-"CK_MD_TSO"}"
491 ;;
492 "i86pc")
493 RTM_ENABLE="CK_MD_RTM_DISABLE"
494 LSE_ENABLE="CK_MD_LSE_DISABLE"
495 MM="${MM:-"CK_MD_TSO"}"
496 if test -z "$ISA"; then ISA=`isainfo -n 2> /dev/null || echo i386` ; fi
497 case "$ISA" in
498 "amd64")
499 RTM_ENABLE=${RTM_ENABLE_SET:-"CK_MD_RTM_DISABLE"}
500 PLATFORM=x86_64
501 ENVIRONMENT=64
502 ;;
503 *)
504 PLATFORM=x86
505 ENVIRONMENT=32
506 assert "$PLATFORM $ENVIRONMENT" "$PLATFORM $ENVIRONMENT" "unsupported"
507 ;;
508 esac
509 ;;
510 "ppc64"|"ppc64le"|"powerpc64")
511 RTM_ENABLE="CK_MD_RTM_DISABLE"
512 LSE_ENABLE="CK_MD_LSE_DISABLE"
513 MM="${MM:-"CK_MD_RMO"}"
514 PLATFORM=ppc64
515 ENVIRONMENT=64
516 ;;
517 arm|armv6|armv6l|armv7|armv7l)
518 RTM_ENABLE="CK_MD_RTM_DISABLE"
519 LSE_ENABLE="CK_MD_LSE_DISABLE"
520 MM="${MM:-"CK_MD_RMO"}"
521 PLATFORM=arm
522 ENVIRONMENT=32
523 ;;
524 "arm64"|"aarch64")
525 RTM_ENABLE="CK_MD_RTM_DISABLE"
526 MM="${MM:-"CK_MD_RMO"}"
527 PLATFORM=aarch64
528 ENVIRONMENT=64
529 ;;
530 "riscv32"|"riscv")
531 RTM_ENABLE="CK_MD_RTM_DISABLE"
532 MM="${MM:-"CK_MD_RMO"}"
533 PLATFORM=riscv32
534 ENVIRONMENT=32
535 ;;
536 "riscv64")
537 RTM_ENABLE="CK_MD_RTM_DISABLE"
538 MM="${MM:-"CK_MD_RMO"}"
539 PLATFORM=riscv64
540 ENVIRONMENT=64
541 ;;
542 "s390x")
543 RTM_ENABLE="CK_MD_RTM_DISABLE"
544 LSE_ENABLE="CK_MD_LSE_DISABLE"
545 MM="${MM:-"CK_MD_RMO"}"
546 PLATFORM=s390x
547 ENVIRONMENT=64
548 ;;
549 *)
550 RTM_ENABLE="CK_MD_RTM_DISABLE"
551 LSE_ENABLE="CK_MD_LSE_DISABLE"
552 PLATFORM=unknown
553 MM="${MM:-"CK_MD_RMO"}"
554 USE_CC_BUILTINS=1
555 ;;
556 esac
557
558 assert "$PLATFORM" "$PLATFORM" "unsupported"
559
560 if test "$VMA" = "unknown"; then
561 VMA_BITS_R="CK_MD_VMA_BITS_UNKNOWN"
562 VMA_BITS_VALUE_R=""
563 POINTER_PACK_ENABLE="CK_MD_POINTER_PACK_DISABLE"
564 else
565 VMA_BITS_R="CK_MD_VMA_BITS"
566 VMA_BITS_VALUE_R="${VMA_BITS}ULL"
567 fi
568
569 if test "$USE_CC_BUILTINS"; then
570 CFLAGS="$CFLAGS -DCK_USE_CC_BUILTINS=1"
571 PC_CFLAGS="-DCK_USE_CC_BUILTINS=1"
572 fi
573
574 # `which` on Solaris sucks
575 pathsearch()
576 {
577 what=$1
578 oldFS="$IFS"
579 IFS=":"
580 for d in $PATH ; do
581 if test -x "$d/$what" ; then
582 echo "$d/$what";
583 IFS="$oldFS"
584 return
585 fi
586 done
587 IFS="$oldFS"
588 }
589
590 printf "Finding dirname command.........."
591 DIRNAME=`pathsearch "${DIRNAME:-dirname}"`
592 if test -z "$DIRNAME" -o ! -x "$DIRNAME"; then
593 DIRNAME=`pathsearch "${DIRNAME:-dirname}"`
594 DIRNAME="$DIRNAME"
595 else
596 echo "success [$DIRNAME]"
597 fi
598
599 if test -z "$DIRNAME"; then
600 echo "not found (out of source build unsupported)"
601 else
602 printf "Determining source directory......"
603
604 SRC_DIR=`$DIRNAME $0`
605 cd `$DIRNAME $0`
606 SRC_DIR=`pwd`
607
608 echo "success [$SRC_DIR]"
609 fi
610
611 if test -n "$GZIP"; then
612 printf "Finding gzip tool................"
613 GZIP=`pathsearch "${GZIP:-gzip}"`
614 if test -z "$GZIP" -o ! -x "$GZIP"; then
615 GZIP=`pathsearch "${GZIP:-gzip}"`
616 GZIP="$GZIP"
617 fi
618
619 if test -z "$GZIP"; then
620 echo "not found"
621 else
622 echo "success [$GZIP]"
623 GZIP="$GZIP -c"
624 GZIP_SUFFIX=".gz"
625 fi
626 fi
627
628 if test -z "$GZIP"; then
629 GZIP=cat
630 GZIP_SUFFIX=""
631 fi
632
633 if test "$PROFILE"; then
634 printf "Using user-specified profile....."
635
636 if test -z "$CC"; then
637 echo "failed [specify compiler]"
638 exit $EXIT_FAILURE
639 fi
640
641 if test ! -f build/ck.build.$PROFILE; then
642 echo "failed [$PROFILE]"
643 exit $EXIT_FAILURE
644 fi
645
646 echo "success [$PROFILE]"
647 printf "Generating header files.........."
648 generate include/ck_md.h.in include/ck_md.h
649 generate include/freebsd/ck_md.h.in include/freebsd/ck_md.h
650 echo "success"
651 printf "Generating build files..........."
652 generate src/Makefile.in src/Makefile
653 generate doc/Makefile.in doc/Makefile
654 generate build/ck.build.in build/ck.build
655 generate build/regressions.build.in build/regressions.build
656 generate build/ck.pc.in build/ck.pc
657 generate build/ck.spec.in build/ck.spec
658 generate Makefile.in Makefile
659 echo "success"
660 generate_stdout
661 exit $EXIT_SUCCESS
662 fi
663
664 printf "Finding suitable compiler........"
665 if test ! -x "${CC}"; then
666 CC=`pathsearch "${CC:-cc}"`
667 if test -z "$CC" -o ! -x "$CC"; then
668 CC=`pathsearch "${CC:-gcc}"`
669 fi
670 fi
671 assert "$CC" "not found"
672
673 cat << EOF > .1.c
674 #include <stdio.h>
675 int main(void) {
676 #if defined(_WIN32)
677 #if defined(__MINGW64__)
678 puts("mingw64");
679 return (0);
680 #elif defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION >= 3)
681 puts("mingw32");
682 return (0);
683 #else
684 return (1);
685 #endif /* __MINGW32__ && __MINGW32_MAJOR_VERSION >= 3 */
686 #elif defined(__clang__) && (__clang_major__ >= 3)
687 puts("clang");
688 return (0);
689 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5110)
690 puts("suncc");
691 return (0);
692 #elif defined(__GNUC__) && (__GNUC__ >= 4)
693 puts("gcc");
694 return (0);
695 #else
696 return (1);
697 #endif
698 }
699 EOF
700
701 $CC -o .1 .1.c
702 COMPILER=`./.1 2> /dev/null`
703 r=$?
704 rm -f .1.c .1
705
706 if test "$r" -ne 0; then
707 assert "" "update compiler"
708 else
709 echo "success [$CC]"
710 fi
711
712 if test "$COMPILER" = "suncc"; then
713 LD=/bin/ld
714 LDFLAGS="-G -z text -h libck.so.$VERSION_MAJOR $LDFLAGS"
715 CFLAGS="-xO5 $CFLAGS"
716 PTHREAD_CFLAGS="-mt -lpthread"
717 elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang" || test "$COMPILER" = "mingw32" || test "$COMPILER" = "mingw64"; then
718 LD=$CC
719 SONAME="$LDNAME_MAJOR"
720 if test "$SYSTEM" = "darwin"; then
721 CC_WL_OPT="-install_name"
722 LDNAME="libck.dylib"
723 LDNAME_VERSION="libck.$VERSION.dylib"
724 LDNAME_MAJOR="libck.$VERSION_MAJOR.dylib"
725 SONAME="$LIBRARY/$LDNAME_MAJOR"
726 else
727 CC_WL_OPT="-soname"
728 fi
729
730 LDFLAGS="-Wl,$CC_WL_OPT,$SONAME $LDFLAGS"
731 if test "$WANT_PIC" = "yes"; then
732 LDFLAGS="$LDFLAGS -shared -fPIC"
733 CFLAGS="$CFLAGS -fPIC"
734
735 if [ "$DISABLE_SHARED" -eq 1 ] && [ "$DISABLE_STATIC" -eq 1 ]; then
736 echo "Error: You have choosen to disable the shared lib, yet you also disabled the static lib." 1>&2
737 exit $EXIT_FAILURE
738 elif [ "$DISABLE_STATIC" -eq 1 ]; then
739 ALL_LIBS="libck.so"
740 INSTALL_LIBS="install-so"
741 elif [ "$DISABLE_SHARED" -eq 1 ]; then
742 ALL_LIBS="libck.a"
743 INSTALL_LIBS="install-lib"
744 else
745 ALL_LIBS="libck.so libck.a"
746 INSTALL_LIBS="install-so install-lib"
747 fi
748 else
749 LDFLAGS="$LDFLAGS -fno-PIC"
750 CFLAGS="$CFLAGS -fno-PIC"
751 if [ "$DISABLE_STATIC" -eq 1 ]; then
752 echo "Error: You have choosen to disable PIC, yet you also disabled the static lib." 1>&2
753 exit $EXIT_FAILURE
754 else
755 ALL_LIBS="libck.a"
756 INSTALL_LIBS="install-lib"
757 fi
758 fi
759
760 CFLAGS="-D_BSD_SOURCE -D_DEFAULT_SOURCE -std=gnu99 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wcast-align -Wcast-qual -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -fstrict-aliasing -O2 -pipe -Wno-parentheses $CFLAGS"
761 PTHREAD_CFLAGS="-pthread"
762 if test "$COMPILER" = "mingw64"; then
763 ENVIRONMENT=64
764 PLATFORM=x86_64
765 fi
766 if test "$SYSTEM" = "netbsd"; then
767 CFLAGS="$CFLAGS -D_NETBSD_SOURCE"
768 fi
769 if test "$SYSTEM" != "dragonflybsd"; then
770 CFLAGS="$CFLAGS -D_XOPEN_SOURCE=600"
771 fi
772 else
773 assert "" "unknown compiler"
774 fi
775
776 printf "Finding suitable archiver........"
777 if test ! -x "${AR}"; then
778 AR=`pathsearch "${AR:-ar}"`
779 if test -z "$AR" -o ! -x "$AR"; then
780 AR=`pathsearch "${AR:-ar}"`
781 else
782 echo "success [$AR]"
783 fi
784 fi
785 assert "$AR" "not found"
786
787 printf "Detecting VMA bits..............."
788 VMA="unknown"
789 if test "$VMA_BITS" = "unknown"; then
790 if test "$PLATFORM" = "x86" || test $PLATFORM = "x86_64"; then
791 case $SYSTEM in
792 darwin)
793 VMA=`sysctl -n machdep.cpu.address_bits.virtual`
794 ;;
795 linux)
796 VMA=`awk '/address sizes/ {print $7;exit}' /proc/cpuinfo`
797 ;;
798 *)
799 if test "$PLATFORM" = "x86"; then
800 VMA="32"
801 else
802 cat << EOF > .1.c
803 #include <stdio.h>
804
805 int main(int argc, char *argv[])
806 {
807 unsigned long ret = 0x80000000;
808
809 __asm __volatile("cpuid\n"
810 : "+a" (ret));
811 if (ret >= 0x80000008) {
812 ret = 0x80000008;
813 __asm __volatile("cpuid\n"
814 : "+a" (ret));
815 printf("%lu\n", (ret >> 8) & 0xff);
816 } else {
817 return (1);
818 }
819 return (0);
820 }
821 EOF
822
823 $CC -o .1 .1.c 2>/dev/null
824 VMA=`./.1 2>/dev/null`
825 if test $? -ne 0; then
826 VMA="unknown"
827 fi
828 rm -f .1.c .1
829 fi
830 esac
831 fi
832
833 VMA_BITS=$VMA
834 else
835 VMA=$VMA_BITS
836 fi
837
838 if test "$VMA" = "unknown"; then
839 echo "unknown"
840 VMA_BITS_R="CK_MD_VMA_BITS_UNKNOWN"
841 VMA_BITS_VALUE_R=""
842 POINTER_PACK_ENABLE="CK_MD_POINTER_PACK_DISABLE"
843 else
844 echo "success [$VMA]"
845 VMA_BITS_R="CK_MD_VMA_BITS"
846 VMA_BITS_VALUE_R="${VMA_BITS}ULL"
847 fi
848
849 for i in $REQUIRE_HEADER; do
850 printf "Checking header file usability..."
851
852 cat << EOF > .1.c
853 #include <$i>
854 int main(void){return(0);}
855 EOF
856 $CC -o .1 .1.c 2> /dev/null
857 hf_s=$?
858
859 rm -f .1 .1.c
860 if test $hf_s -eq 0; then
861 echo "success [$i]"
862 else
863 echo "failed [$i]"
864 exit $EXIT_FAILURE
865 fi
866 done
867
868 printf "Detecting git SHA................"
869 get_git_sha
870 echo "$GIT_MSG [$GIT_SHA]"
871
872 # Platform will be used as a macro.
873 PROFILE="${PROFILE:-$PLATFORM}"
874 PLATFORM="__${PLATFORM}__"
875
876 printf "Generating header files.........."
877 mkdir -p $BUILD_DIR/include
878 mkdir -p $BUILD_DIR/include/freebsd
879 generate include/ck_md.h.in $BUILD_DIR/include/ck_md.h
880 generate include/freebsd/ck_md.h.in $BUILD_DIR/include/freebsd/ck_md.h
881 echo "success"
882
883 printf "Generating build files..........."
884
885 mkdir -p $BUILD_DIR/doc
886 mkdir -p $BUILD_DIR/build
887 mkdir -p $BUILD_DIR/src
888
889 if test "$BUILD_DIR" '!=' "$SRC_DIR"; then
890 mkdir -p $BUILD_DIR/regressions
891 cp $SRC_DIR/regressions/Makefile.unsupported $BUILD_DIR/regressions/Makefile &> /dev/null
892 cp $SRC_DIR/build/ck.build.$PROFILE $BUILD_DIR/build/ck.build.$PROFILE &> /dev/null
893 fi
894
895 generate src/Makefile.in $BUILD_DIR/src/Makefile
896 generate doc/Makefile.in $BUILD_DIR/doc/Makefile
897 generate build/ck.build.in $BUILD_DIR/build/ck.build
898 generate build/regressions.build.in $BUILD_DIR/build/regressions.build
899 generate build/ck.pc.in $BUILD_DIR/build/ck.pc
900 generate build/ck.spec.in $BUILD_DIR/build/ck.spec
901 generate Makefile.in $BUILD_DIR/Makefile
902 touch src/*.c
903 echo "success"
904 generate_stdout
905
906 if test "$PROFILE" = "unknown"; then
907 echo
908 echo "WARNING: your target architecture is not a first-class citizen."
909 echo
910 echo "The test suite may not work as intended. Consider reaching out "
911 echo "to the mailing list about having the project add first-class "
912 echo "support for your architecture."
913 fi