~stanray/xaralx/0.4

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
AC_INIT(wxOil/camelot.cpp)
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(XaraLX, 0.7)

AC_PREFIX_PROGRAM( pkg-config )

# BinReloc sets CFLAGS and CXXFLAGS, so we have to undo this
inCFLAGS=$CFLAGS
inCXXFLAGS=$CXXFLAGS

AM_BINRELOC

CFLAGS=$inCFLAGS
CXXFLAGS=$inCXXFLAGS

# Process command line arguments

AC_ARG_ENABLE(debug,
              AS_HELP_STRING([--enable-debug],
                             [Enable debug information and checks]),
              DebugEnable="$enableval", DebugEnable="no")

AC_ARG_ENABLE(static-exec,
              AS_HELP_STRING([--enable-static-exec],
                             [Enable build of a static executable]),
              StaticEnable="$enableval", StaticEnable="no")

AC_ARG_ENABLE(international,
              AS_HELP_STRING([--disable-international],
                             [Disable building of international resources]),
              InternationalEnable="$enableval", InternationalEnable="yes")

AC_ARG_ENABLE(svnversion,
              AS_HELP_STRING([--disable-svnversion],
                             [Disable svn versioning]),
              SvnVersionEnable="$enableval", SvnVersionEnable="yes")

AC_ARG_ENABLE(xarlib,
              AS_HELP_STRING([--enable-xarlib],
                             [Enable build of the xarlib filter library]),
              XarLibEnable="$enableval", XarLibEnable="no")

# Note that as each filter is a separate package, if you got your code from svn you will need to
# do "autoreconf -f -i" in filters/SVGFilter (and all the others); the tarballs should be OK
AC_ARG_ENABLE(filters,
              AS_HELP_STRING([--enable-filters],
                             [Enable build of the filters]),
              FiltersEnable="$enableval", FiltersEnable="no")

OPT_FLAGS34="-fno-strict-aliasing"
WARN_FLAGS34="-Wstrict-aliasing=2"

# Sort out compile lags
if test "$DebugEnable" = "yes"; then
	DEBUG_FLAGS="-ggdb -D_DEBUG"
	OPT_FLAGS="-O0"
	WARN_FLAGS=""
else
	DEBUG_FLAGS=""
	OPT_FLAGS="-O3"
	WARN_FLAGS=""
fi

# Note mysteriously we still use --enable-debug to control build flags even when static enabled
if test "$StaticEnable" = "yes"; then
	DebugEnable="no"
fi

# Check that AUTOMAKE is new enough
AutomakeVersion=`automake --version | awk '{ if($3 ~ /automake\)/) print $4}'`
AC_MSG_CHECKING([Automake ($AutomakeVersion)])
AutomakeVersion=`echo $AutomakeVersion | $AWK 'BEGIN { FS = "."; } { printf "% d", ($1 * 1000 + $2) * 1000 + $3;}'`
if test "$AutomakeVersion" -lt 1009000; then
	AC_MSG_ERROR([Version 1.9.0 or later of AUTOMAKE is needed])
else
	AC_MSG_RESULT([Version OK])
fi

# Test for GCC and version
GccVersion=0
PrecompileEnable="yes"

AC_PROG_CXX
AC_PROG_INSTALL

AC_MSG_CHECKING([Compiler])
if test $ac_compiler_gnu = "yes"; then
	GccVersion=`$CXX -v 2>&1 | $AWK '{ if ($2 ~ /version/) print $3 }'`
	GccVersion=`echo $GccVersion | $AWK 'BEGIN { FS = "."; } { printf "% d", ($1 * 1000 + $2) * 1000 + $3;}'`

	if test -n "$GccVersion" && test "$GccVersion" -ge 3004000; then
		AC_MSG_RESULT([gcc >= 3.4.0, PreCompiled headers enabled])
		WARN_FLAGS="$WARNFLAGS $WARN_FLAGS34"
		OPT_FLAGS="$OPT_FLAGS $OPT_FLAGS34"
		PrecompileEnable="yes"
	else
		AC_MSG_RESULT([gcc < 3.4.0, PreCompiled headers disabled])
		PrecompileEnable="no"
	fi
else
	AC_MSG_RESULT([non-gcc, PreCompiled headers disabled])
	PrecompileEnable="no"
fi

# Setup our build flags (if not set by user)
if test -z "$CFLAGS"; then
	CFLAGS="-Wall -Wno-unknown-pragmas -g -fexceptions $OPT_FLAGS $WARN_FLAGS $DEBUG_FLAGS"
else
	CFLAGS="-Wall -Wno-unknown-pragmas -g -fexceptions $OPT_FLAGS $WARN_FLAGS $DEBUG_FLAGS $CFLAGS"
fi
if test -z "$CXXFLAGS"; then
	CXXFLAGS="-Wall -Wno-unknown-pragmas -g -fexceptions $OPT_FLAGS $WARN_FLAGS $DEBUG_FLAGS"
else
	CXXFLAGS="-Wall -Wno-unknown-pragmas -g -fexceptions $OPT_FLAGS $WARN_FLAGS $DEBUG_FLAGS $CXXFLAGS"
fi

# Set language - this should be taken from a configure option
# Note this MUST be in ISO8859-1 form

# Stop automake directly including stuff
XRCINCLUDE=include

# Disable generation of shared libtool libraries - that's libXar. Note this has NOTHING to
# do with static-exec (the executables)
# We don't need dlopen right now and it's not supported on Darwin
# AC_LIBTOOL_DLOPEN
AC_PROG_RANLIB

AC_C_BIGENDIAN
AC_CHECK_SIZEOF(void*)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(__int64)


WXCONFIG=wx-config
AC_ARG_WITH(wx-config,
[[  --with-wx-config=FILE   Use the given path to wx-config when determining
                            wxWidgets configuration; defaults to "wx-config"]],
[
    if test "$withval" != "yes" -a "$withval" != ""; then
        WXCONFIG=$withval
    fi
])

XARALANGUAGE=EN
AC_ARG_WITH(language,
[[  --with-language=LANG    Use ISO8859-1 country code LANG for resource
                            language; defaults to "EN"]],
[
    if test "$withval" != "yes" -a "$withval" != ""; then
        XARALANGUAGE=$withval
    fi
])

RESOURCE_DIR_DEFINE=
AC_ARG_WITH(resource-dir,
[[  --with-resource-dir=DIR The absoulte path to root of resource directory
                            structure; defaults to using binreloc before 
                            falling back to /usr/share/xaralx]],
[
    if test "$withval" != "yes" -a "$withval" != ""; then
        RESOURCE_DIR_DEFINE="-DRESOURCE_DIR=\\\"$withval\\\""
    fi
])

wxversion=0

AC_DEFUN([WXTEST],
[
	AC_REQUIRE([AC_PROG_AWK])
	AC_MSG_CHECKING([wxWidgets version])
	if wxversion=`$WXCONFIG --version`; then
		AC_MSG_RESULT([$wxversion])
	else
		AC_MSG_RESULT([not found])
		AC_MSG_ERROR([wxWidgets is required. Try --with-wx-config.])
	fi])

# Call WXTEST func
WXTEST

GTK_CFLAGS=""
GTK_LIBS=""

HAVE_WXRC="no"
WXRC=""
# Verify minimus requires
vers=`echo $wxversion | $AWK 'BEGIN { FS = "."; } { printf "% d", ($1 * 1000 + $2) * 1000 + $3;}'`
if test -n "$vers" && test "$vers" -ge 2006003; then
	WX_CPPFLAGS="`$WXCONFIG --static=$StaticEnable --debug=$DebugEnable --unicode=yes --cppflags`"
	WX_CXXFLAGS="`$WXCONFIG --static=$StaticEnable --debug=$DebugEnable --unicode=yes --cxxflags | sed -e 's/-fno-exceptions//'`"
	WX_LIBS="`$WXCONFIG --static=$StaticEnable --debug=$DebugEnable --unicode=yes --libs std`"
	WX_LIBS2="`echo $WX_LIBS | sed -e 's/-pthread//g'`"

	# See if we are running on GTK
	WX_GTK="no"
	AC_MSG_CHECKING([wxWidgets GTK usage])
	if echo $WX_CPPFLAGS | grep -q '__WXGTK__' ; then 
		WX_GTK="yes"
		AC_MSG_RESULT([found])
		PKG_CHECK_MODULES(GTK, [gtk+-2.0])
	else
		AC_MSG_RESULT([not found])
	fi

	if test "$InternationalEnable" = "yes"; then
		AC_MSG_CHECKING([wxWidgets wxrc utility])
		WXRC="`$WXCONFIG --utility=wxrc`"
	
		if test "$WXRC" = "" ; then
			AC_MSG_RESULT([not found, disabling international build])
			HAVE_WXRC="no"
			InternationalEnable="no"
		else
			HAVE_WXRC="yes"
			AC_MSG_RESULT([found])
		fi
	fi

else
	AC_MSG_ERROR([wxWidgets 2.6.3 or newer is required])
fi

# Test for libxml2
XML2CONFIG=xml2-config
AC_ARG_WITH(xml2-config,
[[  --with-xml2-config=FILE Use the given path to xml2-config when determining
                            libxml2 configuration; defaults to "xml2-config"]],
[
    if test "$withval" != "yes" -a "$withval" != ""; then
        XML2CONFIG=$withval
    fi
])
 
xml2version=0

AC_DEFUN([XML2TEST],
[
	AC_REQUIRE([AC_PROG_AWK])
	AC_MSG_CHECKING([libxml2 version])
	if xml2version=`$XML2CONFIG --version`; then
		AC_MSG_RESULT([$xml2version])
	else
		AC_MSG_RESULT([not found])
		AC_MSG_ERROR([libxml2 is required. Try --with-xml2-config.])
	fi
])

# Call XML2TEST func
XML2TEST

# check libxml2 version
xml2version=`echo $xml2version | $AWK 'BEGIN { FS = "."; } { printf "% d", ($1 * 1000 + $2) * 1000 + $3;}'`
if test -z "$xml2version" || test "$xml2version" -lt 2006000; then
	AC_MSG_ERROR([libxml2 2.6 or newer is required])
fi

LIBXML2_CFLAGS="`$XML2CONFIG --cflags`"
LIBXML2_LIBS="`$XML2CONFIG --libs`"

# Define FTCONFIG
FTCONFIG=freetype-config
AC_ARG_WITH(freetype-config,
[[  --with-freetype-config=FILE   Use the given path to freetype-config when determining
                                  freetype configuration; defaults to "freetype-config"]],
[
    if test "$withval" != "yes" -a "$withval" != ""; then
        FTCONFIG=$withval
    fi
])

ftversion=0

# In wxGTK builds we need Pango and FreeType for font rendering
AC_DEFUN([FTTEST],
[
	AC_MSG_CHECKING([freetype version])
	if ftversion=`$FTCONFIG --version`; then
		AC_MSG_RESULT([$ftversion])
	else
		AC_MSG_RESULT([not found])
		AC_MSG_ERROR([freetype is required. Try --with-freetype-config.])
	fi])

if test $WX_GTK = "yes"; then
	# GTK build, so call FTTEST function to test for FreeType
	FTTEST
	FT_CFLAGS="`$FTCONFIG --cflags`"

	# check for the Pango package
	PkgError="no"
	PKG_CHECK_MODULES(PANGOX, pangox,
			  [
				PANGO_CFLAGS="$PANGOX_CFLAGS"
			  ],
			  [
				PkgError="yes"
			  ]
			  )
	if test PkgError = "yes"; then
		AC_MSG_ERROR([pangox library not found])
	fi
else
	# non-GTK build, i.e., MacOS, so Pango and FreeType are not required
	FT_CFLAGS=""
	PANGO_CFLAGS=""
fi

TOPDIR=$srcdir;
if test `echo $srcdir | cut -c1` != "/"; then
	TOPDIR="../$srcdir";
fi

if test "$StaticEnable" = "yes"; then
	CPPFLAGS="$CPPFLAGS -static -static-libgcc"
	CXXFLAGS="$CXXFLAGS -static -static-libgcc"
	if test "$PrecompileEnable" = "yes"; then
		CPPFLAGS="$CPPFLAGS -ffunction-sections -fdata-sections"
		CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections"
		WX_LIBS="$WX_LIBS --gc-sections"
	fi

	# Force as much as possible to be statically linked
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lXrandr/-Wl,-Bstatic -lXrandr -Wl,-Bdynamic/g'`"
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lXext/-Wl,-Bstatic -lXext -Wl,-Bdynamic/g'`"
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lXinerama/-Wl,-Bstatic -lXinerama -Wl,-Bdynamic/g'`"
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lXxf86vm/-Wl,-Bstatic -lXxf86vm -Wl,-Bdynamic/g'`"	
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lXrender/-Wl,-Bstatic -lXrender -Wl,-Bdynamic/g'`"	
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lXfixes/-Wl,-Bstatic -lXfixes -Wl,-Bdynamic/g'`"	
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lexpat/-Wl,-Bstatic -lexpat -Wl,-Bdynamic/g'`"
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-ljpeg/-Wl,-Bstatic -ljpeg -Wl,-Bdynamic/g'`"
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lpng/-Wl,-Bstatic -lpng -Wl,-Bdynamic/g'`"
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-ltiff/-Wl,-Bstatic -ltiff -Wl,-Bdynamic/g'`"
	# These are handled by explicitly linking xml2 (see below)
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lxml2//g'`"
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lz//g'`"
	WX_LIBS="`echo $WX_LIBS | sed -e 's/-lm//g'`"
	WX_LIBS2="`echo $WX_LIBS | sed -e 's/-pthread//g'`"
	# libxml2 linking needs fix-up too
	LIBXML2_LIBS="`echo $LIBXML2_LIBS | sed -e 's/-lxml2/-Wl,-Bstatic -lxml2 -Wl,-Bdynamic/g'`"
	LIBXML2_LIBS="`echo $LIBXML2_LIBS | sed -e 's/-lz/-Wl,-Bstatic -lz -Wl,-Bdynamic/g'`"
	LIBXML2_LIBS="`echo $LIBXML2_LIBS | sed -e 's/-lm/-Wl,-Bstatic -lm -Wl,-Bdynamic/g'`"
fi

# pass the Pango, FreeType and GTK flags (required for wxGTK font rendering)
CPPFLAGS="$CPPFLAGS $WX_CPPFLAGS $PANGO_CFLAGS $FT_CFLAGS $GTK_CFLAGS $LIBXML2_CFLAGS $RESOURCE_DIR_DEFINE"
CXXFLAGS="$CXXFLAGS $WX_CPPFLAGS $PANGO_CFLAGS $FT_CFLAGS $GTK_CFLAGS $LIBXML2_CFLAGS $RESOURCE_DIR_DEFINE"

AC_MSG_CHECKING([Linker])
case $host in
    *-*-darwin*)
		AC_MSG_RESULT([Darwin ld])
        DarwinLink="yes";;
    *)
		AC_MSG_RESULT([GNU ld])
        DarwinLink="no";;
esac

CDRAW_LIB_DIR=""
AC_MSG_CHECKING([CDraw location])
case $target in
    *-*-darwin*)
	AC_MSG_RESULT([libs/darwin])
	CDRAW_LIB_DIR="libs/darwin";;
    i?86-*)
	AC_MSG_RESULT([libs/x86])
	CDRAW_LIB_DIR="libs/x86";;
    amd64-* | x86_64-*)
	AC_MSG_RESULT([libs/x86_64])
	CDRAW_LIB_DIR="libs/x86_64";;
    powerpc-*)
        AC_MSG_RESULT([libs/ppc])
        CDRAW_LIB_DIR="libs/ppc";;
    *)
	AC_MSG_ERROR([Architecture $target not supported])
esac

PODIR=""
BUILDRESFLAGS=""
if test "$InternationalEnable" = "yes" ; then
# These two macros must be left aligned in order for autoreconf to
# find them.
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.14.3])
	PODIR=po
	BUILDRESFLAGS="-i $BUILDRESFLAGS"
fi

if test "$SvnVersionEnable" = "yes" ; then
	BUILDRESFLAGS="-s $BUILDRESFLAGS"
fi

# Force XarLibEnable on if we are to build the filters
if test "$FiltersEnable" = "yes"; then
	XarLibEnable="yes"
	# ensure the filters have a local XarLib
	export LOCAL_XARLIB_OVERRIDE=yes
	# Add each filter below here
	AC_CONFIG_SUBDIRS([filters/SVGFilter])
fi

# Do not pass CXXFLAGS, CFLAGS in. This sets up CXXLINK which breaks XARLIB compilation. Instead set
XARALXCXXFLAGS="$CXXFLAGS"
XARALXCPPFLAGS="$CPPFLAGS"
CXXFLAGS=""
CPPFLAGS=""


AM_CONDITIONAL(PRECOMPILE_ENABLE, [test "$PrecompileEnable" = "yes"])
AM_CONDITIONAL(STATIC_ENABLE, [test "$StaticEnable" = "yes"])
AM_CONDITIONAL(DARWIN_LINK, [test "$DarwinLink" = "yes"])
AM_CONDITIONAL(INTERNATIONAL_ENABLE, [test "$InternationalEnable" = "yes"])
AM_CONDITIONAL(SVNVERSION_ENABLE, [test "$SvnVersionEnable" = "yes"])
AM_CONDITIONAL(XARLIB_ENABLE, [test "$XarLibEnable" = "yes"])
AM_CONDITIONAL(FILTERS_ENABLE, [test "$FiltersEnable" = "yes"])

AC_SUBST(XARALXCXXFLAGS)
AC_SUBST(XARALXCPPFLAGS)
AC_SUBST(TOPDIR)
AC_SUBST(WX_LIBS)
AC_SUBST(WX_LIBS2)
AC_SUBST(XRCINCLUDE)
AC_SUBST(XARALANGUAGE)
AC_SUBST(WXRC)
AC_SUBST(VERSION)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
AC_SUBST(CDRAW_LIB_DIR)
AC_SUBST(LIBXML2_LIBS)
AC_SUBST(PODIR)
AC_SUBST(BUILDRESFLAGS)

AC_OUTPUT(Makefile PreComp/Makefile Kernel/Makefile wxOil/Makefile tools/Makefile wxXtra/Makefile xarlib/Makefile xarlib/Xar.pc po/Makefile.in)