code duplication
[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                 --lang)
59                         lang="$1"
60                         shift
61                         ;;
62                 *)
63                         cat << "END"
64 Usage: ./configure [options...]
65     -g: Full debugging, no optimization, and full warnings
66     -O?: Optimization, no debugging or warnings
67     --cc <compiler>: Set the C compiler to use (default "gcc")
68     --copt <opt>: Set C optimization flags
69     --cextra <opt>: Set extra C flags
70     --lextra <opt>: Set extra linker flags
71     --curses-hack: Disable scroll-optimization for broken curses
72     --lang <code>: Preferred interface language (default "en")
73 END
74                         exit 1
75                         ;;
76         esac
77 done
78
79 CFLAGS="$COPT $CEXTRA"
80
81 echo "Checking for libraries"
82 echo 'main(){}' > test.c
83 LFLAGS=""
84 for lib in -lcurses -lncurses; do
85         if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then
86                 LFLAGS="$lib"
87         fi
88 done
89 for lib in -lsocket -lnsl -ltermcap; do 
90         if $CC $CFLAGS $LEXTRA test.c $lib > /dev/null 2>&1; then
91                 LFLAGS="$LFLAGS $lib"
92         fi
93 done
94
95 echo "Checking for on_exit()"
96 cat << END > test.c
97 void handler(void) {}
98 main() { on_exit(handler, (void *)0); }
99 END
100 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
101         HAS_ON_EXIT=true
102 else
103         HAS_ON_EXIT=false
104 fi
105
106 echo "Checking for sigprocmask()"
107 cat << END > test.c
108 #include <signal.h>
109 main() { sigset_t set; sigprocmask(SIG_BLOCK, &set, &set); }
110 END
111 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
112         HAS_SIGPROCMASK=true
113 else
114         HAS_SIGPROCMASK=false
115 fi
116
117 echo "Checking for getopt.h"
118 cat << END > test.c
119 #include <getopt.h>
120 main(){}
121 END
122
123 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
124         HAS_GETOPT_H=true
125 else
126         HAS_GETOPT_H=false
127 fi
128
129 echo "Checking for memory.h"
130 cat << END > test.c
131 #include <memory.h>
132 main(){}
133 END
134
135 if $CC $CFLAGS $LEXTRA test.c > /dev/null 2>&1; then
136         HAS_MEMORY_H=true
137 else
138         HAS_MEMORY_H=false
139 fi
140
141 rm -f test.c test.o a.out
142
143 test -z "$lang" && lang=en
144 MSG_FILE=msg.$lang.h
145 if [ ! -f $MSG_FILE ]; then
146         echo "Error: $MSG_FILE not found"
147         exit
148 fi
149
150 echo "Creating config.mak"
151 cat > config.mak << END
152 ### Automatically generated by ./configure ###
153
154 CC = $CC
155 COPT = $COPT
156 CEXTRA = $CEXTRA
157 LEXTRA = $LEXTRA
158 LFLAGS = $LEXTRA $LFLAGS
159 CFLAGS = \$(CEXTRA) \$(COPT)
160 MSG_FILE = $MSG_FILE
161 END
162
163 echo "Creating config.h"
164 cat << END > config.h
165 /*** Automatically generated by ./configure ***/
166
167 END
168
169 if [ "$HAS_GETOPT_H" = "true" ]; then
170         echo "#include <getopt.h>" >> config.h
171 else
172         echo "extern char *optarg;" >> config.h
173         echo "extern int optind;" >> config.h
174 fi
175 if [ "$HAS_MEMORY_H" = "true" ]; then
176         echo "#include <memory.h>" >> config.h
177 fi
178 if [ "$HAS_ON_EXIT" = "true" ]; then
179         echo "#define HAS_ON_EXIT" >> config.h
180 fi
181 if [ "$HAS_SIGPROCMASK" = "true" ]; then
182         echo "#define HAS_SIGPROCMASK" >> config.h
183 fi
184 if [ "$CURSES_HACK" = "true" ]; then
185         echo "#define CURSES_HACK" >> config.h
186 fi
187
188 cat << END
189
190 Now do a 'make'
191
192 END
193