~ chicken-core (master) /configure
Trap1#!/bin/sh
2#
3# configuration script for the CHICKEN build process
4#
5# Copyright (c) 2024, The CHICKEN Team
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
9# conditions are met:
10#
11# Redistributions of source code must retain the above copyright notice, this list of conditions and the following
12# disclaimer.
13# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
14# disclaimer in the documentation and/or other materials provided with the distribution.
15# Neither the name of the author nor the names of its contributors may be used to endorse or promote
16# products derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
19# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26# POSSIBILITY OF SUCH DAMAGE.
27
28prefix=/usr/local
29debug=
30static=
31host=
32target=
33tprefix=
34pprefix=
35psuffix=
36srcdir=
37vardir=
38linker=
39platform=
40chicken=
41pobjs=
42mkcmd="make"
43
44usage () {
45 echo "usage: configure [--help] [--prefix DIRECTORY] [--platform PLATFORM | list] [--chicken PROGRAMNAME] [--debugbuild] [--staticbuild] [--disable-shared] [--host HOSTSYSTEM] [--target TARGETSYSTEM] [--program-prefix PREFIX] [--program-suffix SUFFIX] [--target-prefix DIRECTORY] [--srcdir DIRECTORY] [--vardir DIRECTORY] [--c-compiler PROGRAMNAME] [--linker PROGRAMNAME] [--profile-objects OBJECTLIST]"
46 echo
47 echo "consult the README file for more information."
48 exit "$1"
49}
50
51while [ -n "$1" ]; do
52 arg="$1"
53 shift
54 case "$arg" in
55 -h|-help|--help)
56 usage 0;;
57 --chicken=*)
58 chicken=${arg#--chicken=};;
59 --chicken)
60 test -z "$1" && usage 1 >&2
61 chicken="$1"
62 shift;;
63 --prefix=*)
64 prefix=${arg#--prefix=};;
65 --prefix)
66 test -z "$1" && usage 1 >&2
67 prefix="$1"
68 shift;;
69 --platform=*)
70 platform=${arg#--platform=};;
71 --platform)
72 test -z "$1" && usage 1 >&2
73 platform="$1"
74 shift;;
75 --debugbuild)
76 debug=1;;
77 --staticbuild|--disable-shared)
78 static=1;;
79 --host=*)
80 host=${arg#--host=};;
81 --host)
82 test -z "$1" && usage 1 >&2
83 host="$1"
84 shift;;
85 --target=*)
86 target=${arg#--target=};;
87 --target)
88 test -z "$1" && usage 1 >&2
89 target="$1"
90 shift;;
91 --program-prefix=*)
92 pprefix=${arg#--program-prefix=};;
93 --program-prefix)
94 test -z "$1" && usage 1 >&2
95 pprefix="$1"
96 shift;;
97 --program-suffix=*)
98 psuffix=${arg#--program-suffix=};;
99 --program-suffix)
100 test -z "$1" && usage 1
101 psuffix="$1"
102 shift;;
103 --target-prefix=*)
104 tprefix=${arg#--target-prefix=};;
105 --target-prefix)
106 test -z "$1" && usage 1
107 tprefix="$1"
108 shift;;
109 --srcdir=*)
110 srcdir=${arg#--srcdir=};;
111 --srcdir)
112 test -z "$1" && usage 1 >&2
113 srcdir="$1"
114 shift;;
115 --vardir=*)
116 vardir=${arg#--vardir=};;
117 --vardir)
118 test -z "$1" && usage 1 >&2
119 vardir="$1"
120 shift;;
121 --profile-objects=*)
122 pobjs=${arg#--profile-objects=};;
123 --profile-objects)
124 test -z "$1" && usage 1 >&2
125 pobjs="$1"
126 shift;;
127 --c-compiler=*)
128 CC=${arg#--c-compiler=};;
129 --c-compiler)
130 test -z "$1" && usage 1 >&2
131 CC="$1"
132 shift;;
133 --linker=*)
134 linker=${arg#--linker=};;
135 --linker)
136 test -z "$1" && usage 1 >&2
137 linker="$1"
138 shift;;
139 *)
140 usage 1 >&2;;
141 esac
142done
143
144if [ "$platform" = list ]; then
145 echo "available platforms:"
146 echo
147 for mf in Makefile.*; do
148 echo " ${mf#Makefile.}"
149 done
150 echo
151 exit
152fi
153
154if [ -z "$platform" ]; then
155 printf 'detecting platform ... '
156
157 # Detect the PLATFORM with uname.
158 # Based on Chibi Scheme auto-detector
159 # Heavily revamped by John Cowan
160 # Moved into configure script by Felix Winkelmann
161 # Copyright (c) 2009-2018 Alex Shinn, John Cowan
162 # BSD license at <https://github.com/ashinn/chibi-scheme/blob/master/COPYING>
163
164 # Now we can use uname tests
165 uname_s=$(uname)
166 uname_o=$(uname -o 2>/dev/null)
167
168 case "$uname_s" in
169 Darwin)
170 platform=macosx;;
171 *BSD)
172 platform=bsd;;
173 DragonFly)
174 platform=bsd;;
175 Windows_NT)
176 platform=mingw
177 case "$prefix" in
178 [a-zA-Z]:*)
179 ;;
180 *)
181 echo "on Windows, the prefix must contain a drive letter" >&2
182 exit 1;;
183 esac;;
184 SunOS)
185 platform=solaris;;
186 BeOS)
187 platform=haiku;;
188 Haiku)
189 platform=haiku;;
190 GNU)
191 platform=hurd;;
192 AIX)
193 platform=aix;;
194 *)
195 case "$uname_o" in
196 Cygwin)
197 platform=cygwin;;
198 Android)
199 platform=android;;
200 GNU/Linux)
201 platform=linux;;
202 Linux)
203 platform=linux;;
204 *)
205 echo
206 echo "unable to figure out platform" >&2
207 exit 1;;
208 esac;;
209 esac
210 echo "$platform"
211fi
212
213cccmd="gcc"
214if [ "$platform" = "bsd" ]; then
215 cccmd="cc"
216 if command -v gmake >/dev/null; then
217 mkcmd="gmake"
218 else
219 echo "GNU make is required but does not seem to be available" >&2
220 exit 1
221 fi
222fi
223
224echo "installation prefix: $prefix"
225test -n "$chicken" && echo "bootstrap chicken: $chicken"
226
227test -n "$CC" && cccmd="$CC"
228
229printf "testing C compiler (%s) ... " "$cccmd"
230tmpc="$(mktemp).c"
231cat > "$tmpc" <<EOF
232int main() {return 0;}
233EOF
234if command -v $cccmd >/dev/null; then
235 if $cccmd "$tmpc" $CFLAGS -o "${tmpc}.out"; then
236 rm -f "$tmpc"
237 if "${tmpc}.out"; then
238 echo works
239 rm -f "${tmpc}.out"
240 else
241 rm -f "${tmpc}.out"
242 echo
243 echo "$cccmd does not seem to produce working executables" >&2
244 exit 1
245 fi
246 else
247 rm -f "$tmpc" "${tmpc}.out"
248 echo
249 echo "$cccmd does not seem to work" >&2
250 exit 1
251 fi
252else
253 echo
254 echo "cannot find $cccmd" >&2
255 exit 1
256fi
257
258echo "# GENERATED BY configure" > config.make
259echo "PLATFORM ?= $platform" >> config.make
260echo "PREFIX ?= $prefix" >> config.make
261test -n "$debug" && echo "DEBUGBUILD ?= 1" >> config.make
262test -n "$static" && echo "STATICBUILD ?= 1" >> config.make
263test -n "$CC" && echo "C_COMPILER ?= $cccmd" >> config.make
264test -n "$linker" && echo "LINKER ?= $linker" >> config.make
265test -n "$CFLAGS" && echo "C_COMPILER_OPTIMIZATION_OPTIONS ?= $CFLAGS" >> config.make
266test -n "$host" && echo "HOSTSYSTEM ?= $host" >> config.make
267test -n "$target" && echo "TARGETSYSTEM ?= $target" >> config.make
268test -n "$pprefix" && echo "PROGRAM_PREFIX ?= $pprefix" >> config.make
269test -n "$psuffix" && echo "PROGRAM_SUFFIX ?= $psuffix" >> config.make
270test -n "$tprefix" && echo "TARGET_PREFIX ?= $tprefix" >> config.make
271test -n "$srcdir" && echo "SRCDIR ?= $srcdir" >> config.make
272test -n "$vardir" && echo "VARDIR ?= $vardir" >> config.make
273test -n "$chicken" && echo "CHICKEN ?= $chicken" >> config.make
274test -n "$pobjs" && echo "PROFILE_OBJECTS ?= $pobjs" >> config.make
275
276echo
277echo "now run ${mkcmd} to build the system"
278echo