forked from exult/exult
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acinclude.m4
141 lines (117 loc) · 4.24 KB
/
acinclude.m4
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
dnl Check if we have SDL (sdl-config, header and library) version >= 1.2.0
dnl Extra options: --with-sdl-prefix=PATH and --with-sdl={sdl12,sdl2}
dnl Output:
dnl SDL_CFLAGS and SDL_LIBS are set and AC_SUBST-ed
dnl HAVE_SDL_H is AC_DEFINE-d
AC_DEFUN([EXULT_CHECK_SDL],[
exult_backupcppflags="$CPPFLAGS"
exult_backupldflags="$LDFLAGS"
exult_backuplibs="$LIBS"
exult_sdlok=yes
AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], sdl_prefix="$withval", sdl_prefix="")
AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)], sdl_exec_prefix="$withval", sdl_exec_prefix="")
AC_ARG_WITH(sdl, [ --with-sdl=sdl12,sdl2 Select a specific version of SDL to use (optional)], sdl_ver="$withval", sdl_ver="")
dnl First: find sdl-config or sdl2-config
exult_extra_path=$prefix/bin:$prefix/usr/bin
sdl_args=""
if test x$sdl_exec_prefix != x ; then
sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
exult_extra_path=$sdl_exec_prefix/bin
fi
if test x$sdl_prefix != x ; then
sdl_args="$sdl_args --prefix=$sdl_prefix"
exult_extra_path=$sdl_prefix/bin
fi
if test x"$sdl_ver" = xsdl12 ; then
exult_sdl_progs=sdl-config
elif test x"$sdl_ver" = xsdl2 ; then
exult_sdl_progs=sdl2-config
else
dnl NB: This line implies we prefer SDL 1.2 to SDL 2.0
exult_sdl_progs="sdl-config sdl2-config"
fi
AC_PATH_PROGS(SDL_CONFIG, $exult_sdl_progs, no, [$exult_extra_path:$PATH])
if test "$SDL_CONFIG" = "no" ; then
exult_sdlok=no
else
SDL_CFLAGS=`$SDL_CONFIG $sdl_args --cflags`
SDL_LIBS=`$SDL_CONFIG $sdl_args --libs`
sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
sdl_patchlevel=`$SDL_CONFIG $sdl_args --version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
if test $sdl_major_version -eq 1 ; then
sdl_ver=sdl12
else
sdl_ver=sdl2
fi
fi
if test x"$sdl_ver" = xsdl2 ; then
REQ_MAJOR=2
REQ_MINOR=0
REQ_PATCHLEVEL=0
else
REQ_MAJOR=1
REQ_MINOR=2
REQ_PATCHLEVEL=0
fi
REQ_VERSION=$REQ_MAJOR.$REQ_MINOR.$REQ_PATCHLEVEL
AC_MSG_CHECKING([for SDL - version >= $REQ_VERSION])
dnl Second: include "SDL.h"
if test x$exult_sdlok = xyes ; then
CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include "SDL.h"
]],)],sdlh_found=yes,sdlh_found=no)
if test x$sdlh_found = xno; then
exult_sdlok=no
else
AC_DEFINE(HAVE_SDL_H, 1, [Define to 1 if you have the "SDL.h" header file])
fi
fi
dnl Next: version check (cross-compile-friendly idea borrowed from autoconf)
dnl (First check version reported by sdl-config, then confirm
dnl the version in SDL.h matches it)
if test x$exult_sdlok = xyes ; then
if test ! \( \( $sdl_major_version -gt $REQ_MAJOR \) -o \( \( $sdl_major_version -eq $REQ_MAJOR \) -a \( \( $sdl_minor_version -gt $REQ_MINOR \) -o \( \( $sdl_minor_version -eq $REQ_MINOR \) -a \( $sdl_patchlevel -gt $REQ_PATCHLEVEL \) \) \) \) \); then
exult_sdlok="no, version < $REQ_VERSION found"
else
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include "SDL.h"
int main()
{
static int test_array[1-2*!(SDL_MAJOR_VERSION==$sdl_major_version&&SDL_MINOR_VERSION==$sdl_minor_version&&SDL_PATCHLEVEL==$sdl_patchlevel)];
test_array[0] = 0;
return 0;
}
]])],,[[exult_sdlok="no, version of SDL.h doesn't match that of sdl-config"]])
fi
fi
dnl Next: try linking
if test "x$exult_sdlok" = xyes; then
LIBS="$LIBS $SDL_LIBS"
AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include "SDL.h"
int main(int argc, char* argv[]) {
SDL_Init(0);
return 0;
}
]])],sdllinkok=yes,sdllinkok=no)
if test x$sdllinkok = xno; then
exult_sdlok=no
fi
fi
AC_MSG_RESULT($exult_sdlok)
LDFLAGS="$exult_backupldflags"
CPPFLAGS="$exult_backupcppflags"
LIBS="$exult_backuplibs"
if test "x$exult_sdlok" = xyes; then
AC_SUBST(SDL_CFLAGS)
AC_SUBST(SDL_LIBS)
ifelse([$1], , :, [$1])
else
ifelse([$2], , :, [$2])
fi
]);