summaryrefslogtreecommitdiff
path: root/configure
blob: a66bf7f5eada430879566e901d3466e4c47c5a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/bin/sh

# -----------------------------
# q2pro configuration script by [SkulleR]
# -----------------------------

# defaults
sources=$(dirname $0)
if [ "$sources" = "." ]; then
    sources=`pwd`
fi
outdir=`pwd`
prefix="/usr/local"
cross_prefix=""
cc="gcc"
make="make"
windres="windres"
strip="strip"
mingw="no"
pngconfig="libpng-config"
exesuffix=""
libsuffix=".so"
dsound="no"
wave="???"
dinput="no"
oss="no"
evdev="no"
zlib="yes"
png="no"
jpeg="no"
sdl="yes"
client="yes"
ref_soft="yes"
ref_gl="yes"
mod_ui="yes"
server="no"
openffa="no"
help="no"
targets=""
executables=""
libraries=""
hardlink="no"
asm="no"
gldriver="libGL.so"
indriver=""
homedir=".q2pro"
defcfg="/etc/default/q2pro"
asmflags=""
logfile="console.log"
cfgfile="config.cfg"
defcfg="default.cfg"
autocfg="autoexec.cfg"
revision="163"
tmpc="/tmp/q2pro-${RANDOM}.c"
tmpo="/tmp/q2pro-${RANDOM}.o"

if [ -z "$CFLAGS" ]; then
    CFLAGS="-O2"
fi

# detect host CPU
cpu=`uname -m`
case $cpu in
i386|i486|i586|i686)
cpu="i386"
asm="yes"
;;
ia64)
cpu="ia64"
;;
x86_64|amd64)
cpu="x86_64"
;;
*)
cpu="unknown"
;;
esac

# detect host OS
targetos=`uname -s`
case $targetos in
CYGWIN*)
targetos="Windows"
mingw="yes"
sdl="no"
wave="yes"
CFLAGS="-mno-cygwin $CFLAGS"
;;
MINGW*)
targetos="Windows"
mingw="yes"
sdl="no"
wave="yes"
;;
*BSD)
make="gmake"
oss="yes"
;;
Linux)
oss="yes"
evdev="yes"
;;
esac

#parse options
for opt do
    case $opt in
    --help|-h) help="yes"
    ;;
    --sources=*) sources=`echo $opt | cut -d '=' -f 2`
    ;;
    --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
    ;;
    --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
    ;;
    --enable-mingw) mingw="yes" ; sdl="no"
    ;;
    --cc=*) cc=`echo $opt | cut -d '=' -f 2`
    ;;
    --make=*) make=`echo $opt | cut -d '=' -f 2`
    ;;
    --windres=*) windres=`echo $opt | cut -d '=' -f 2`
    ;;
    --strip=*) strip=`echo $opt | cut -d '=' -f 2`
    ;;
    --hardlink) hardlink="yes"
    ;;
    --disable-client) client="no"
    ;;
    --enable-server) server="yes"
    ;;
    --enable-openffa) openffa="yes"
    ;;
    --enable-dsound) dsound="yes"
    ;;
    --enable-dinput) dinput="yes"
    ;;
    --disable-wave) wave="no"
    ;;
    --disable-oss) oss="no"
    ;;
    --disable-zlib) zlib="no"
    ;;
    --enable-png) png="yes"
    ;;
    --enable-jpeg) jpeg="yes"
    ;;
    --disable-asm) asm="no"
    ;;
    *) echo "Unknown option: $opt (try --help)" && exit 1
    ;;
    esac
done

if [ "$help" = "yes" ]; then
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo "  --help                      print this message"
echo "  --prefix=PREFIX             install in PREFIX [$prefix]"
echo "  --cross-prefix=PREFIX       add PREFIX to compile tools [$cross_prefix]"
echo "  --cc=CC                     use C compiler [$cc]"
echo "  --make=MAKE                 use MAKE processor [$make]"
echo "  --windres=WINDRES           use RC compiler [$windres]"
echo "  --hardlink                  build hard linked client"
echo "  --disable-client            do not build client"
echo "  --enable-server             build dedicated server"
echo "  --enable-openffa            build OpenFFA deathmatch mod"
echo "  --enable-mingw              enable Windows build"
echo "  --enable-dsound             enable DirectSound driver"
echo "  --enable-dinput             enable DirectInput driver"
echo "  --disable-wave              disable WAVE sound driver"
echo "  --disable-oss               disable OSS driver"
echo "  --disable-evdev             disable Evdev driver"
echo "  --disable-zlib              disable linking with zlib"
echo "  --enable-png                enable linking with PNG library"
echo "  --enable-jpeg               enable linking with JPEG library"
echo "  --disable-asm               disable i386 assembly optimizations"
echo ""
echo "Object files are built in the directory from which configure is run."
exit 1
fi

if [ "$mingw" = "yes" ]; then
    targetos="Windows"
    pathsep='\\'
    exesuffix=".exe"
    libsuffix=".dll"
    oss="no"
    evdev="no"
    gldriver="opengl32"
    gamelib="gamex86.dll"
    exported="__attribute__((dllexport))"
    homedir=""
    asmflags="-DUNDERSCORES"
    cfgfile="q2config.cfg"
    if [ "$wave" = "???" ]; then
        wave="yes"
    fi
else
    pathsep="/"
    gamelib="game$cpu.so"
    exported="__attribute__((visibility(\"default\")))"

    datadir="$prefix/share/games/quake2"
    libdir="$prefix/lib/games/quake2"
    refdir="$prefix/lib/games/q2pro"
    bindir="$prefix/games"
    mandir="$prefix/share/man/man6"

# check if -fvisibility is supported
    echo "int main(){return 0;}" > $tmpc
    if $cc -o $tmpo -fvisibility\=hidden $tmpc 2>/dev/null ; then
        CFLAGS="-fvisibility=hidden $CFLAGS"
    fi
    rm -f $tmpc $tmpo

    LDFLAGS="-Wl,--no-undefined $LDFLAGS"
fi

if [ ! -z "$cross_prefix" ]; then
    cc="$cross_prefix-$cc"
    windres="$cross_prefix-$windres"
    strip="$cross_prefix-$strip"
    pngconfig="$cross_prefix-$pngconfig"
fi

echo "Build client       $client"
if [ "$client" = "yes" ]; then
    if [ "$hardlink" = "yes" ]; then
        echo "Hard linked        $hardlink"
    else
        echo "Software refresh   $ref_soft"
        echo "OpenGL refresh     $ref_gl"
        echo "Build UI module    $mod_ui"
    fi
fi
echo "Build server       $server"
echo "Build OpenFFA      $openffa"
if [ "$mingw" = "no" ]; then
    echo "Install prefix     $prefix"
    echo "Data directory     $datadir"
    echo "Game libraries     $libdir"
    if [ "$client" = "yes" ]; then
        echo "Refresh libraries  $refdir"
    fi
    echo "Binaries           $bindir"
    echo "Man pages          $mandir"
fi
echo "zlib support       $zlib"
if [ "$client" = "yes" ]; then
    echo "PNG support        $png"
    echo "JPEG support       $jpeg"
    if [ "$mingw" = "yes" ]; then
        echo "DInput support     $dinput"
        echo "DSound support     $dsound"
        echo "WAVE sound support $wave"
    else
        echo "OSS support        $oss"
        echo "Evdev support      $evdev"
    fi
fi
test "$cpu" = "i386" && echo "i386 assembly      $asm"

CFLAGS="-I\$(OUTDIR) -MF \$*.d -MMD -Wall -Wno-missing-braces -Wstrict-prototypes -pipe -ffloat-store -fno-strict-aliasing $CFLAGS"
#LDFLAGS="$LDFLAGS"

config_mk="config.mk"
config_h="config.h"

echo "# Generated by configure - do not modify" > $config_mk
echo "// Generated by configure - do not modify" > $config_h

test "$mingw" = "yes" && echo "MINGW=$mingw" >> $config_mk
echo "CC=$cc" >> $config_mk
echo "WINDRES=$windres" >> $config_mk
echo "STRIP=$strip" >> $config_mk
echo "MAKE=$make" >> $config_mk
echo "SRCDIR=$sources" >> $config_mk
echo "OUTDIR=$outdir" >> $config_mk
echo "EXESUFFIX=$exesuffix" >> $config_mk
echo "LIBSUFFIX=$libsuffix" >> $config_mk
echo "#define LIBSUFFIX \"$libsuffix\"" >> $config_h
echo "VPATH=\$(SRCDIR)/source \$(SRCDIR)/asm" >> $config_mk
echo "CFLAGS=$CFLAGS" >> $config_mk
echo "LDFLAGS=$LDFLAGS" >> $config_mk
test "$mingw" = "yes" && echo "RESFLAGS=-I\$(OUTDIR) -I\$(SRCDIR)/source" >> $config_mk
test "$asm" = "yes" && echo "ASMFLAGS=$asmflags" >> $config_mk

if [ "$client" = "yes" ]; then
    targets="$targets q2pro"
    executables="$executables q2pro$exesuffix"

    if [ "$hardlink" = "no" ]; then
        if [ "$ref_soft" = "yes" ]; then
            targets="$targets ref_soft"
            libraries="$libraries ref_soft$libsuffix"
        fi

        if [ "$ref_gl" = "yes" ]; then
            targets="$targets ref_gl"
            libraries="$libraries ref_gl$libsuffix"
        fi

        if [ "$mod_ui" = "yes" ]; then
            targets="$targets mod_ui"
            libraries="$libraries mod_ui$libsuffix"
        fi
    fi
else
    sdl="no"
fi

if [ "$server" = "yes" ]; then
    targets="$targets q2proded"
    executables="$executables q2proded$exesuffix"
fi

if [ "$openffa" = "yes" ]; then
    targets="$targets openffa"
    libraries="$libraries $gamelib"
fi

echo "TARGETS=$targets" >> $config_mk
echo "BINARIES=$executables $libraries" >> $config_mk
echo "EXECUTABLES=$executables" >> $config_mk
echo "LIBRARIES=$libraries" >> $config_mk

echo "REVISION=$revision" >> $config_mk
echo "#define REVISION $revision" >> $config_h
echo "#define VERSION \"r$revision\"" >> $config_h

if [ "$mingw" = "no" ]; then
    echo "DATADIR=$datadir" >> $config_mk
    echo "#define DATADIR \"$datadir\"" >> $config_h

    echo "LIBDIR=$libdir" >> $config_mk
    echo "#define LIBDIR \"$libdir\"" >> $config_h

    echo "REFDIR=$refdir" >> $config_mk
    echo "#define REFDIR \"$refdir\"" >> $config_h

    echo "BINDIR=$bindir" >> $config_mk
    echo "#define BINDIR \"$bindir\"" >> $config_h

    echo "MANDIR=$mandir" >> $config_mk

    echo "#define HOMEDIR \"$homedir\"" >> $config_h
fi

echo "#define EXPORTED $exported" >> $config_h
echo "#define QDECL" >> $config_h

echo "GAMELIB=$gamelib" >> $config_mk
echo "#define GAMELIB \"$gamelib\"" >> $config_h

echo "#define COM_LOGFILE_NAME \"$logfile\"" >> $config_h
echo "#define COM_CONFIG_NAME \"$cfgfile\"" >> $config_h
echo "#define COM_DEFAULTCFG_NAME \"$defcfg\"" >> $config_h
echo "#define COM_AUTOEXECCFG_NAME \"$autocfg\"" >> $config_h

test "$mingw" = "no" && echo "#define DEFCFG \"$defcfg\"" >> $config_h

echo "#define CPUSTRING \"$cpu\"" >> $config_h
echo "#define BUILDSTRING \"$targetos\"" >> $config_h

echo "#define PATH_SEP_CHAR '$pathsep'" >> $config_h
echo "#define PATH_SEP_STRING \"$pathsep\"" >> $config_h

echo "#define DEFAULT_OPENGL_DRIVER \"$gldriver\"" >> $config_h

echo "#define DEFAULT_INPUT_DRIVER \"$indriver\"" >> $config_h

if [ "$zlib" = "yes" ]; then
    echo "USE_ZLIB=yes" >> $config_mk
    echo "ZLIB_LDFLAGS=-lz" >> $config_mk
    echo "ZLIB_CFLAGS=" >> $config_mk
    echo "#define USE_ZLIB 1" >> $config_h
fi

if [ "$png" = "yes" ]; then
    echo "USE_PNG=yes" >> $config_mk
    echo "PNG_LDFLAGS=$($pngconfig --libs)" >> $config_mk
    echo "PNG_CFLAGS=$($pngconfig --cflags)" >> $config_mk
    echo "#define USE_PNG 1" >> $config_h
fi

if [ "$jpeg" = "yes" ]; then
    echo "USE_JPEG=yes" >> $config_mk
    echo "JPEG_LDFLAGS=-ljpeg" >> $config_mk
    echo "JPEG_CFLAGS=" >> $config_mk
    echo "#define USE_JPEG 1" >> $config_h
fi

if [ "$sdl" = "yes" ]; then
    echo "USE_SDL=yes" >> $config_mk
    echo "SDL_LDFLAGS=`sdl-config --libs`" >> $config_mk
    echo "SDL_CFLAGS=`sdl-config --cflags`" >> $config_mk
    echo "#define USE_SDL 1" >> $config_h
fi

if [ "$oss" = "yes" ]; then
    echo "USE_OSS=yes" >> $config_mk
    echo "#define USE_OSS 1" >> $config_h
fi

if [ "$evdev" = "yes" ]; then
    echo "USE_EVDEV=yes" >> $config_mk
    echo "#define USE_EVDEV 1" >> $config_h
fi

if [ "$wave" = "yes" ]; then
    echo "USE_WAVE=yes" >> $config_mk
    echo "#define USE_WAVE 1" >> $config_h
fi

if [ "$dsound" = "yes" ]; then
    echo "USE_DSOUND=yes" >> $config_mk
    echo "#define USE_DSOUND 1" >> $config_h
fi

if [ "$dinput" = "yes" ]; then
    echo "USE_DINPUT=yes" >> $config_mk
    echo "#define USE_DINPUT 1" >> $config_h
fi

if [ "$asm" = "yes" ]; then
    echo "USE_ASM=yes" >> $config_mk
    echo "#define USE_ASM 1" >> $config_h
fi

echo "#define USE_MAPCHECKSUM 1" >> $config_h

if [ "$hardlink" = "yes" ]; then
    echo "REF_HARD_LINKED=yes" >> $config_mk
    echo "#define REF_HARD_LINKED 1" >> $config_h

    echo "UI_HARD_LINKED=yes" >> $config_mk
    echo "#define UI_HARD_LINKED 1" >> $config_h

    echo "#define OPENGL_RENDERER 1" >> $config_h
    echo "#define TRUECOLOR_RENDERER 1" >> $config_h
    echo "#define DEFAULT_REFRESH_DRIVER \"gl\"" >> $config_h
else
    echo "#define DEFAULT_REFRESH_DRIVER \"soft\"" >> $config_h
fi

for t in $targets ; do
    mkdir -p .$t ;
done