use more customary lowercase filename for configure script
[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 echo "Creating config.mak"
139 cat > config.mak << END
140 ### Automatically generated by ./configure ###
141
142 CC = $CC
143 COPT = $COPT
144 CEXTRA = $CEXTRA
145 LEXTRA = $LEXTRA
146 LFLAGS = $LEXTRA $LFLAGS
147 CFLAGS = \$(CEXTRA) \$(COPT)
148 END
149
150 echo "Creating config.h"
151 cat << END > config.h
152 /*** Automatically generated by ./configure ***/
153
154 END
155
156 if [ "$HAS_GETOPT_H" = "true" ]; then
157         echo "#include <getopt.h>" >> config.h
158 else
159         echo "extern char *optarg;" >> config.h
160         echo "extern int optind;" >> config.h
161 fi
162 if [ "$HAS_MEMORY_H" = "true" ]; then
163         echo "#include <memory.h>" >> config.h
164 fi
165 if [ "$HAS_ON_EXIT" = "true" ]; then
166         echo "#define HAS_ON_EXIT" >> config.h
167 fi
168 if [ "$HAS_SIGPROCMASK" = "true" ]; then
169         echo "#define HAS_SIGPROCMASK" >> config.h
170 fi
171 if [ "$CURSES_HACK" = "true" ]; then
172         echo "#define CURSES_HACK" >> config.h
173 fi
174
175 cat << END
176
177 Now do a 'make'
178
179 END
180