b3ee7018530a13306a46f73cc89c02fee48d1503
[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
21 CC="gcc"
22 COPT="-O"
23 CEXTRA="-m486"
24 LEXTRA=""
25 CURSES_HACK=false
26
27 while [ $# -ge 1 ]; do
28         opt="$1"
29         shift
30         case "$opt" in
31                 -g)
32                         COPT="-g -O0"
33 #                       CEXTRA="-Wall -Wstrict-prototypes -m486"
34                         ;;
35                 -O*)
36                         COPT="$opt"
37                         CEXTRA="-DNDEBUG"
38                         ;;
39                 --cc)
40                         CC="$1"
41                         shift
42                         ;;
43                 --copt)
44                         COPT="$1"
45                         shift
46                         ;;
47                 --cextra)
48                         CEXTRA="$1"
49                         shift
50                         ;;
51                 --lextra)
52                         LEXTRA="$1"
53                         shift
54                         ;;
55                 --curses-hack)
56                         CURSES_HACK=true
57                         ;;
58                 *)
59                         cat << "END"
60 Usage: ./Configure [options...]
61     -g: Full debugging, no optimization, and full warnings
62     -O?: Optimization, no debugging or warnings
63     --cc <compiler>: Set the C compiler to use (default "gcc")
64     --copt <opt>: Set C optimization flags
65     --cextra <opt>: Set extra C flags
66     --lextra <opt>: Set extra linker flags
67     --curses-hack: Disable scroll-optimization for broken curses
68 END
69                         exit 1
70                         ;;
71         esac
72 done
73
74 CFLAGS="$COPT $CEXTRA"
75
76 echo "Checking for libraries"
77 echo 'main(){}' > test.c
78 LFLAGS=""
79 for lib in -lcurses -lncurses; do
80         if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then
81                 LFLAGS="$lib"
82         fi
83 done
84 for lib in -lsocket -lnsl -ltermcap; do 
85         if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then
86                 LFLAGS="$LFLAGS $lib"
87         fi
88 done
89
90 echo "Checking for on_exit()"
91 cat << END > test.c
92 void handler(void) {}
93 main() { on_exit(handler, (void *)0); }
94 END
95 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
96         HAS_ON_EXIT=true
97 else
98         HAS_ON_EXIT=false
99 fi
100
101 echo "Checking for sigprocmask()"
102 cat << END > test.c
103 #include <signal.h>
104 main() { sigset_t set; sigprocmask(SIG_BLOCK, &set, &set); }
105 END
106 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
107         HAS_SIGPROCMASK=true
108 else
109         HAS_SIGPROCMASK=false
110 fi
111
112 echo "Checking for getopt.h"
113 cat << END > test.c
114 #include <getopt.h>
115 main(){}
116 END
117
118 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
119         HAS_GETOPT_H=true
120 else
121         HAS_GETOPT_H=false
122 fi
123
124 echo "Checking for memory.h"
125 cat << END > test.c
126 #include <memory.h>
127 main(){}
128 END
129
130 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
131         HAS_MEMORY_H=true
132 else
133         HAS_MEMORY_H=false
134 fi
135
136 rm -f test.c test.o a.out
137
138 SOURCES="game- curses- board- util- inet-"
139 SRCS="`echo $SOURCES | sed -e s/-/.c/g`"
140 OBJS="`echo $SOURCES | sed -e s/-/.o/g`"
141 SSOURCES="server- util-"
142 SSRCS="`echo $SSOURCES | sed -e s/-/.c/g`"
143 SOBJS="`echo $SSOURCES | sed -e s/-/.o/g`"
144
145 DISTFILES="README FAQ INSTALL COPYING VERSION TODO ChangeLog Configure netris.h"
146 DISTFILES="$DISTFILES $SRCS server.c"
147
148 echo "Creating Makefile"
149 sed -e "s/-LFLAGS-/$LFLAGS/g" -e "s/-OBJS-/$OBJS/g" \
150         -e "s/-SOBJS-/$SOBJS/g" -e "s/-DISTFILES-/$DISTFILES/g" \
151         -e "s/-COPT-/$COPT/g" -e "s/-CEXTRA-/$CEXTRA/g" \
152         -e "s/-LEXTRA-/$LEXTRA/g" -e "s/-CC-/$CC/g" \
153         << "END" > Makefile
154 #
155 # Automatically generated by ./Configure -- DO NOT EDIT!
156 #
157
158 CC = -CC-
159 COPT = -COPT-
160 CEXTRA = -CEXTRA-
161 LEXTRA = -LEXTRA-
162 LFLAGS = -LEXTRA- -LFLAGS-
163 CFLAGS = $(CEXTRA) $(COPT)
164
165 PROG = netris
166 SPROG = netrisserver
167 HEADERS = netris.h
168 OBJS = -OBJS-
169 SOBJS = -SOBJS-
170 DISTFILES = -DISTFILES-
171
172 all: Makefile config.h $(PROG) $(SPROG)
173
174 $(PROG): $(OBJS)
175         $(CC) -o $(PROG) $(OBJS) $(LFLAGS) $(CFLAGS)
176
177 $(SPROG): $(SOBJS)
178         $(CC) -o $(SPROG) $(SOBJS) $(LFLAGS) $(CFLAGS)
179
180 .c.o:
181         $(CC) $(CFLAGS) -c $<
182
183 Makefile config.h: Configure
184         @echo "Makefile and/or config.h is out of date"
185         @echo "Run ./Configure now"
186         @false
187
188 dist: $(DISTFILES)
189         @vers=`cat VERSION`; \
190         dir="netris-$$vers"; \
191         echo "Creating $$dir directory"; \
192         rm -rf $$dir; \
193         mkdir $$dir; \
194         cp $(DISTFILES) $$dir; \
195         chmod 755 $$dir; \
196         chmod 644 $$dir/*; \
197         chmod 755 $$dir/Configure; \
198         echo "Creating $$dir.tar.gz"; \
199         tar -cvzof $$dir.tar.gz $$dir
200
201 clean:
202         rm -f $(PROG) $(OBJS) $(SPROG) $(SOBJS) a.out
203
204 cleandir: clean
205         rm -f Makefile config.h
206
207 END
208
209 echo "Creating config.h"
210 cat << END > config.h
211 /*
212  * Automatically generated by ./Configure -- DO NOT EDIT!
213  */
214
215 END
216
217 if [ "$HAS_GETOPT_H" = "true" ]; then
218         echo "#include <getopt.h>" >> config.h
219 else
220         echo "extern char *optarg;" >> config.h
221         echo "extern int optind;" >> config.h
222 fi
223 if [ "$HAS_MEMORY_H" = "true" ]; then
224         echo "#include <memory.h>" >> config.h
225 fi
226 if [ "$HAS_ON_EXIT" = "true" ]; then
227         echo "#define HAS_ON_EXIT" >> config.h
228 fi
229 if [ "$HAS_SIGPROCMASK" = "true" ]; then
230         echo "#define HAS_SIGPROCMASK" >> config.h
231 fi
232 if [ "$CURSES_HACK" = "true" ]; then
233         echo "#define CURSES_HACK" >> config.h
234 fi
235
236 cat << END
237
238 Now do a 'make'
239
240 END
241