1#!/bin/sh
2
3#
4# configure
5#
6# This script should be started before 'make'.
7# It should detect your personal configuration.
8#
9
10OS=`uname`
11case $OS in
12	Linux) OSDEF=_LINUX ;;
13	*BSD) OSDEF=_BSD ;;
14	SunOS) OSDEF=_SUNOS ;;
15	*) OSDEF=_UNKNOWN ;;
16esac
17echo "System define: $OSDEF"
18
19echo -n "Looking for Xorg headers... "
20X11PATH=""
21test -r /usr/local/include/X11/Xlib.h && X11PATH=/usr/local
22test -r /usr/X11R6/include/X11/Xlib.h && X11PATH=/usr/X11R6
23if [ -z "$X11PATH" ]; then
24	echo "not found (CONFIGURE ERROR!)."
25	exit 1
26else
27	echo "found in $X11PATH"
28fi
29
30echo "Setting up prefixes..."
31PREFIXSETUPBSD="\
32.if !defined(PREFIX)\n\
33PREFIX = \/usr\/local\n\
34.endif\n\
35\n\
36.if !defined(X11BASE)\n\
37X11BASE = $X11PATH\n\
38.endif\n\
39"
40
41PREFIXSETUPGNU="\
42ifndef PREFIX\n\
43PREFIX = /usr/local\n\
44endif\n\
45\n\
46ifndef X11BASE\n\
47X11BASE = X11PATH\n\
48endif\n\
49"
50
51rm -f ./conftest ./Makefile ./GNUmakefile
52printf "Testing compiler ... ";
53cc -Wall -Wstrict-prototypes -o conftest conftest.c
54if [ $? -ne 0 ]; then
55	echo "Compilation failed."
56	exit 1
57fi
58./conftest
59
60case $? in
610)   printf "cc: test FAILED.\n";exit 1;;
621)   ENDIANSTR="";;
632)   ENDIANSTR="-DUSE_LITTLE_ENDIAN";;
64esac
65
66OS=`uname`
67case $OS in
68*BSD)  printf "Using -pthread.\n"; PTHREAD="-pthread";;
69    *) printf "Using -lpthread.\n"; PTHREAD="-lpthread";;
70esac
71
72printf "Searching special header files ...\n"
73printf "fb.h: "
74if test -r /usr/include/linux/fb.h ; then
75    printf "found.\n";
76    if test ! -e "/dev/fb0" ; then
77    printf "Warning: /dev/fb0 doesn't exist.\n";
78    fi
79    FBSTR="-DFRAMEBUFFER"
80else
81    printf "not found.\n";
82    unset FBSTR;
83fi
84
85printf "joystick.h: "
86if test -r /usr/include/linux/joystick.h || test -r /usr/include/sys/joystick.h ; then
87    printf "found.\n";
88    if test ! -e "/dev/js0" ; then
89	if test ! -e "/dev/joy0"; then
90	    printf "Warning: /dev/js0 and /dev/joy0 don't exist.\n";
91	    printf "         Setting device to /dev/js0.\n";
92	fi
93	case $OS in
94	    *BSD)  printf "Using BSD joystick.\n"; JOYSTR="-DBSD_JOYSTICK";;
95	    *) printf "Using Linux joystick.\n"; JOYSTR="-DJOYSTICK";;
96	esac
97    else
98	JOYSTR="-DJOYSTICK"
99    fi
100    printf "Compiling joy-button configuration ... "
101    JOYCONF="conf"
102    JOYINST="install -m 755 -s .\/cingb_conf \/usr\/local\/bin\/cingb_conf"
103    printf "ok\n";
104else
105    printf "not found.\n";
106    unset JOYSTR;
107fi
108
109printf "soundcard.h: "
110if test -r /usr/include/linux/soundcard.h || test -r /usr/include/sys/soundcard.h ; then
111    printf "found.\n";
112    SNDSTR="-DSOUND";
113else
114    printf "not found.\n";
115    printf "audioio.h: "
116    if test -r /usr/include/sys/audioio.h ; then
117	printf "found.\n";
118	SNDSTR="-DSOUND -DAUDIO";
119    else
120	printf "not found.\n";
121	unset SNDSTR;
122    fi
123fi
124
125
126printf "Xvlib.h: "
127if test -r $X11PATH/include/X11/extensions/Xvlib.h ; then
128    printf "found.\n";
129    XVIDEODEF="-DWITH_XVIDEO";
130    LIBXV="-lXv"
131else
132    printf "not found.\n";
133    unset XVIDEODEF
134    unset LIBXV
135fi
136
137printf "XShm.h: "
138if test -r $X11PATH/include/X11/extensions/XShm.h ; then
139    printf "found.\n";
140    SHMSTR="-DMIT_SHM";
141    LIBSHM="-lXext";
142else
143    printf "not found.\n";
144    unset SHMSTR;
145    unset LIBSHM;
146fi
147
148printf "Checking libraries  ...\n"
149printf "libsocket ... "
150if test -r /lib/libsocket.a || test -r /usr/lib/libsocket.a ; then
151    printf "found.\n";
152    LIBSOCK="-lsocket";
153else
154    printf "not found.\n"
155    unset LIBSOCK;
156fi
157
158printf "libnsl ... "
159if test -r /lib/libnsl.a || test -r /usr/lib/libnsl.a ; then
160    printf "found.\n";
161    LIBNSL="-lnsl";
162else
163    printf "not found.\n";
164    unset LIBNSL;
165fi
166
167
168printf "Creating Makefile ... "
169sed "s/%%%endian%%%/$ENDIANSTR/;s/%%%joystick%%%/$JOYSTR/;s/%%%framebuffer%%%/$FBSTR/;s/%%%sound%%%/$SNDSTR/;s/%%%libnsl%%%/$LIBNSL/;s/%%%libsocket%%%/$LIBSOCK/;s/%%%mitshm%%%/$SHMSTR/;s/%%%libext%%%/$LIBSHM/;s/%%%pthread%%%/$PTHREAD/;s/%%%joyconf%%%/$JOYCONF/;s/%%%joyinst%%%/$JOYINST/; s/%%%XVDEF%%%/$XVIDEODEF/; s/%%%LIBXV%%%/$LIBXV/; s/%%%OSDEF%%%/-D$OSDEF/" Makefile.templ > Makefile.pre
170
171awk "/%%%prefix-setup%%%/ { print \"$PREFIXSETUPBSD\";next};{ print \$0 }" Makefile.pre > Makefile
172awk "/%%%prefix-setup%%%/ { print \"$PREFIXSETUPGNU\";next};{ print \$0 }" Makefile.pre > GNUmakefile
173
174if test "$?"="0"; then
175	printf "ok\n";
176else
177        printf "FAILED\n";
178	exit 1;
179fi
180
181if test -n "$JOYPATH" ; then
182    printf "\n................................................\n";
183    printf "Now run 'make'.\n";
184fi
185