/
configure
executable file
·183 lines (141 loc) · 3.38 KB
/
configure
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/sh
#
# Configure script for 'uncsv'
# Copyright (c) 2013 Bertrand Janin <b@janin.com>
#
UNCSV_VERSION="0.9.1"
# Some shells have shitty echos
alias echo=/bin/echo
# Some people run configure from their backyard
cd "`dirname $0`"
# Sad default, you can try CC=clang ./configure too
if [ -z "$CC" ]; then
export CC=gcc
fi
# generate_makefile() - Generate the main Makefile
# $1 file to add at the end
generate_makefile() {
echo "# Automagically generated by 'configure'"
echo
echo "CFLAGS+=-Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual"
echo "CFLAGS+=-Wstrict-prototypes -Wmissing-prototypes"
echo "CFLAGS+=-Wmissing-declarations -Wnested-externs -Winline"
echo "CFLAGS+=-DUNCSV_VERSION=\\\"$UNCSV_VERSION\\\" $X_CFLAGS"
if [ "$DEBUG_MODE" = "Y" ]; then
echo "CFLAGS+=-ggdb -O0"
else
echo "CFLAGS+=-O2"
fi
if [ -n "$X_OBJECTS" ]; then
echo "EXTRA_OBJECTS=$X_OBJECTS"
fi
echo "CC?=$CC"
echo "PREFIX?=$PREFIX"
echo "MANDEST=$MANDEST"
cat $1
}
# usage() - Spit out basic help
usage() {
echo "usage: ./configure [-h] [-d] [platform]"
echo
echo " -h this help screen."
echo " -d configure for debug mode (-ggdb -O0)"
echo
echo "By default, this script will attempt to detect your OS and will guess the most"
echo "appropriate configuration. If it gets your system wrong, you can force it,"
echo "here is the list of ''supported'' platforms:"
echo
echo " bsd - OpenBSD, FreeBSD, OS X, Darwin, ..."
echo " linux - Linux"
exit
}
# stuff_not_found() - Exit 'cause we're missing something
stuff_not_found() {
message="$1"
echo "not found"
echo
echo ERROR: $message
exit 2
}
# Command-line arguments
while true; do
case "$1" in
-h|--help)
usage
exit 2
;;
-d|--debug)
echo "Debug mode... enabled"
DEBUG_MODE="Y"
shift
;;
--prefix=*)
PREFIX="${1##--prefix=}"
shift
;;
# Skip all random long opts passed by packagers thinking this
# is autoconf-compatible.
--*)
shift
;;
*)
break
;;
esac
done
# Detect platform
echo -n "Target platform... "
OS=`uname`
if [ -n "$1" ]; then
OS="$1"
fi
echo $OS
# Platform-specific configuration
case $OS in
Linux|Unix|POSIX)
X_CFLAGS="-D_GNU_SOURCE -D_LOCAL_TZ_FILE"
X_OBJECTS=""
MANDEST="share/man"
;;
*BSD)
;;
Darwin)
MANDEST="share/man"
;;
*)
echo
echo "Sorry but '$OS' is currently unsupported, you can attemp 'bsd' or 'linux' as"
echo "target and cross your fingers. In order to do that you just need to give either"
echo "one as parameter to ./configure. You can get the official list of supported "
echo "platform with ./configure -l"
exit
esac
# Default paths
[ -z "$PREFIX" ] && PREFIX="/usr/local"
[ -z "$MANDEST" ] && MANDEST="man"
# Check for make
echo -n "make... "
cat <<EOF > fake_makefile
all:
@echo found
EOF
if ! make -f fake_makefile 1>/dev/null 2>/dev/null; then
stuff_not_found "Make not found (try to install make or gmake)"
fi
echo found
rm -f fake_makefile*
# Check if we have a working cc
echo -n "cc... "
cat <<EOF > fake_cc.c
#include <stdio.h>
main() { printf("woot\n"); }
EOF
if ! ${CC} fake_cc.c -o /dev/null 1>/dev/null 2>/dev/null; then
stuff_not_found "No C compiler found (try to install gcc or clang)"
fi
echo ${CC}
rm -f fake_cc*
generate_makefile Makefile.src > Makefile
generate_makefile src/Makefile.src > src/Makefile
echo
echo "Configured for '$OS', run 'make' (or 'gmake') to compile."