summaryrefslogtreecommitdiff
path: root/configure
blob: ad24495e41624fb4edab43d12ed636bae404547e (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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
#!/bin/sh

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

# build directories
sources=$(dirname $0)
if [ "$sources" = "." ]; then
    sources=`pwd`
fi

if [ ! -f $sources/source/common.c ] ; then
    echo "ERROR: $sources does not look like Q2PRO source tree"
    exit 1
fi

outdir=`pwd`

# defaults
prefix="/usr/local"
datadir="share/games/quake2"
libdir="lib/games/quake2"
refdir="lib/games/q2pro"
bindir="games"
mandir="share/man/man6"
cross_prefix=""
cc="gcc"
make="make"
windres="windres"
strip="strip"
mingw="no"
pngconfig="libpng-config"
sdlconfig="sdl-config"
exesuffix=""
libsuffix=".so"
dsound="no"
wave="???"
dinput="no"
oss="no"
evdev="no"
zlib="yes"
png="no"
jpeg="no"
sdl="yes"
dl="no"
x11="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"
anticheat="no"
singleuser="no"
gldriver="libGL.so.1"
indriver=""
homedir="~/.q2pro"
defcfg="/etc/default/q2pro"
asmflags=""
logfile="console.log"
cfgfile="config.cfg"
defcfg="default.cfg"
autocfg="autoexec.cfg"
histfile=".conhistory"
democache=".democache"
screenshots="screenshots"
scoreshots="scoreshots"
revision="226"
tmpc="/tmp/q2pro-${RANDOM}.c"
tmpo="/tmp/q2pro-${RANDOM}.o"
config_mk="config.mk"
config_h="config.h"

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

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

# detect host OS
targetos=`uname -s`
case $targetos in
CYGWIN*)
mingw="yes"
CFLAGS="-mno-cygwin $CFLAGS"
;;
MINGW*)
mingw="yes"
;;
*BSD)
make="gmake"
oss="yes"
;;
Linux)
oss="yes"
evdev="yes"
dl="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"
    ;;
    --enable-anticheat) anticheat="yes"
    ;;
    --single-user) singleuser="yes"
    ;;
    --datadir=*) datadir=`echo $opt | cut -d '=' -f 2`
    ;;
    --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
    ;;
    --refdir=*) refdir=`echo $opt | cut -d '=' -f 2`
    ;;
    --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
    ;;
    --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
    ;;
    --homedir=*) homedir=`echo $opt | cut -d '=' -f 2`
    ;;
    *) 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 "  --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             link client with ref_gl and mod_ui"
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 "  --enable-anticheat     enable r1ch.net anticheat server interface"
echo "  --single-user          assume to be installed in home dir"
echo "  --prefix=PREFIX        install in PREFIX [$prefix]"
echo "  --datadir=DIR          game data tree [$datadir]"
echo "  --libdir=DIR           game libraries tree [$libdir]"
echo "  --refdir=DIR           refresh libraries directory [$refdir]"
echo "  --bindir=DIR           executables directory [$bindir]"
echo "  --mandir=DIR           manpages directory [$mandir]"
echo "  --homedir=DIR          home directory [$homedir]"
echo ""
echo "Object files are built in the directory from which configure is run."
exit 1
fi

if [ "$mingw" = "yes" ]; then
    if [ "$cpu" = "i386" ]; then
        cpu="x86"
        targetos="Win32"
    else
        targetos="Win64"
    fi
    pathsep='\\'
    exesuffix=".exe"
    libsuffix=".dll"
    oss="no"
    evdev="no"
    sdl="no"
    gldriver="opengl32"
    exported="__attribute__((dllexport))"
    homedir=""
    asmflags="-DUNDERSCORES"
    cfgfile="q2config.cfg"
    if [ "$wave" != "no" ]; then
        wave="yes"
    fi
else
    pathsep="/"
    exported="__attribute__((visibility(\"default\")))"

    if [ "$singleuser" = "yes" ]; then
        prefix=""
        datadir="."
        libdir="."
        refdir="."
        bindir=""
        mandir=""
        homedir=""
    else
        if [ ! -z "$prefix" ]; then
            datadir="$prefix/$datadir"
            libdir="$prefix/$libdir"
            refdir="$prefix/$refdir"
            bindir="$prefix/$bindir"
            mandir="$prefix/$mandir"
        fi
    fi

# 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

gamelib="game$cpu.so"

vpath="\$(SRCDIR)/source"
if [ "$client" = "yes" ]; then
    vpath="$vpath \$(SRCDIR)/asm"
fi

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

# echo configuration info
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
    if [ "$singleuser" = "yes" ]; then
        echo "Single user        $singleuser"
    else
        echo "Data directory     $datadir"
        echo "Game libraries     $libdir"
        if [ "$client" = "yes" ]; then
            echo "Refresh libraries  $refdir"
        fi
        echo "Binaries           $bindir"
        echo "Man pages          $mandir"
        echo "Home directory     $homedir"
    fi
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 -pipe $CFLAGS -Wno-strict-aliasing"
#LDFLAGS="$LDFLAGS"


# determine what needs to be built
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


# build configuration files
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=$vpath" >> $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

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 "#define HOMEDIR \"$homedir\"" >> $config_h

    if [ "$singleuser" = "yes" ]; then
        echo "SINGLEUSER=$singleuser" >> $config_mk
    else
        echo "BINDIR=$bindir" >> $config_mk
        echo "MANDIR=$mandir" >> $config_mk
    fi
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
echo "#define COM_HISTORYFILE_NAME \"$histfile\"" >> $config_h
echo "#define COM_DEMOCACHE_NAME \"$democache\"" >> $config_h
echo "#define SCREENSHOTS_DIRECTORY \"$screenshots\"" >> $config_h
echo "#define SCORESHOTS_DIRECTORY \"$scoreshots\"" >> $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 [ "$dl" = "yes" ]; then
    echo "USE_DL=yes" >> $config_mk
fi

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=$($sdlconfig --libs)" >> $config_mk
    echo "SDL_CFLAGS=$($sdlconfig --cflags)" >> $config_mk
    echo "#define USE_SDL 1" >> $config_h
    if [ "$x11" = "yes" ]; then
        echo "USE_X11=yes" >> $config_mk
        echo "X11_LDFLAGS=-lX11" >> $config_mk
        echo "X11_CFLAGS=" >> $config_mk
        echo "#define USE_X11 1" >> $config_h
    fi
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

if [ "$anticheat" = "yes" ]; then
    echo "USE_ANTICHEAT=yes" >> $config_mk
    echo "#define USE_ANTICHEAT 2" >> $config_h
fi

echo "#define USE_MAPCHECKSUM 1" >> $config_h
echo "#define USE_AUTOREPLY 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

echo "#define PRIz \"zu\"" >> $config_h

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