Fixed mp-doccer detection broken in previous patch.
[ahxm.git] / config.sh
blob66731a936a79444cafe1e0e01c18a27297b8037f
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 cflags
67 if [ "$CFLAGS" = "" -a "$CC" = "gcc" ] ; then
68 CFLAGS="-g -Wall"
71 echo "CFLAGS=$CFLAGS" >> makefile.opts
73 # Add CFLAGS to CC
74 CC="$CC $CFLAGS"
76 # set archiver
77 if [ "$AR" = "" ] ; then
78 AR=ar
81 echo "AR=$AR" >> makefile.opts
83 # set lexer
84 if [ "$LEX" = "" ] ; then
85 LEX=lex
88 echo "LEX=$LEX" >> makefile.opts
90 # set parser
91 if [ "$YACC" = "" ] ; then
92 YACC=yacc
95 echo "YACC=$YACC" >> makefile.opts
97 # add version
98 cat VERSION >> config.h
100 # add installation prefix
101 echo "#define CONFOPT_PREFIX \"$PREFIX\"" >> config.h
103 #########################################################
105 # configuration directives
107 # test for Linux OSS
108 echo -n "Testing for Linux OSS... "
109 echo "#include <linux/soundcard.h>" > .tmp.c
110 echo "int main(void) {" >> .tmp.c
111 echo "int i=open(\"/dev/dsp\",0);" >> .tmp.c
112 echo "ioctl(i,SNDCTL_DSP_SETFRAGMENT,&i);" >> .tmp.c
113 echo "return 0; } " >>.tmp.c
115 $CC .tmp.c -o .tmp.o 2> /dev/null
116 if [ $? = 0 ] ; then
117 echo "#define CONFOPT_LINUX_OSS 1" >> config.h
118 echo "OK"
119 else
120 echo "No"
123 # test for IRIX audio library
124 echo -n "Testing for IRIX audio library... "
125 echo "#include <dmedia/audio.h>" > .tmp.c
126 echo "int main(void) { alNewConfig(); return 0; }" >> .tmp.c
128 $CC .tmp.c -laudio -o .tmp.o 2> /dev/null
129 if [ $? = 0 ] ; then
130 echo "#define CONFOPT_SGI 1" >> config.h
131 echo "-laudio" >> config.ldflags
132 echo "OK"
133 else
134 echo "No"
137 # test for esound library
138 echo -n "Testing for esound development libraries... "
139 echo "#include <esd.h>" > .tmp.c
140 echo "int main(void) { return 0; }" >> .tmp.c
142 $CC -I/usr/local/include -L/usr/local/lib -lesd .tmp.c -o .tmp.o 2> /dev/null
143 if [ $? = 0 ] ; then
144 echo "#define CONFOPT_ESD 1" >> config.h
145 echo "-lesd" >> config.ldflags
146 echo "OK"
147 else
148 echo "No"
151 # test for artsc library
152 echo -n "Testing for aRts development libraries... "
153 echo "#include <artsc.h>" > .tmp.c
154 echo "int main(void) { arts_init(); return 0; }" >> .tmp.c
156 TMP_CFLAGS=`artsc-config --cflags 2>/dev/null`
157 TMP_LDFLAGS=`artsc-config --libs 2>/dev/null`
159 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
160 if [ $? = 0 ] ; then
161 echo "#define CONFOPT_ARTS 1" >> config.h
162 echo $TMP_CFLAGS >> config.cflags
163 echo $TMP_LDFLAGS >> config.ldflags
164 echo "OK"
165 else
166 echo "No"
169 # test for pulseaudio libraries
170 echo -n "Testing for Pulseaudio development libraries... "
171 echo "#include <pulse/simple.h>" > .tmp.c
172 echo "#include <pulse/error.h>" >> .tmp.c
173 echo "int main(void) { return 0; }" >> .tmp.c
175 TMP_CFLAGS=$(pkg-config libpulse-simple --cflags 2>/dev/null)
176 TMP_LDFLAGS=$(pkg-config libpulse-simple --libs 2>/dev/null)
178 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
179 if [ $? = 0 ] ; then
180 echo "#define CONFOPT_PULSEAUDIO 1" >> config.h
181 echo $TMP_CFLAGS >> config.cflags
182 echo $TMP_LDFLAGS >> config.ldflags
183 echo "OK"
184 else
185 echo "No"
188 # test for getuid() availability
189 echo -n "Testing for getuid() existence... "
190 echo "#include <unistd.h>" > .tmp.c
191 echo "#include <sys/types.h>" >> .tmp.c
192 echo "int main(void) { getuid(); return 0; }" >> .tmp.c
194 TMP_CFLAGS=""
195 TMP_LDFLAGS=""
196 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
197 if [ $? = 0 ] ; then
198 echo "OK"
199 else
200 echo "No; activating workaround"
201 echo "#define getuid() 1000" >> config.h
204 # test for number of arguments in mkdir()
205 echo -n "Testing for number of arguments in mkdir()... "
206 echo "#include <stdio.h>" > .tmp.c
207 echo "#include <string.h>" >> .tmp.c
208 echo "#include <stdlib.h>" >> .tmp.c
209 echo "#include <unistd.h>" >> .tmp.c
210 echo "#include <sys/stat.h>" >> .tmp.c
211 echo "#include <sys/types.h>" >> .tmp.c
212 echo "int main(void) { mkdir(\"testdir\"); return 0; }" >> .tmp.c
214 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
215 if [ $? = 0 ] ; then
216 echo "1"
217 echo "#define CONFOPT_MKDIR_ARGS 1" >> config.h
218 else
219 echo "2"
220 echo "#define CONFOPT_MKDIR_ARGS 2" >> config.h
223 echo -n "Testing for nanosleep() support... "
224 echo "#include <time.h>" > .tmp.c
225 echo "int main(void) { struct timespec ts; nanosleep(&ts, NULL); return 0; }" >> .tmp.c
227 TMP_CFLAGS=""
228 TMP_LDFLAGS=""
229 $CC $TMP_CFLAGS .tmp.c $TMP_LDFLAGS -o .tmp.o 2> /dev/null
230 if [ $? = 0 ] ; then
231 echo "OK"
232 echo "#define CONFOPT_NANOSLEEP 1" >> config.h
233 else
234 echo "No; MIDI output will not be available"
235 BIN="ahxm"
238 # pthreads support
239 if [ "$WITH_PTHREADS" = 1 ] ; then
240 echo "#define CONFOPT_PTHREADS 1" >> config.h
241 echo "-pthread" >> config.ldflags
244 # test for Grutatxt
245 echo -n "Testing if Grutatxt is installed... "
247 DOCS="\$(ADD_DOCS)"
249 if which grutatxt > /dev/null 2>&1 ; then
250 echo "OK"
251 echo "GRUTATXT=yes" >> makefile.opts
252 DOCS="\$(GRUTATXT_DOCS)"
253 else
254 echo "No"
255 echo "GRUTATXT=no" >> makefile.opts
258 # test for mp_doccer
259 echo -n "Testing if mp_doccer is installed... "
260 MP_DOCCER=$(which mp_doccer||which mp-doccer)
262 if [ $? = 0 ] ; then
264 if ${MP_DOCCER} --help | grep grutatxt > /dev/null ; then
266 echo "OK"
268 echo "MP_DOCCER=yes" >> makefile.opts
269 DOCS="$DOCS \$(MP_DOCCER_DOCS)"
271 grep GRUTATXT=yes makefile.opts > /dev/null && DOCS="$DOCS \$(G_AND_MP_DOCS)"
272 else
273 echo "Outdated (No)"
274 echo "MP_DOCCER=no" >> makefile.opts
276 else
277 echo "No"
278 echo "MP_DOCCER=no" >> makefile.opts
281 #########################################################
283 # final setup
285 echo "BIN=$BIN" >> makefile.opts
286 echo "DOCS=$DOCS" >> makefile.opts
287 echo "VERSION=$VERSION" >> makefile.opts
288 echo "PREFIX=$PREFIX" >> makefile.opts
289 echo >> makefile.opts
291 cat makefile.opts makefile.in makefile.depend > Makefile
293 #########################################################
295 # cleanup
297 rm -f .tmp.c .tmp.o
299 exit 0