-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·196 lines (158 loc) · 3.63 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
#
# Configure script for 'lmytfy'
# Copyright 2014-2016, Truveris Inc. All Rights Reserved.
#
#
PROG="lmytfy"
VERSION="0.2.0"
# Some shells have shitty echos
alias echo=/bin/echo
# generate_makefile() - Generate the main Makefile
# $1 - source makefile, appended at the end
generate_makefile() {
echo "# Automagically generated by 'configure'"
echo
echo "PROG_IRC=$PROG-irc"
echo "PROG_MATTERMOST=$PROG-mattermost"
echo "CFLAGS+=$CFLAGS -std=c99 -pedantic"
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+=-DVERSION=\\\"$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"
cat "$1"
}
# usage() - Spit out basic help
usage() {
echo "usage: ./configure [-hd] [--prefix path] [platform]"
echo
echo " -h this help screen."
echo " -d configure for debug mode (-ggdb -O0)"
echo " --prefix path base path for installation"
echo
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"
;;
esac
# Default paths
[ -z "$PREFIX" ] && PREFIX="/usr"
# 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
if [ -z "$CC" ]; then
if cc -v 1>/dev/null 2>/dev/null; then
export CC=cc
elif gcc -v 1>/dev/null 2>/dev/null; then
export CC=gcc
else
stuff_not_found "No C compiler found (try to install clang or gcc)"
fi
fi
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 "Detected compiler (${CC}) is not working"
fi
echo ${CC}
rm -f fake_cc*
# Check if we have strlcpy
echo -n "strlcpy... "
cat <<EOF > fake_strlcpy.c
main() { char buf[32]; strlcpy(buf, "woot", sizeof(buf)); }
EOF
if ! ${CC} fake_strlcpy.c -o /dev/null 1>/dev/null 2>/dev/null; then
echo "not found (we'll use ours)"
X_OBJECTS="$X_OBJECTS strlcpy.o"
CFLAGS="$CFLAGS -DHAS_NO_STRLCPY"
else
echo yes
fi
rm -f fake_strlcpy*
# Check if we have strtonum
echo -n "strtonum... "
cat <<EOF > fake_strtonum.c
main() { int i; const char *errstr; i = strtonum("42", 1, 64, &errstr); }
EOF
if ! ${CC} fake_strtonum.c -o /dev/null 1>/dev/null 2>/dev/null; then
echo "not found (we'll use ours)"
X_OBJECTS="$X_OBJECTS strtonum.o"
CFLAGS="$CFLAGS -DHAS_NO_STRTONUM"
else
echo yes
fi
rm -f fake_strtonum*
echo
find . -name "Makefile.src" | while read input; do
output=${input%%.src}
echo "generating $output"
generate_makefile $input > $output
done
echo
echo "Run 'make' (or 'gmake') to compile and 'sudo make install' to install."