a17707ebd95e8f344d1e65a48bfcd1a9605620e6
[netris.git] / Configure
1 :
2 #
3 # Netris -- A free networked version of T*tris
4 # Copyright (C) 1994-1996,1999  Mark H. Weaver <mhw@netris.org>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #
20 # $Id: Configure,v 1.18 1999/05/16 06:56:19 mhw Exp $
21 #
22
23 CC="gcc"
24 COPT="-O -m486"
25 CEXTRA=""
26 LEXTRA=""
27 CURSES_HACK=false
28
29 while [ $# -ge 1 ]; do
30         opt="$1"
31         shift
32         case "$opt" in
33                 -g)
34                         COPT="-g -O0"
35 #                       CEXTRA="-Wall -Wstrict-prototypes"
36                         ;;
37                 -O*)
38                         COPT="$opt"
39                         CEXTRA="-DNDEBUG"
40                         ;;
41                 --cc)
42                         CC="$1"
43                         shift
44                         ;;
45                 --copt)
46                         COPT="$1"
47                         shift
48                         ;;
49                 --cextra)
50                         CEXTRA="$1"
51                         shift
52                         ;;
53                 --lextra)
54                         LEXTRA="$1"
55                         shift
56                         ;;
57                 --curses-hack)
58                         CURSES_HACK=true
59                         ;;
60                 *)
61                         cat << "END"
62 Usage: ./Configure [options...]
63     -g: Full debugging, no optimization, and full warnings
64     -O?: Optimization, no debugging or warnings
65     --cc <compiler>: Set the C compiler to use (default "gcc")
66     --copt <opt>: Set C optimization flags
67     --cextra <opt>: Set extra C flags
68     --lextra <opt>: Set extra linker flags
69     --curses-hack: Disable scroll-optimization for broken curses
70 END
71                         exit 1
72                         ;;
73         esac
74 done
75
76 CFLAGS="$COPT $CEXTRA"
77
78 echo "Checking for libraries"
79 echo 'main(){}' > test.c
80 LFLAGS=""
81 for lib in -lcurses -lncurses; do
82         if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then
83                 LFLAGS="$lib"
84         fi
85 done
86 for lib in -lsocket -lnsl -ltermcap; do 
87         if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then
88                 LFLAGS="$LFLAGS $lib"
89         fi
90 done
91
92 echo "Checking for on_exit()"
93 cat << END > test.c
94 void handler(void) {}
95 main() { on_exit(handler, (void *)0); }
96 END
97 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
98         HAS_ON_EXIT=true
99 else
100         HAS_ON_EXIT=false
101 fi
102
103 echo "Checking for sigprocmask()"
104 cat << END > test.c
105 #include <signal.h>
106 main() { sigset_t set; sigprocmask(SIG_BLOCK, &set, &set); }
107 END
108 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
109         HAS_SIGPROCMASK=true
110 else
111         HAS_SIGPROCMASK=false
112 fi
113
114 echo "Checking for getopt.h"
115 cat << END > test.c
116 #include <getopt.h>
117 main(){}
118 END
119
120 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
121         HAS_GETOPT_H=true
122 else
123         HAS_GETOPT_H=false
124 fi
125
126 echo "Checking for memory.h"
127 cat << END > test.c
128 #include <memory.h>
129 main(){}
130 END
131
132 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
133         HAS_MEMORY_H=true
134 else
135         HAS_MEMORY_H=false
136 fi
137
138 rm -f test.c test.o a.out
139
140 ORIG_SOURCES="game- curses- shapes- board- util- inet- robot-"
141 SOURCES="$ORIG_SOURCES"
142
143 SRCS="`echo $SOURCES | sed -e s/-/.c/g`"
144 OBJS="`echo $SOURCES | sed -e s/-/.o/g`"
145
146 DISTFILES="README FAQ COPYING VERSION Configure netris.h sr.c server.c robot_desc"
147 DISTFILES="$DISTFILES `echo $ORIG_SOURCES | sed -e s/-/.c/g`"
148
149 echo > .depend
150
151 echo "Creating Makefile"
152 sed -e "s/-LFLAGS-/$LFLAGS/g" -e "s/-SRCS-/$SRCS/g" \
153         -e "s/-OBJS-/$OBJS/g" -e "s/-DISTFILES-/$DISTFILES/g" \
154         -e "s/-COPT-/$COPT/g" -e "s/-CEXTRA-/$CEXTRA/g" \
155         -e "s/-LEXTRA-/$LEXTRA/g" -e "s/-CC-/$CC/g" \
156         << "END" > Makefile
157 #
158 # Automatically generated by ./Configure -- DO NOT EDIT!
159 #
160
161 CC = -CC-
162 COPT = -COPT-
163 CEXTRA = -CEXTRA-
164 LEXTRA = -LEXTRA-
165 LFLAGS = -LEXTRA- -LFLAGS-
166 CFLAGS = $(CEXTRA) $(COPT)
167
168 PROG = netris
169 HEADERS = netris.h
170
171 SRCS = -SRCS-
172 OBJS = -OBJS-
173 DISTFILES = -DISTFILES-
174
175 all: Makefile config.h proto.h $(PROG) sr server
176
177 $(PROG): $(OBJS)
178         $(CC) -o $(PROG) $(OBJS) $(LFLAGS) $(CFLAGS)
179
180 sr: sr.o
181         $(CC) -o sr sr.o $(LFLAGS) $(CFLAGS)
182
183 server: server.o
184                 $(CC) -o server server.o $(LFLAGS) $(CFLAGS)
185
186 .c.o:
187         $(CC) $(CFLAGS) -c $<
188
189 Makefile config.h: Configure
190         @echo "Makefile and/or config.h is out of date"
191         @echo "Run ./Configure now"
192         @false
193
194 proto.h: $(SRCS)
195         @touch $@
196         @mv $@ $@.old
197         @cat $(SRCS) | grep '^ExtFunc[  ]' | sed -e 's/)$$/);/' > $@
198         @if diff $@.old $@ > /dev/null 2>&1; then :; else \
199                 echo "proto.h changed"; \
200                 touch proto.chg; \
201         fi
202         @rm -f $@.old
203
204 depend: proto.h $(SRCS)
205         @echo "Checking dependencies"
206         @sed -n -e '1,/make depend #####$$/p' Makefile > Makefile.new
207         @$(CC) -M $(SRCS) | sed -e 's/proto\.h/proto.chg/g' >> Makefile.new
208         @mv -f Makefile.new Makefile
209
210 dist: $(DISTFILES)
211         @vers=`cat VERSION`; \
212         dir="netris-$$vers"; \
213         echo "Creating $$dir directory"; \
214         rm -rf $$dir; \
215         mkdir $$dir; \
216         cp $(DISTFILES) $$dir; \
217         chmod 755 $$dir; \
218         chmod 644 $$dir/*; \
219         chmod 755 $$dir/Configure; \
220         echo "Creating $$dir.tar.gz"; \
221         tar -cvzof $$dir.tar.gz $$dir
222
223 clean:
224         rm -f proto.h proto.chg $(PROG) $(OBJS) test.c a.out sr sr.o server server.o
225
226 cleandir: clean
227         rm -f .depend Makefile config.h
228
229 ##### DO NOT EDIT OR DELETE THIS LINE, it's needed by make depend #####
230 END
231
232 echo "Creating config.h"
233 cat << END > config.h
234 /*
235  * Automatically generated by ./Configure -- DO NOT EDIT!
236  */
237
238 END
239
240 if [ "$HAS_GETOPT_H" = "true" ]; then
241         echo "#include <getopt.h>" >> config.h
242 else
243         echo "extern char *optarg;" >> config.h
244         echo "extern int optind;" >> config.h
245 fi
246 if [ "$HAS_MEMORY_H" = "true" ]; then
247         echo "#include <memory.h>" >> config.h
248 fi
249 if [ "$HAS_ON_EXIT" = "true" ]; then
250         echo "#define HAS_ON_EXIT" >> config.h
251 fi
252 if [ "$HAS_SIGPROCMASK" = "true" ]; then
253         echo "#define HAS_SIGPROCMASK" >> config.h
254 fi
255 if [ "$CURSES_HACK" = "true" ]; then
256         echo "#define CURSES_HACK" >> config.h
257 fi
258
259 echo "Running 'make depend'"
260 if make depend; then :; else cat << END; fi
261
262 make depend failed, but that's OK unless you're doing development
263 END
264 cat << END
265
266 Now do a 'make'
267
268 END
269
270 # vi: ts=4 ai