-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathConfigure
executable file
·272 lines (233 loc) · 5.82 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
:
#
# Netris -- A free networked version of T*tris
# Copyright (C) 1994-1996,1999 Mark H. Weaver <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: Configure,v 1.18 1999/05/16 06:56:19 mhw Exp $
#
CC="gcc"
COPT="-g -O"
CEXTRA=""
LEXTRA=""
CURSES_HACK=false
while [ $# -ge 1 ]; do
opt="$1"
shift
case "$opt" in
-g)
COPT="-g"
CEXTRA="-Wall -Wstrict-prototypes"
;;
-O*)
COPT="$opt"
CEXTRA="-DNDEBUG"
;;
--cc)
CC="$1"
shift
;;
--copt)
COPT="$1"
shift
;;
--cextra)
CEXTRA="$1"
shift
;;
--lextra)
LEXTRA="$1"
shift
;;
--curses-hack)
CURSES_HACK=true
;;
*)
cat << "END"
Usage: ./Configure [options...]
-g: Full debugging, no optimization, and full warnings
-O?: Optimization, no debugging or warnings
--cc <compiler>: Set the C compiler to use (default "gcc")
--copt <opt>: Set C optimization flags
--cextra <opt>: Set extra C flags
--lextra <opt>: Set extra linker flags
--curses-hack: Disable scroll-optimization for broken curses
END
exit 1
;;
esac
done
CFLAGS="$COPT $CEXTRA"
echo "Checking for libraries"
echo 'main(){}' > test.c
LFLAGS=""
for lib in -lcurses -lncurses; do
if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then
LFLAGS="$lib"
fi
done
for lib in -lsocket -lnsl -ltermcap; do
if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then
LFLAGS="$LFLAGS $lib"
fi
done
echo "Checking for on_exit()"
cat << END > test.c
void handler(void) {}
main() { on_exit(handler, (void *)0); }
END
if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
HAS_ON_EXIT=true
else
HAS_ON_EXIT=false
fi
echo "Checking for sigprocmask()"
cat << END > test.c
#include <signal.h>
main() { sigset_t set; sigprocmask(SIG_BLOCK, &set, &set); }
END
if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
HAS_SIGPROCMASK=true
else
HAS_SIGPROCMASK=false
fi
echo "Checking for getopt.h"
cat << END > test.c
#include <getopt.h>
main(){}
END
if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
HAS_GETOPT_H=true
else
HAS_GETOPT_H=false
fi
echo "Checking for memory.h"
cat << END > test.c
#include <memory.h>
main(){}
END
if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
HAS_MEMORY_H=true
else
HAS_MEMORY_H=false
fi
rm -f test.c test.o a.out
ORIG_SOURCES="game- curses- shapes- board- util- inet- robot-"
GEN_SOURCES="version-"
SOURCES="$ORIG_SOURCES $GEN_SOURCES"
SRCS="`echo $SOURCES | sed -e s/-/.c/g`"
OBJS="`echo $SOURCES | sed -e s/-/.o/g`"
DISTFILES="README FAQ COPYING VERSION Configure netris.h sr.c robot_desc"
DISTFILES="$DISTFILES `echo $ORIG_SOURCES | sed -e s/-/.c/g`"
echo > .depend
echo "Creating Makefile"
sed -e "s/-LFLAGS-/$LFLAGS/g" -e "s/-SRCS-/$SRCS/g" \
-e "s/-OBJS-/$OBJS/g" -e "s/-DISTFILES-/$DISTFILES/g" \
-e "s/-COPT-/$COPT/g" -e "s/-CEXTRA-/$CEXTRA/g" \
-e "s/-LEXTRA-/$LEXTRA/g" -e "s/-CC-/$CC/g" \
<< "END" > Makefile
#
# Automatically generated by ./Configure -- DO NOT EDIT!
#
CC = -CC-
COPT = -COPT-
CEXTRA = -CEXTRA-
LEXTRA = -LEXTRA-
LFLAGS = -LEXTRA- -LFLAGS-
CFLAGS = $(CEXTRA) $(COPT)
PROG = netris
HEADERS = netris.h
SRCS = -SRCS-
OBJS = -OBJS-
DISTFILES = -DISTFILES-
all: Makefile config.h proto.h $(PROG) sr
$(PROG): $(OBJS)
$(CC) -o $(PROG) $(OBJS) $(LFLAGS)
sr: sr.o
$(CC) -o sr sr.o $(LFLAGS)
.c.o:
$(CC) $(CFLAGS) -c $<
Makefile config.h: Configure
@echo "Makefile and/or config.h is out of date"
@echo "Run ./Configure now"
@false
version.c: VERSION
@echo "Creating version.c"
@sed -e 's/^\(.*\)$$/char *version_string = "\1";/' VERSION > $@
proto.h: $(SRCS)
@touch $@
@mv $@ [email protected]
@cat $(SRCS) | grep '^ExtFunc[ ]' | sed -e 's/)$$/);/' > $@
@if diff [email protected] $@ > /dev/null 2>&1; then :; else \
echo "proto.h changed"; \
touch proto.chg; \
fi
@rm -f [email protected]
depend: proto.h $(SRCS)
@echo "Checking dependencies"
@sed -n -e '1,/make depend #####$$/p' Makefile > Makefile.new
@$(CC) -M $(SRCS) | sed -e 's/proto\.h/proto.chg/g' >> Makefile.new
@mv -f Makefile.new Makefile
dist: $(DISTFILES)
@vers=`cat VERSION`; \
dir="netris-$$vers"; \
echo "Creating $$dir directory"; \
rm -rf $$dir; \
mkdir $$dir; \
cp $(DISTFILES) $$dir; \
chmod 755 $$dir; \
chmod 644 $$dir/*; \
chmod 755 $$dir/Configure; \
echo "Creating $$dir.tar.gz"; \
tar -cvzof $$dir.tar.gz $$dir
clean:
rm -f proto.h proto.chg $(PROG) $(OBJS) version.c test.c a.out sr sr.o
cleandir: clean
rm -f .depend Makefile config.h
##### DO NOT EDIT OR DELETE THIS LINE, it's needed by make depend #####
END
echo "Creating config.h"
cat << END > config.h
/*
* Automatically generated by ./Configure -- DO NOT EDIT!
*/
END
if [ "$HAS_GETOPT_H" = "true" ]; then
echo "#include <getopt.h>" >> config.h
else
echo "extern char *optarg;" >> config.h
echo "extern int optind;" >> config.h
fi
if [ "$HAS_MEMORY_H" = "true" ]; then
echo "#include <memory.h>" >> config.h
fi
if [ "$HAS_ON_EXIT" = "true" ]; then
echo "#define HAS_ON_EXIT" >> config.h
fi
if [ "$HAS_SIGPROCMASK" = "true" ]; then
echo "#define HAS_SIGPROCMASK" >> config.h
fi
if [ "$CURSES_HACK" = "true" ]; then
echo "#define CURSES_HACK" >> config.h
fi
echo "Running 'make depend'"
if make depend; then :; else cat << END; fi
make depend failed, but that's OK unless you're doing development
END
cat << END
Now do a 'make'
END
# vi: ts=4 ai