aboutsummaryrefslogtreecommitdiffstats
path: root/dists/autogen/m4/fpc.m4
blob: 896c53d22d8357e507d850b4a3b24e81f52b8f5d (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
dnl ** Version 1.1 of file is part of the LGPLed 
dnl **   J Sound System (http://jss.sourceforge.net)
dnl **
dnl ** Checks for Free Pascal Compiler by Matti "ccr/TNSP" Hamalainen
dnl ** (C) Copyright 2000-2001 Tecnic Software productions (TNSP)
dnl **
dnl ** Versions
dnl ** --------
dnl ** 1.0 - Created
dnl **
dnl ** 1.1 - Added stuff to enable unix -> win32
dnl **       cross compilation.
dnl **
dnl ** 1.x - A few fixes (by the UltraStar Deluxe Team)
dnl **

AC_DEFUN([AC_PROG_FPC], [

AC_ARG_VAR(PFLAGS, [Free Pascal Compiler flags (replaces all other flags)])
AC_ARG_VAR(PFLAGS_DEBUG, [Free Pascal Compiler debug flags @<:@-gl -Coi -Xs- -vew -dDEBUG_MODE@:>@])
AC_ARG_VAR(PFLAGS_RELEASE, [Free Pascal Compiler release flags @<:@-O2 -Xs -vew@:>@])
AC_ARG_VAR(PFLAGS_EXTRA, [Free Pascal Compiler additional flags])

dnl set DEBUG/RELEASE flags to default-values if unset

dnl - Do not use -dDEBUG because this will enable range-checks that will fail with USDX.
dnl - Disable -Xs which is defined in fpc.cfg (TODO: is this necessary?).
dnl - For FPC we have to use DEBUG_MODE instead of DEBUG to enable the apps debug-mode 
dnl   because DEBUG enables some additional compiler-flags in fpc.cfg too
PFLAGS_DEBUG=${PFLAGS_DEBUG-"-gl -Xs- -vew -dDEBUG_MODE"}
dnl -dRELEASE works too but we define our own settings
PFLAGS_RELEASE=${PFLAGS_RELEASE-"-O2 -Xs -vew"}


AC_ARG_ENABLE(dummy_fpc1,[
Free Pascal Compiler specific options:])

AC_ARG_WITH(fpc,
  [AS_HELP_STRING([--with-fpc=DIR],
    [Directory of the FPC executable @<:@PATH@:>@])],
  [PPC_PATH=$withval], [])

FPC_DEBUG="no"

AC_ARG_ENABLE(release,
  [AS_HELP_STRING([--enable-release],
    [Enable FPC release options @<:@default=yes@:>@])],
  [test $enableval = "no" && FPC_DEBUG="yes"], [])

AC_ARG_ENABLE(debug,
  [AS_HELP_STRING([--enable-debug],
    [Enable FPC debug options (= --disable-release) @<:@default=no@:>@])],
  [test $enableval = "yes" && FPC_DEBUG="yes"], [])

AC_ARG_ENABLE(profile,
  [AS_HELP_STRING([--enable-profile],
    [Enable FPC profiling options @<:@default=no@:>@])],
  [PFLAGS_EXTRA="$PFLAGS_EXTRA -pg"], [])


dnl ** set PFLAGS depending on whether it is already set by the user
dnl Note: the user's PFLAGS must *follow* this script's flags
dnl   to enable the user to overwrite the settings.
if test x${PFLAGS+assigned} = x; then
dnl PFLAGS not set by the user
	if test x$FPC_DEBUG = xyes; then 
		PFLAGS="$PFLAGS_DEBUG"
		PFLAGS_MAKE="[\$](PFLAGS_DEBUG)"
	else
		PFLAGS="$PFLAGS_RELEASE"
		PFLAGS_MAKE="[\$](PFLAGS_RELEASE)"
	fi
else
dnl PFLAGS set by the user, just add additional flags
	PFLAGS="$PFLAGS"
	PFLAGS_MAKE="$PFLAGS"
fi

dnl ** find compiler executable

PPC_CHECK_PROGS="fpc FPC ppc386 ppc PPC386 ppos2"

if test -z "$PPC_PATH"; then
	PPC_PATH=$PATH
	AC_CHECK_PROGS(PPC, $PPC_CHECK_PROGS)
	AC_CHECK_PROGS(FPCMAKE, [fpcmake])
else
	AC_PATH_PROGS(PPC, $PPC_CHECK_PROGS, [], $PPC_PATH)
	AC_PATH_PROGS(FPCMAKE, [fpcmake], [], $PPC_PATH)
fi
if test -z "$PPC"; then
	AC_MSG_ERROR([no Free Pascal Compiler found in $PPC_PATH])
fi
if test -z "$FPCMAKE"; then
	AC_MSG_ERROR([fpcmake not found in $PPC_PATH])
fi

AC_PROG_FPC_WORKS
AC_PROG_FPC_LINKS

dnl *** Get the FPC version and some paths
FPC_VERSION=`${PPC} -iV`
FPC_PLATFORM=`${PPC} -iTO`
FPC_PROCESSOR=`${PPC} -iTP`

if test "x$prefix" != xNONE; then
	FPC_PREFIX=$prefix
else
	FPC_PREFIX=$ac_default_prefix
fi
FPC_BASE_PATH="${FPC_PREFIX}/lib/fpc/${FPC_VERSION}"
FPC_UNIT_PATH="${FPC_BASE_PATH}/units/${FPC_PLATFORM}"

AC_SUBST(PFLAGS)
AC_SUBST(PFLAGS_MAKE)
AC_SUBST(PFLAGS_EXTRA)
AC_SUBST(PFLAGS_DEBUG)
AC_SUBST(PFLAGS_RELEASE)

AC_SUBST(FPC_VERSION)
AC_SUBST(FPC_PLATFORM)
AC_SUBST(FPC_PROCESSOR)

AC_SUBST(FPC_PREFIX)
AC_SUBST(FPC_BASE_PATH)
AC_SUBST(FPC_UNIT_PATH)
])

PFLAGS_TEST="$PFLAGS $PFLAGS_EXTRA"

dnl ***
dnl *** Check if FPC works and can compile a program
dnl ***
AC_DEFUN([AC_PROG_FPC_WORKS],
[AC_CACHE_CHECK([whether the Free Pascal Compiler ($PPC $PFLAGS_TEST) works], ac_cv_prog_ppc_works,
[
rm -f conftest*
echo "program foo; begin writeln; end." > conftest.pp
${PPC} ${PFLAGS_TEST} conftest.pp >> config.log

if test -f conftest || test -f conftest.exe; then
dnl *** It works!
	ac_cv_prog_ppc_works="yes"

else
	ac_cv_prog_ppc_works="no"
fi
rm -f conftest*
dnl AC_MSG_RESULT($ac_cv_prog_ppc_works)
if test x$ac_cv_prog_ppc_works = xno; then
	AC_MSG_ERROR([installation or configuration problem: Cannot create executables.])
fi
])])


dnl ***
dnl *** Check if FPC can link with standard libraries
dnl ***
AC_DEFUN([AC_PROG_FPC_LINKS],
[AC_CACHE_CHECK([whether the Free Pascal Compiler ($PPC $PFLAGS_TEST) can link], ac_cv_prog_ppc_works,
[
rm -f conftest*
echo "program foo; uses crt; begin writeln; end." > conftest.pp
${PPC} ${PFLAGS_TEST} conftest.pp >> config.log
if test -f conftest || test -f conftest.exe; then
	ac_cv_prog_ppc_links="yes"
else
	ac_cv_prog_ppc_links="no"
fi
rm -f conftest*
AC_MSG_RESULT($ac_cv_prog_ppc_links)
if test x$ac_cv_prog_ppc_links = xno; then
	AC_MSG_ERROR([installation or configuration problem: Cannot link with some standard libraries.])
fi
])])