aboutsummaryrefslogtreecommitdiffstats
path: root/configure.ac
blob: a04d5a6884412780cdd172a238f203b64b90931a (plain) (blame)
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
#
# ultrastardx configure.ac script
#
# by UltraStar Deluxe Team
#
# Execute "autogen.sh" to create the configure script.
#

# Require autoconf >= 2.61
AC_PREREQ(2.61)

# Init autoconf
AC_INIT([ultrastardx], 
        [1.1-alpha], 
        [http://sourceforge.net/tracker/?group_id=191560&atid=937872])
# specify the website here
PACKAGE_WEBSITE="http://www.ultrastardeluxe.org/"
AC_SUBST(PACKAGE_WEBSITE)
# specify the IRC-channel here
PACKAGE_IRC="#ultrastardx at quakenet.org"
AC_SUBST(PACKAGE_IRC)

# Specify a source-file so autoconf can check if the source-dir exists
AC_CONFIG_SRCDIR(src/ultrastardx.dpr)

# Set the path to install-sh
AC_CONFIG_AUX_DIR(dists/autogen)

# show features and packages in one list
AC_PRESERVE_HELP_ORDER

# set sharerootdir to the resolved dataroot-dir for the config-*.inc file.
# Pascal cannot handle shell-variables like ${prefix}
AC_DEFINE_DIR(sharerootdir, datarootdir)

# -----------------------------------------
# find tools
# -----------------------------------------

# options for make command
AC_PROG_MAKE_SET
# find tool for ln -s (e.g. uses cp -p for FAT-filesystems)
AC_LN_S
# find a program for recursive dir creation
AC_PROG_MKDIR_P
# find the best install tool
AC_PROG_INSTALL
# some other useful tools
#AC_PROG_AWK
AC_PROG_SED
AC_PROG_GREP
#AC_PROG_EGREP

# -----------------------------------------
# macro declarations
# -----------------------------------------

# AC_TRIM(STRING)
# removes surrounding whitespace
# -------------------------------------------
AC_DEFUN([AC_TRIM],
[echo "[$1]" | $SED 's/^[[ \t]]*//' | $SED 's/[[ \t]]*$//'
])

# AC_SUBST_DEFINE(DEFINE_SUFFIX, IS_DEFINED)
# used to enable/disable pascal defines
AC_DEFUN([AC_SUBST_DEFINE],
[
    if [[ x$2 = xyes ]]; then
        DEFINE_[$1]=DEFINE
    else
	DEFINE_[$1]=UNDEF
    fi
    AC_SUBST(DEFINE_[$1])
])

# AC_SPLIT_VERSION(VARIABLE_PREFIX, VERSION)
# Splits version number ("major.minor.release") into its components.
# Sets
#   [$VARIABLE_PREFIX]_VERSION_MAJOR
#   [$VARIABLE_PREFIX]_VERSION_MINOR
#   [$VARIABLE_PREFIX]_VERSION_RELEASE
# This function calls
#   AC_SUBST([$VARIABLE_PREFIX]_VERSION_type] for each type
AC_DEFUN([AC_SPLIT_VERSION],
[
    version=[$2]    

    # strip leading non-numeric tokens 
    # (necessary for some ffmpeg-packages in ubuntu)
    # example: 0d.51.1.0 -> 51.1.0
    version=`echo $version | $SED 's/^[[^.]]*[[^0-9.]][[^.]]*\.//'`

    # replace "." and "-" with " " and ignore trailing tokens.
    # 1.23.4-r2 will be splitted to [maj=1, min=23, rel=4].
    # In addition we delete every character which is not 0-9.
    # 1.3a4-r32 will be [maj=1, min=34, rel=32].
    read major minor release ignore <<eof
        `echo $version | tr '.-' ' ' | $SED 's/[[^0-9\ ]].*//'` 
eof
    # Note: Do NOT indent the eof-delimiter
    # We use a here-document (<<< here-strings not POSIX compatible)

    # strip preceding 0s and set unset version-parts to 0
    [$1][_VERSION_MAJOR]=$(($major))
    [$1][_VERSION_MINOR]=$(($minor))
    [$1][_VERSION_RELEASE]=$(($release))
    # integer representation: MMMmmmrrr (M:major,m:minor,r:release)
    # can be used if pkg-config's comparison fails
    [$1][_VERSION_INT]=$(($[$1][_VERSION_MAJOR]*1000000+$[$1][_VERSION_MINOR]*1000+$[$1][_VERSION_RELEASE]))

    AC_SUBST([$1][_VERSION_MAJOR])
    AC_SUBST([$1][_VERSION_MINOR])
    AC_SUBST([$1][_VERSION_RELEASE])
    AC_SUBST([$1][_VERSION_INT])
])

# PKG_VALUE(VARIABLE_PREFIX, POSTFIX, COMMAND, MODULE, HELP-STRING)
# -----------------------------------------------------
AC_DEFUN([PKG_VALUE],
[
    AC_ARG_VAR([$1]_[$2], [$5, overriding pkg-config])   
    # check if variable was defined by the user
    if test -z "$[$1]_[$2]"; then
        # if not, get it from pkg-config
        if test x$[$1][_HAVE] = xyes; then
            PKG_CHECK_EXISTS([$4],
                [[$1]_[$2]=`$PKG_CONFIG --[$3] --silence-errors "$4"`],
                [# print error message and quit
                 err_msg=`$PKG_CONFIG --errors-to-stdout --print-errors "$4"`
                 AC_MSG_ERROR(
[

$err_msg

If --with-[$1]=nocheck is defined the environment variable 
[$1]_[$2]
must be set to avoid the need to call pkg-config.

See the pkg-config man page for more details.
])

                ])
        fi
    fi
    AC_SUBST([$1]_[$2])
])

# PKG_VERSION(VARIABLE_PREFIX, MODULE)
#   Checks version of a package
# Parameters:
# - VARIABLE_PREFIX: the prefix for the variables storing information about the package.
# - MODULE:          package name according to pkg-config
# Sets:
#   [$VARIABLE_PREFIX]_VERSION         # full version string (format: "major.minor.release")
#   [$VARIABLE_PREFIX]_VERSION_MAJOR   # major version number
#   [$VARIABLE_PREFIX]_VERSION_MINOR   # minor version number
#   [$VARIABLE_PREFIX]_VERSION_RELEASE # release version number
#   [$VARIABLE_PREFIX]_VERSION_INT     # integer representation: MMMmmmrrr (M:major,m:minor,r:release)
AC_DEFUN([PKG_VERSION],
[
    if test x$[$1][_HAVE] = xyes; then
        AC_MSG_CHECKING([version of $1])
        PKG_VALUE([$1], [VERSION], [modversion], [$2], [version of $1])   
        AC_MSG_RESULT(@<:@$[$1][_VERSION]@:>@)
    else
        [$1][_VERSION]="0.0.0"
    fi
    AC_SPLIT_VERSION([$1], $[$1][_VERSION])
])

# PKG_HAVE(VARIABLE_PREFIX, MODULE, [REQUIRED])
#   Checks with pkg-config if a package exists and retrieves information 
#   about it.
# Parameters:
# - VARIABLE_PREFIX: the prefix for the variables storing information about the package.
# - MODULE:   package name according to pkg-config
# - REQUIRED: if true, the configure-script is aborted if the package was not found
# Uses:
#   with_[$VARIABLE_PREFIX]: whether and how the package should be checked for
#     "check":   check for the package but do not abort if it does not exist (default)
#     "no":      do not check for the package (sets _HAVE to "no" and _VERSION to "0.0.0")
#     "yes":     check for the package and abort if it does not exist
#     "nocheck": do not check for the package (sets _HAVE to "yes")
# Sets:
#   [$VARIABLE_PREFIX]_HAVE       # package is available (values: "yes"|"no")
#   [$VARIABLE_PREFIX]_LIBS       # linker flags (e.g. -Lmylibdir -lmylib)
#   [$VARIABLE_PREFIX]_LIBDIRS    # library dirs (e.g. -Lmylibdir)
AC_DEFUN([PKG_HAVE],
[
    have_lib="no"
    AC_MSG_CHECKING([for $2])
    if test x"$with_[$1]" = xnocheck; then
        # do not call pkg-config, use user settings
        have_lib="yes"
    elif test x"$with_[$1]" != xno; then
        # check if package exists
	PKG_CHECK_EXISTS([$2], [
            have_lib="yes"
            [$1][_LIBS]=`$PKG_CONFIG --libs --silence-errors "$2"`
            [$1][_LIBDIRS]=`$PKG_CONFIG --libs-only-L --silence-errors "$2"`
            [$1][_LIBDIRS]=`AC_TRIM($[$1][_LIBDIRS])`
            # add library directories to LIBS (ignore *_LIBS for now)
	    if test -n "$[$1][_LIBDIRS]"; then
                LIBS="$LIBS $[$1][_LIBDIRS]"
            fi
        ])
    fi
    if test x$have_lib = xyes; then
        [$1][_HAVE]="yes"
        if test -n "$[$1][_LIBDIRS]"; then
            # show additional lib-dirs
            AC_MSG_RESULT(yes [(]$[$1][_LIBDIRS][)])
        else
            AC_MSG_RESULT(yes)
        fi
    else
        [$1][_HAVE]="no"
        AC_MSG_RESULT(no)

        # check if package is required
        if test x$3 = xyes -o x"$with_[$1]" = xyes ; then
            # print error message and quit
            err_msg=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
            AC_MSG_ERROR(
[

$err_msg

Alternatively, you may set --with-[$1]=nocheck and the environment
variables [$1]_[[...]] (see configure --help) 
to appropriate values to avoid the need to call pkg-config.

See the pkg-config man page for more details.
])
        fi
    fi
])


# -----------------------------------------
# define switches
# -----------------------------------------

# print library options header
AC_ARG_WITH([cfg-dummy1], [
External Libraries:])

# add portmixer option
AC_ARG_WITH([portmixer],
    [AS_HELP_STRING([--with-portmixer],
      [enable portmixer audio-mixer support @<:@default=check@:>@])],
    [with_portmixer=$withval], [with_portmixer="check"])

# add projectM option
AC_ARG_WITH([libprojectM], 
    [AS_HELP_STRING([--with-libprojectM],
      [enable projectM visualization support @<:@default=no@:>@])],
    [with_libprojectM=$withval], [with_libprojectM="no"])

# print misc options header
AC_ARG_WITH([cfg-dummy2], [
Development options:])

LOCAL_BUILD="no"

# add global option
AC_ARG_ENABLE(global,
    [AS_HELP_STRING([--enable-global],
      [install into global folders (PREFIX/...) @<:@default=yes@:>@])],
    [test $enableval = "no" && LOCAL_BUILD="yes"], [])

# add local option
AC_ARG_ENABLE(local,
    [AS_HELP_STRING([--enable-local],
      [install into local folders (./game/...) (same as --disable-global) @<:@default=no@:>@]))],
    [test $enableval = "yes" && LOCAL_BUILD="yes"], [])

# set default Makefile install-target according to local/global build-type
AC_SUBST_DEFINE(USE_LOCAL_DIRS, $LOCAL_BUILD)
if [[ x$LOCAL_BUILD = xyes ]]; then
    AC_SUBST(install_type, ["local"])
else
    AC_SUBST(install_type, ["global"])    
fi


# -----------------------------------------
# check for compilers
# -----------------------------------------

AC_CANONICAL_TARGET

# find and test the freepascal compiler
# sets PFLAGS, FPC_VERSION, FPC_DEBUG, etc.
AC_PROG_FPC
# FPC_VERSION is already defined by FPC, use
# PPC as prefix instead.
AC_SPLIT_VERSION(PPC, $FPC_VERSION)

# find and test the C compiler (for C-libs and wrappers)
AC_PROG_CC
AC_LANG([C])

# find and test the C++ compiler (for C-libs and wrappers)
AC_PROG_CXX
AC_LANG([C++])

AC_PROG_RANLIB

# find pkg-config
PKG_PROG_PKG_CONFIG()
if [[ x$PKG_CONFIG = x ]]; then
   AC_MSG_ERROR([
!!! pkg-config was not found on your system. 
!!! It is needed to determine the versions of your libraries.
!!! Install it and try again.])
fi


# -----------------------------------------
# check for OS
# -----------------------------------------

if [[ x$FPC_PLATFORM = xdarwin ]]; then
   AC_MSG_CHECKING([for Mac OS X version])
   MACOSX_VERSION=`sw_vers -productVersion`
   AC_SPLIT_VERSION(MACOSX, $MACOSX_VERSION)
   AC_MSG_RESULT(@<:@$MACOSX_VERSION@:>@)
fi

# -----------------------------------------
# check for libraries
# -----------------------------------------

# libpng
PKG_HAVE([libpng], [libpng], yes)

# find sdl
PKG_HAVE([sdl], [sdl], yes)

# find sqlite3
PKG_HAVE([sqlite3], [sqlite3], yes)

# find FFMpeg
# Note: do not use the min/max version parameters with ffmpeg
# otherwise it might fail in ubuntu due to a wrong version number 
# format in ffmpeg's .pc-files.
# For example: 0d.51.1.2 instead of the correct 51.1.2.
#   A check for version >=52.0.0 will return version 0d.51.1.2 
#   although it is lower because pkg-config is confused by the 0d.
# Use [mylib]_VERSION_INT for version-checking instead
PKG_HAVE([libavcodec], [libavcodec], yes)
PKG_VERSION([libavcodec], [libavcodec])
AC_CHECK_LIB([avcodec], [avcodec_decode_audio], [HAVE_AVCODEC_DECODE_AUDIO="yes"])
AC_CHECK_LIB([avcodec], [avcodec_decode_audio2], [HAVE_AVCODEC_DECODE_AUDIO2="yes"])
AC_CHECK_LIB([avcodec], [img_convert], [HAVE_IMG_CONVERT="yes"])
PKG_HAVE([libavformat], [libavformat], yes)
PKG_VERSION([libavformat], [libavformat])
PKG_HAVE([libavutil], [libavutil], yes)
PKG_VERSION([libavutil], [libavutil])
if [[ x$libavcodec_HAVE = xyes -a x$libavformat_HAVE = xyes -a x$libavutil_HAVE = xyes ]]; then
    ffmpeg_HAVE=yes
else
    ffmpeg_HAVE=no
fi
AC_SUBST_DEFINE(HAVE_FFMPEG, $ffmpeg_HAVE)

# find FFMpeg's swscale lib (just if FFMpeg is compiled in GPL mode)
PKG_HAVE([libswscale], [libswscale], no)
PKG_VERSION([libswscale], [libswscale])
AC_SUBST_DEFINE(HAVE_SWSCALE, $libswscale_HAVE)


# find projectM version
libprojectM_PKG="libprojectM >= 0.98"
PKG_HAVE([libprojectM], [$libprojectM_PKG], no)
PKG_VERSION([libprojectM], [$libprojectM_PKG])
AC_SUBST_DEFINE(HAVE_PROJECTM, $libprojectM_HAVE)
# get projectM include-dir
PKG_VALUE([libprojectM], [INCLUDEDIR], [variable=includedir], [$libprojectM_PKG], 
          [C-Header include-dir (e.g. /usr/include)])
# get projectM data-dir (for preset- and font-dir)
PKG_VALUE([libprojectM], [DATADIR], [variable=pkgdatadir], [$libprojectM_PKG], 
          [projectM data-directory for presets etc. (e.g. /usr/share/projectM)])
# check if we need the c-wrapper
if [[ "$libprojectM_VERSION_MAJOR" -ge 1 ]]; then
    libprojectM_USE_CWRAPPER=yes
else
    libprojectM_USE_CWRAPPER=no
fi
AC_SUBST(USE_PROJECTM_CWRAPPER, $libprojectM_USE_CWRAPPER)

# find portaudio
PKG_HAVE([portaudio], [portaudio-2.0], yes)
PKG_VERSION([portaudio], [portaudio-2.0])
AC_SUBST_DEFINE(HAVE_PORTAUDIO, $portaudio_HAVE)
# find portmixer
PKG_HAVE([portmixer], [portmixer], no)
AC_SUBST_DEFINE(HAVE_PORTMIXER, $portmixer_HAVE)

# determine linker-flags
#LDFLAGS=
#LIBS=
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)

# -----------------------------------------
# create output files
# -----------------------------------------

AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([src/config-$FPC_PLATFORM.inc:src/config.inc.in])
if [[ x$libprojectM_USE_CWRAPPER = xyes ]]; then
    AC_CONFIG_FILES([src/lib/projectM/cwrapper/Makefile])
fi
AC_CONFIG_FILES([tools/ResourceExtractor/Makefile])
AC_OUTPUT

# -----------------------------------------
# show results
# -----------------------------------------

AC_MSG_NOTICE([

!!!
!!! Configuration of $PACKAGE_NAME $PACKAGE_VERSION done!
!!!
!!! Type "make" to compile and 
!!!      "make install" to install it afterwards.
!!!
!!! For further information on $PACKAGE_NAME visit:
!!!   $PACKAGE_WEBSITE
!!!
!!! IMPORTANT:
!!! This is an UNSUPPORTED ALPHA release for developers only.
!!!
!!! DO NOT EXPECT THE MAKEFILE OR THE PROGRAM ITSELF TO WORK
!!!
!!! If you want to contribute, visit the IRC-Channel instead:
!!!   $PACKAGE_IRC
!!!
!!! PLEASE DO NOT SEND BUGREPORTS FOR THIS VERSION.
!!!
])

# TODO: insert this in the public beta release
#!!! In case you find a bug send a bugreport to:
#!!!   $PACKAGE_BUGREPORT
#!!! You might as well ask for help at the IRC-Channel
#!!!   $PACKAGE_IRC