Tweaked CFLAGS detection in config.sh.
[ahxm.git] / config.sh
blob36cdb196a259883019a6f8922fd852425518bda2
1 #!/bin/sh
3 # Configuration shell script
5 BIN="ahxm midiin"
7 # gets program version
8 VERSION=`cut -f2 -d\" VERSION`
10 # default installation prefix
11 PREFIX=/usr/local
13 # parse arguments
14 while [ $# -gt 0 ] ; do
16 case $1 in
17 --help) CONFIG_HELP=1 ;;
19 --with-pthreads) WITH_PTHREADS=1 ;;
21 --prefix) PREFIX=$2 ; shift ;;
22 --prefix=*) PREFIX=`echo $1 | sed -e 's/--prefix=//'` ;;
23 esac
25 shift
26 done
28 if [ "$CONFIG_HELP" = "1" ] ; then
30 echo "Available options:"
31 echo "--prefix=PREFIX Installation prefix ($PREFIX)."
32 echo "--with-pthreads Activate POSIX threads support."
34 echo
35 echo "Environment variables:"
36 echo "CC C Compiler."
37 echo "CFLAGS Compile flags (i.e., -O3)."
38 echo "AR Archiver."
39 echo "LEX Lexer."
40 echo "YACC Parser."
42 exit 1
45 echo "Configuring..."
47 echo "/* automatically created by config.sh - do not modify */" > config.h
48 echo "# automatically created by config.sh - do not modify" > makefile.opts
49 > config.ldflags
50 > config.cflags
51 > .config.log
53 # set compiler
54 if [ "$CC" = "" ] ; then
55 CC=cc
56 # if CC is unset, try if gcc is available
57 which gcc > /dev/null 2>&1
59 if [ $? = 0 ] ; then
60 CC=gcc
64 echo "CC=$CC" >> makefile.opts
66 # set archiver
67 if [ "$AR" = "" ] ; then
68 AR=ar
71 echo "AR=$AR" >> makefile.opts
73 # set lexer
74 if [ "$LEX" = "" ] ; then
75 LEX=lex
78 echo "LEX=$LEX" >> makefile.opts
80 # set parser
81 if [ "$YACC" = "" ] ; then
82 YACC=yacc
85 echo "YACC=$YACC" >> makefile.opts
87 # add version
88 cat VERSION >> config.h
90 # add installation prefix
91 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
93 DRIVERS="wav"
95 #########################################################
97 # configuration directives
99 # CFLAGS
100 if [ -z "$CFLAGS" ] ; then
101 CFLAGS="-g -Wall"
104 echo -n "Testing if C compiler supports ${CFLAGS}... "
105 echo "int main(int argc, char *argv[]) { return 0; }" > .tmp.c
107 $CC .tmp.c -o .tmp.o 2>> .config.log
109 if [ $? = 0 ] ; then
110 echo "OK"
111 else
112 echo "No; resetting to defaults"
113 CFLAGS=""
116 echo "CFLAGS=$CFLAGS" >> makefile.opts
118 # Add CFLAGS to CC
119 CC="$CC $CFLAGS"
121 # Win32
122 echo -n "Testing for win32... "
123 if [ "$WITHOUT_WIN32" = "1" ] ; then
124 echo "Disabled by user"
125 else
126 echo "#include <windows.h>" > .tmp.c
127 echo "#include <commctrl.h>" >> .tmp.c
128 echo "int STDCALL WinMain(HINSTANCE h, HINSTANCE p, LPSTR c, int m)" >> .tmp.c
129 echo "{ return 0; }" >> .tmp.c
131 TMP_LDFLAGS="-lwinmm"
132 $CC .tmp.c $TMP_LDFLAGS -o .tmp.o 2>> .config.log
134 if [ $? = 0 ] ; then
135 echo "#define CONFOPT_WIN32 1" >> config.h
136 echo "OK"
137 WITHOUT_UNIX_GLOB=1
138 WITH_WIN32=1
139 echo $TMP_LDFLAGS >> config.ldflags
140 DRIVERS="win32 ${DRIVERS}"
141 else
142 echo "No"
146 # test for Linux OSS
147 echo -n "Testing for Linux OSS... "
148 echo "#include <linux/soundcard.h>" > .tmp.c
149 echo "int main(void) {" >> .tmp.c
150 echo "int i=open(\"/dev/dsp\",0);" >> .tmp.c
151 echo "ioctl(i,SNDCTL_DSP_SETFRAGMENT,&i);" >> .tmp.c
152 echo "return 0; } " >>.tmp.c
154 $CC .tmp.c -o .tmp.o 2> /dev/null
155 if [ $? = 0 ] ; then
156 echo "#define CONFOPT_LINUX_OSS 1" >> config.h
157 echo "OK"
158 DRIVERS="oss ${DRIVERS}"
159 else
160 echo "No"
163 # test for IRIX audio library
164 echo -n "Testing for IRIX audio library... "
165 echo "#include <dmedia/audio.h>" > .tmp.c
166 echo "int main(void) { alNewConfig(); return 0; }" >> .tmp.c
168 $CC .tmp.c -laudio -o .tmp.o 2> /dev/null
169 if [ $? = 0 ] ; then
170 echo "#define CONFOPT_SGI 1" >> config.h
171 echo "-laudio" >> config.ldflags
172 echo "OK"
173 DRIVERS="sgi ${DRIVERS}"
174 else
175 echo "No"
178 # test for esound library
179 echo -n "Testing for esound development libraries... "
180 echo "#include <esd.h>" > .tmp.c
181 echo "int main(void) { return 0; }" >> .tmp.c
183 $CC -I/usr/local/include -L/usr/local/lib -lesd .tmp.c -o .tmp.o 2> /dev/null
184 if [ $? = 0 ] ; then
185 echo "#define CONFOPT_ESD 1" >> config.h
186 echo "-lesd" >> config.ldflags
187 echo "OK"
188 DRIVERS="esd ${DRIVERS}"
189 else
190 echo "No"
193 # test for artsc library
194 echo -n "Testing for aRts development libraries... "
195 echo "#include <artsc.h>" > .tmp.c
196 echo "int main(void) { arts_init(); return 0; }" >> .tmp.c
198 TMP_CFLAGS=`artsc-config --cflags 2>/dev/null`
199 TMP_LDFLAGS=`artsc-config --libs 2>/dev/null`
201 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
202 if [ $? = 0 ] ; then
203 echo "#define CONFOPT_ARTS 1" >> config.h
204 echo $TMP_CFLAGS >> config.cflags
205 echo $TMP_LDFLAGS >> config.ldflags
206 echo "OK"
207 DRIVERS="arts ${DRIVERS}"
208 else
209 echo "No"
212 # test for pulseaudio libraries
213 echo -n "Testing for Pulseaudio development libraries... "
214 echo "#include <pulse/simple.h>" > .tmp.c
215 echo "#include <pulse/error.h>" >> .tmp.c
216 echo "int main(void) { return 0; }" >> .tmp.c
218 TMP_CFLAGS=$(pkg-config libpulse-simple --cflags 2>/dev/null)
219 TMP_LDFLAGS=$(pkg-config libpulse-simple --libs 2>/dev/null)
221 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
222 if [ $? = 0 ] ; then
223 echo "#define CONFOPT_PULSEAUDIO 1" >> config.h
224 echo $TMP_CFLAGS >> config.cflags
225 echo $TMP_LDFLAGS >> config.ldflags
226 echo "OK"
227 DRIVERS="pulse ${DRIVERS}"
228 else
229 echo "No"
232 # test for getuid() availability
233 echo -n "Testing for getuid() existence... "
234 echo "#include <unistd.h>" > .tmp.c
235 echo "#include <sys/types.h>" >> .tmp.c
236 echo "int main(void) { getuid(); return 0; }" >> .tmp.c
238 TMP_CFLAGS=""
239 TMP_LDFLAGS=""
240 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
241 if [ $? = 0 ] ; then
242 echo "OK"
243 else
244 echo "No; activating workaround"
245 echo "#define getuid() 1000" >> config.h
248 # test for number of arguments in mkdir()
249 echo -n "Testing for number of arguments in mkdir()... "
250 echo "#include <stdio.h>" > .tmp.c
251 echo "#include <string.h>" >> .tmp.c
252 echo "#include <stdlib.h>" >> .tmp.c
253 echo "#include <unistd.h>" >> .tmp.c
254 echo "#include <sys/stat.h>" >> .tmp.c
255 echo "#include <sys/types.h>" >> .tmp.c
256 echo "int main(void) { mkdir(\"testdir\"); return 0; }" >> .tmp.c
258 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
259 if [ $? = 0 ] ; then
260 echo "1"
261 echo "#define CONFOPT_MKDIR_ARGS 1" >> config.h
262 else
263 echo "2"
264 echo "#define CONFOPT_MKDIR_ARGS 2" >> config.h
267 echo -n "Testing for nanosleep() support... "
268 echo "#include <time.h>" > .tmp.c
269 echo "int main(void) { struct timespec ts; nanosleep(&ts, NULL); return 0; }" >> .tmp.c
271 TMP_CFLAGS=""
272 TMP_LDFLAGS=""
273 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
274 if [ $? = 0 ] ; then
275 echo "OK"
276 echo "#define CONFOPT_NANOSLEEP 1" >> config.h
277 else
278 echo "No; MIDI output will not be available"
279 BIN="ahxm"
282 # pthreads support
283 if [ "$WITH_PTHREADS" = 1 ] ; then
284 echo "#define CONFOPT_PTHREADS 1" >> config.h
285 echo "-pthread" >> config.ldflags
288 # test for Grutatxt
289 echo -n "Testing if Grutatxt is installed... "
291 DOCS="\$(ADD_DOCS)"
293 if which grutatxt > /dev/null 2>&1 ; then
294 echo "OK"
295 echo "GRUTATXT=yes" >> makefile.opts
296 DOCS="\$(GRUTATXT_DOCS)"
297 else
298 echo "No"
299 echo "GRUTATXT=no" >> makefile.opts
302 # test for mp_doccer
303 echo -n "Testing if mp_doccer is installed... "
304 MP_DOCCER=$(which mp_doccer||which mp-doccer)
306 if [ $? = 0 ] ; then
308 if ${MP_DOCCER} --help | grep grutatxt > /dev/null ; then
310 echo "OK"
312 echo "MP_DOCCER=yes" >> makefile.opts
313 DOCS="$DOCS \$(MP_DOCCER_DOCS)"
315 grep GRUTATXT=yes makefile.opts > /dev/null && DOCS="$DOCS \$(G_AND_MP_DOCS)"
316 else
317 echo "Outdated (No)"
318 echo "MP_DOCCER=no" >> makefile.opts
320 else
321 echo "No"
322 echo "MP_DOCCER=no" >> makefile.opts
325 #########################################################
327 # final setup
329 echo "BIN=$BIN" >> makefile.opts
330 echo "DOCS=$DOCS" >> makefile.opts
331 echo "VERSION=$VERSION" >> makefile.opts
332 echo "PREFIX=$PREFIX" >> makefile.opts
333 echo >> makefile.opts
335 cat makefile.opts makefile.in makefile.depend > Makefile
337 echo "#define CONFOPT_DRIVERS \"${DRIVERS}\"" >> config.h
338 echo
339 echo "Configured drivers: ${DRIVERS}"
341 #########################################################
343 # cleanup
345 rm -f .tmp.c .tmp.o
347 exit 0