Debian Codegraph @

configure

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 case "$PLATFORM" in
519 "armv6"|"armv6l")
520 CFLAGS="$CFLAGS -march=armv6k";
521 ;;
522 "armv7"|"armv7l")
523 CFLAGS="$CFLAGS -march=armv7-a";
524 ;;
525 esac
526 RTM_ENABLE="CK_MD_RTM_DISABLE"
527 LSE_ENABLE="CK_MD_LSE_DISABLE"
528 MM="${MM:-"CK_MD_RMO"}"
529 PLATFORM=arm
530 ENVIRONMENT=32
531 ;;
532 "arm64"|"aarch64")
533 RTM_ENABLE="CK_MD_RTM_DISABLE"
534 MM="${MM:-"CK_MD_RMO"}"
535 PLATFORM=aarch64
536 ENVIRONMENT=64
537 ;;
538 "riscv32"|"riscv")
539 RTM_ENABLE="CK_MD_RTM_DISABLE"
540 MM="${MM:-"CK_MD_RMO"}"
541 PLATFORM=riscv32
542 ENVIRONMENT=32
543 ;;
544 "riscv64")
545 RTM_ENABLE="CK_MD_RTM_DISABLE"
546 MM="${MM:-"CK_MD_RMO"}"
547 PLATFORM=riscv64
548 ENVIRONMENT=64
549 ;;
550 "s390x")
551 RTM_ENABLE="CK_MD_RTM_DISABLE"
552 LSE_ENABLE="CK_MD_LSE_DISABLE"
553 MM="${MM:-"CK_MD_RMO"}"
554 PLATFORM=s390x
555 ENVIRONMENT=64
556 ;;
557 *)
558 RTM_ENABLE="CK_MD_RTM_DISABLE"
559 LSE_ENABLE="CK_MD_LSE_DISABLE"
560 PLATFORM=unknown
561 MM="${MM:-"CK_MD_RMO"}"
562 USE_CC_BUILTINS=1
563 ;;
564 esac
565
566 assert "$PLATFORM" "$PLATFORM" "unsupported"
567
568 if test "$VMA" = "unknown"; then
569 VMA_BITS_R="CK_MD_VMA_BITS_UNKNOWN"
570 VMA_BITS_VALUE_R=""
571 POINTER_PACK_ENABLE="CK_MD_POINTER_PACK_DISABLE"
572 else
573 VMA_BITS_R="CK_MD_VMA_BITS"
574 VMA_BITS_VALUE_R="${VMA_BITS}ULL"
575 fi
576
577 if test "$USE_CC_BUILTINS"; then
578 CFLAGS="$CFLAGS -DCK_USE_CC_BUILTINS=1"
579 PC_CFLAGS="-DCK_USE_CC_BUILTINS=1"
580 fi
581
582 # `which` on Solaris sucks
583 pathsearch()
584 {
585 what=$1
586 oldFS="$IFS"
587 IFS=":"
588 for d in $PATH ; do
589 if test -x "$d/$what" ; then
590 echo "$d/$what";
591 IFS="$oldFS"
592 return
593 fi
594 done
595 IFS="$oldFS"
596 }
597
598 printf "Finding dirname command.........."
599 DIRNAME=`pathsearch "${DIRNAME:-dirname}"`
600 if test -z "$DIRNAME" -o ! -x "$DIRNAME"; then
601 DIRNAME=`pathsearch "${DIRNAME:-dirname}"`
602 DIRNAME="$DIRNAME"
603 else
604 echo "success [$DIRNAME]"
605 fi
606
607 if test -z "$DIRNAME"; then
608 echo "not found (out of source build unsupported)"
609 else
610 printf "Determining source directory......"
611
612 SRC_DIR=`$DIRNAME $0`
613 cd `$DIRNAME $0`
614 SRC_DIR=`pwd`
615
616 echo "success [$SRC_DIR]"
617 fi
618
619 if test -n "$GZIP"; then
620 printf "Finding gzip tool................"
621 GZIP=`pathsearch "${GZIP:-gzip}"`
622 if test -z "$GZIP" -o ! -x "$GZIP"; then
623 GZIP=`pathsearch "${GZIP:-gzip}"`
624 GZIP="$GZIP"
625 fi
626
627 if test -z "$GZIP"; then
628 echo "not found"
629 else
630 echo "success [$GZIP]"
631 GZIP="$GZIP -c"
632 GZIP_SUFFIX=".gz"
633 fi
634 fi
635
636 if test -z "$GZIP"; then
637 GZIP=cat
638 GZIP_SUFFIX=""
639 fi
640
641 if test "$PROFILE"; then
642 printf "Using user-specified profile....."
643
644 if test -z "$CC"; then
645 echo "failed [specify compiler]"
646 exit $EXIT_FAILURE
647 fi
648
649 if test ! -f build/ck.build.$PROFILE; then
650 echo "failed [$PROFILE]"
651 exit $EXIT_FAILURE
652 fi
653
654 echo "success [$PROFILE]"
655 printf "Generating header files.........."
656 generate include/ck_md.h.in include/ck_md.h
657 generate include/freebsd/ck_md.h.in include/freebsd/ck_md.h
658 echo "success"
659 printf "Generating build files..........."
660 generate src/Makefile.in src/Makefile
661 generate doc/Makefile.in doc/Makefile
662 generate build/ck.build.in build/ck.build
663 generate build/regressions.build.in build/regressions.build
664 generate build/ck.pc.in build/ck.pc
665 generate build/ck.spec.in build/ck.spec
666 generate Makefile.in Makefile
667 echo "success"
668 generate_stdout
669 exit $EXIT_SUCCESS
670 fi
671
672 printf "Finding suitable compiler........"
673 if test ! -x "${CC}"; then
674 CC=`pathsearch "${CC:-cc}"`
675 if test -z "$CC" -o ! -x "$CC"; then
676 CC=`pathsearch "${CC:-gcc}"`
677 fi
678 fi
679 assert "$CC" "not found"
680
681 cat << EOF > .1.c
682 #include <stdio.h>
683 int main(void) {
684 #if defined(_WIN32)
685 #if defined(__MINGW64__)
686 puts("mingw64");
687 return (0);
688 #elif defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION >= 3)
689 puts("mingw32");
690 return (0);
691 #else
692 return (1);
693 #endif /* __MINGW32__ && __MINGW32_MAJOR_VERSION >= 3 */
694 #elif defined(__clang__) && (__clang_major__ >= 3)
695 puts("clang");
696 return (0);
697 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5110)
698 puts("suncc");
699 return (0);
700 #elif defined(__GNUC__) && (__GNUC__ >= 4)
701 puts("gcc");
702 return (0);
703 #else
704 return (1);
705 #endif
706 }
707 EOF
708
709 $CC -o .1 .1.c
710 COMPILER=`./.1 2> /dev/null`
711 r=$?
712 rm -f .1.c .1
713
714 if test "$r" -ne 0; then
715 assert "" "update compiler"
716 else
717 echo "success [$CC]"
718 fi
719
720 if test "$COMPILER" = "suncc"; then
721 LD=/bin/ld
722 LDFLAGS="-G -z text -h libck.so.$VERSION_MAJOR $LDFLAGS"
723 CFLAGS="-xO5 $CFLAGS"
724 PTHREAD_CFLAGS="-mt -lpthread"
725 elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang" || test "$COMPILER" = "mingw32" || test "$COMPILER" = "mingw64"; then
726 LD=$CC
727 SONAME="$LDNAME_MAJOR"
728 if test "$SYSTEM" = "darwin"; then
729 CC_WL_OPT="-install_name"
730 LDNAME="libck.dylib"
731 LDNAME_VERSION="libck.$VERSION.dylib"
732 LDNAME_MAJOR="libck.$VERSION_MAJOR.dylib"
733 SONAME="$LIBRARY/$LDNAME_MAJOR"
734 else
735 CC_WL_OPT="-soname"
736 fi
737
738 LDFLAGS="-Wl,$CC_WL_OPT,$SONAME $LDFLAGS"
739 if test "$WANT_PIC" = "yes"; then
740 LDFLAGS="$LDFLAGS -shared -fPIC"
741 CFLAGS="$CFLAGS -fPIC"
742
743 if [ "$DISABLE_SHARED" -eq 1 ] && [ "$DISABLE_STATIC" -eq 1 ]; then
744 echo "Error: You have choosen to disable the shared lib, yet you also disabled the static lib." 1>&2
745 exit $EXIT_FAILURE
746 elif [ "$DISABLE_STATIC" -eq 1 ]; then
747 ALL_LIBS="libck.so"
748 INSTALL_LIBS="install-so"
749 elif [ "$DISABLE_SHARED" -eq 1 ]; then
750 ALL_LIBS="libck.a"
751 INSTALL_LIBS="install-lib"
752 else
753 ALL_LIBS="libck.so libck.a"
754 INSTALL_LIBS="install-so install-lib"
755 fi
756 else
757 LDFLAGS="$LDFLAGS -fno-PIC"
758 CFLAGS="$CFLAGS -fno-PIC"
759 if [ "$DISABLE_STATIC" -eq 1 ]; then
760 echo "Error: You have choosen to disable PIC, yet you also disabled the static lib." 1>&2
761 exit $EXIT_FAILURE
762 else
763 ALL_LIBS="libck.a"
764 INSTALL_LIBS="install-lib"
765 fi
766 fi
767
768 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"
769 PTHREAD_CFLAGS="-pthread"
770 if test "$COMPILER" = "mingw64"; then
771 ENVIRONMENT=64
772 PLATFORM=x86_64
773 fi
774 if test "$SYSTEM" = "netbsd"; then
775 CFLAGS="$CFLAGS -D_NETBSD_SOURCE"
776 fi
777 if test "$SYSTEM" != "dragonflybsd"; then
778 CFLAGS="$CFLAGS -D_XOPEN_SOURCE=600"
779 fi
780 else
781 assert "" "unknown compiler"
782 fi
783
784 printf "Finding suitable archiver........"
785 if test ! -x "${AR}"; then
786 AR=`pathsearch "${AR:-ar}"`
787 if test -z "$AR" -o ! -x "$AR"; then
788 AR=`pathsearch "${AR:-ar}"`
789 else
790 echo "success [$AR]"
791 fi
792 fi
793 assert "$AR" "not found"
794
795 printf "Detecting VMA bits..............."
796 VMA="unknown"
797 if test "$VMA_BITS" = "unknown"; then
798 if test "$PLATFORM" = "x86" || test $PLATFORM = "x86_64"; then
799 case $SYSTEM in
800 darwin)
801 VMA=`sysctl -n machdep.cpu.address_bits.virtual`
802 ;;
803 linux)
804 VMA=`awk '/address sizes/ {print $7;exit}' /proc/cpuinfo`
805 ;;
806 *)
807 if test "$PLATFORM" = "x86"; then
808 VMA="32"
809 else
810 cat << EOF > .1.c
811 #include <stdio.h>
812
813 int main(int argc, char *argv[])
814 {
815 unsigned long ret = 0x80000000;
816
817 __asm __volatile("cpuid\n"
818 : "+a" (ret));
819 if (ret >= 0x80000008) {
820 ret = 0x80000008;
821 __asm __volatile("cpuid\n"
822 : "+a" (ret));
823 printf("%lu\n", (ret >> 8) & 0xff);
824 } else {
825 return (1);
826 }
827 return (0);
828 }
829 EOF
830
831 $CC -o .1 .1.c 2>/dev/null
832 VMA=`./.1 2>/dev/null`
833 if test $? -ne 0; then
834 VMA="unknown"
835 fi
836 rm -f .1.c .1
837 fi
838 esac
839 fi
840
841 VMA_BITS=$VMA
842 else
843 VMA=$VMA_BITS
844 fi
845
846 if test "$VMA" = "unknown"; then
847 echo "unknown"
848 VMA_BITS_R="CK_MD_VMA_BITS_UNKNOWN"
849 VMA_BITS_VALUE_R=""
850 POINTER_PACK_ENABLE="CK_MD_POINTER_PACK_DISABLE"
851 else
852 echo "success [$VMA]"
853 VMA_BITS_R="CK_MD_VMA_BITS"
854 VMA_BITS_VALUE_R="${VMA_BITS}ULL"
855 fi
856
857 for i in $REQUIRE_HEADER; do
858 printf "Checking header file usability..."
859
860 cat << EOF > .1.c
861 #include <$i>
862 int main(void){return(0);}
863 EOF
864 $CC -o .1 .1.c 2> /dev/null
865 hf_s=$?
866
867 rm -f .1 .1.c
868 if test $hf_s -eq 0; then
869 echo "success [$i]"
870 else
871 echo "failed [$i]"
872 exit $EXIT_FAILURE
873 fi
874 done
875
876 printf "Detecting git SHA................"
877 get_git_sha
878 echo "$GIT_MSG [$GIT_SHA]"
879
880 # Platform will be used as a macro.
881 PROFILE="${PROFILE:-$PLATFORM}"
882 PLATFORM="__${PLATFORM}__"
883
884 printf "Generating header files.........."
885 mkdir -p $BUILD_DIR/include
886 mkdir -p $BUILD_DIR/include/freebsd
887 generate include/ck_md.h.in $BUILD_DIR/include/ck_md.h
888 generate include/freebsd/ck_md.h.in $BUILD_DIR/include/freebsd/ck_md.h
889 echo "success"
890
891 printf "Generating build files..........."
892
893 mkdir -p $BUILD_DIR/doc
894 mkdir -p $BUILD_DIR/build
895 mkdir -p $BUILD_DIR/src
896
897 if test "$BUILD_DIR" '!=' "$SRC_DIR"; then
898 mkdir -p $BUILD_DIR/regressions
899 cp $SRC_DIR/regressions/Makefile.unsupported $BUILD_DIR/regressions/Makefile &> /dev/null
900 cp $SRC_DIR/build/ck.build.$PROFILE $BUILD_DIR/build/ck.build.$PROFILE &> /dev/null
901 fi
902
903 generate src/Makefile.in $BUILD_DIR/src/Makefile
904 generate doc/Makefile.in $BUILD_DIR/doc/Makefile
905 generate build/ck.build.in $BUILD_DIR/build/ck.build
906 generate build/regressions.build.in $BUILD_DIR/build/regressions.build
907 generate build/ck.pc.in $BUILD_DIR/build/ck.pc
908 generate build/ck.spec.in $BUILD_DIR/build/ck.spec
909 generate Makefile.in $BUILD_DIR/Makefile
910 touch src/*.c
911 echo "success"
912 generate_stdout
913
914 if test "$PROFILE" = "unknown"; then
915 echo
916 echo "WARNING: your target architecture is not a first-class citizen."
917 echo
918 echo "The test suite may not work as intended. Consider reaching out "
919 echo "to the mailing list about having the project add first-class "
920 echo "support for your architecture."
921 fi