blob: 0608b838b753d1cf36604000036b6dee1e850c6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#!/usr/bin/env sh
#
# Configure script for impl
#
CONFIGURE_CMD_ARGS="${*}"
PACKAGE_VERSION="0.1.0"
PACKAGE_DATE="$(date +%Y-%m-%d)"
PACKAGE_STRING="impl $PACKAGE_VERSION"
PACKAGE_BUGREPORT="ethan@gweithio.com"
PACKAGE_URL="https://sixfourtwelve.com/repos/impl.git"
find_program() {
varname=$1
shift
printf "Checking for $varname ..." >&2
for x in $*; do
if command -v $x >/dev/null 2>&1 && [ -x $(command -v $x) ]; then
binary="$(command -v $x)"
printf " $binary\n" >&2
echo "${binary}"
return 0
fi
done
printf " not found\n" >&2
return 1
}
die() {
printf "%s\n" "${*}"
exit 1
}
# Default values
PREFIX="/usr/local"
OPTIMISE="release"
CC=""
AR="ar"
RANLIB="ranlib"
RM="rm"
INSTALL="install"
# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
--prefix=*)
PREFIX="${1#--prefix=}"
;;
--prefix)
shift
PREFIX="$1"
;;
--debug)
OPTIMISE="debug"
;;
--release)
OPTIMISE="release"
;;
--help)
cat <<EOF
Configure script for impl
Options:
--prefix=PREFIX Installation prefix (default: /usr/local)
--debug Build with debug symbols, no optimization
--release Build with optimizations (default)
--help Show this help message
Environment variables:
CC C compiler
AR Archiver
RANLIB ranlib
CFLAGS Additional C flags
LDFLAGS Additional linker flags
EOF
exit 0
;;
*)
die "Unknown option: $1"
;;
esac
shift
done
# Find required tools
if [ -z "$CC" ]; then
CC=$(find_program CC cc clang gcc) || die "No C compiler found"
fi
# Use basename only for better tool compatibility (e.g., bear)
CC=$(basename "$CC")
# Detect compiler type
if $CC --version 2>&1 | grep -i clang >/dev/null; then
CCOM="clang"
elif $CC --version 2>&1 | grep -i gcc >/dev/null; then
CCOM="gcc"
else
CCOM="unknown"
fi
printf "Compiler: %s (%s)\n" "$CC" "$CCOM"
# Generate config.h
cat > config.h <<EOF_CONFIG
#ifndef CONFIG_H
#define CONFIG_H
#define PACKAGE_VERSION "$PACKAGE_VERSION"
#define PACKAGE_STRING "$PACKAGE_STRING"
#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
#define PACKAGE_URL "$PACKAGE_URL"
#endif /* CONFIG_H */
EOF_CONFIG
# Determine source directory
SRCDIR="$(dirname "$0")"
SRCDIR="$(cd "$SRCDIR" && pwd)"
# Generate Makefile from Makefile.in
sed \
-e "s|@PREFIX@|$PREFIX|g" \
-e "s|@CC@|$CC|g" \
-e "s|@CCOM@|$CCOM|g" \
-e "s|@AR@|$AR|g" \
-e "s|@RANLIB@|$RANLIB|g" \
-e "s|@RM@|$RM|g" \
-e "s|@INSTALL@|$INSTALL|g" \
-e "s|@OPTIMISE@|$OPTIMISE|g" \
-e "s|@VERSION@|$PACKAGE_VERSION|g" \
-e "s|@SRCDIR@|$SRCDIR|g" \
< "$SRCDIR/Makefile.in" > Makefile
echo "Configuration complete. Run 'make' to build."
|