add bug report from alternate branch
[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"
25 CEXTRA="-m486"
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 -m486"
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 SOURCES="game- curses- board- util- inet-"
141 SRCS="`echo $SOURCES | sed -e s/-/.c/g`"
142 OBJS="`echo $SOURCES | sed -e s/-/.o/g`"
143 SSOURCES="server- util-"
144 SSRCS="`echo $SSOURCES | sed -e s/-/.c/g`"
145 SOBJS="`echo $SSOURCES | sed -e s/-/.o/g`"
146
147 DISTFILES="README FAQ INSTALL COPYING VERSION TODO ChangeLog Configure netris.h"
148 DISTFILES="$DISTFILES $SRCS server.c"
149
150 echo "Creating Makefile"
151 sed -e "s/-LFLAGS-/$LFLAGS/g" -e "s/-OBJS-/$OBJS/g" \
152         -e "s/-SOBJS-/$SOBJS/g" -e "s/-DISTFILES-/$DISTFILES/g" \
153         -e "s/-COPT-/$COPT/g" -e "s/-CEXTRA-/$CEXTRA/g" \
154         -e "s/-LEXTRA-/$LEXTRA/g" -e "s/-CC-/$CC/g" \
155         << "END" > Makefile
156 #
157 # Automatically generated by ./Configure -- DO NOT EDIT!
158 #
159
160 CC = -CC-
161 COPT = -COPT-
162 CEXTRA = -CEXTRA-
163 LEXTRA = -LEXTRA-
164 LFLAGS = -LEXTRA- -LFLAGS-
165 CFLAGS = $(CEXTRA) $(COPT)
166
167 PROG = netris
168 SPROG = netrisserver
169 HEADERS = netris.h
170 OBJS = -OBJS-
171 SOBJS = -SOBJS-
172 DISTFILES = -DISTFILES-
173
174 all: Makefile config.h $(PROG) $(SPROG)
175
176 $(PROG): $(OBJS)
177         $(CC) -o $(PROG) $(OBJS) $(LFLAGS) $(CFLAGS)
178
179 $(SPROG): $(SOBJS)
180         $(CC) -o $(SPROG) $(SOBJS) $(LFLAGS) $(CFLAGS)
181
182 .c.o:
183         $(CC) $(CFLAGS) -c $<
184
185 Makefile config.h: Configure
186         @echo "Makefile and/or config.h is out of date"
187         @echo "Run ./Configure now"
188         @false
189
190 dist: $(DISTFILES)
191         @vers=`cat VERSION`; \
192         dir="netris-$$vers"; \
193         echo "Creating $$dir directory"; \
194         rm -rf $$dir; \
195         mkdir $$dir; \
196         cp $(DISTFILES) $$dir; \
197         chmod 755 $$dir; \
198         chmod 644 $$dir/*; \
199         chmod 755 $$dir/Configure; \
200         echo "Creating $$dir.tar.gz"; \
201         tar -cvzof $$dir.tar.gz $$dir
202
203 clean:
204         rm -f $(PROG) $(OBJS) $(SPROG) $(SOBJS) a.out
205
206 cleandir: clean
207         rm -f Makefile config.h
208
209 END
210
211 echo "Creating config.h"
212 cat << END > config.h
213 /*
214  * Automatically generated by ./Configure -- DO NOT EDIT!
215  */
216
217 END
218
219 if [ "$HAS_GETOPT_H" = "true" ]; then
220         echo "#include <getopt.h>" >> config.h
221 else
222         echo "extern char *optarg;" >> config.h
223         echo "extern int optind;" >> config.h
224 fi
225 if [ "$HAS_MEMORY_H" = "true" ]; then
226         echo "#include <memory.h>" >> config.h
227 fi
228 if [ "$HAS_ON_EXIT" = "true" ]; then
229         echo "#define HAS_ON_EXIT" >> config.h
230 fi
231 if [ "$HAS_SIGPROCMASK" = "true" ]; then
232         echo "#define HAS_SIGPROCMASK" >> config.h
233 fi
234 if [ "$CURSES_HACK" = "true" ]; then
235         echo "#define CURSES_HACK" >> config.h
236 fi
237
238 cat << END
239
240 Now do a 'make'
241
242 END
243
244 # vi: ts=4 ai