1dnl $Id: configure.ac 1344 2009-06-22 01:11:09Z toni $
2
3dnl Portability note(s):
4dnl * portable tests should use "=" not "=="
5dnl FIXME:
6dnl * Handle --with* with no argument
7
8dnl Modernised AC_INIT since 0.5.0
9dnl   <http://www.gnu.org/software/hello/manual/automake/Public-macros.html>
10AC_INIT(mp3plot, [0.6.0])
11AC_CONFIG_SRCDIR([src/main.cc])
12
13dnl Allow cross-compilation
14dnl Ref: <http://sourceware.org/autobook/autobook/autobook_261.html#SEC261>
15AC_CANONICAL_SYSTEM
16dnl Sets build and build_{cpu,vendor,os}
17dnl Used in Makefile.am to generate the static package name
18dnl Ref: <http://gnu.org/software/autoconf/manual/html_node/Canonicalizing>
19AC_CANONICAL_BUILD
20AC_ARG_PROGRAM
21
22dnl <http://www.gnu.org/software/hello/manual/automake/Options.html#Options>
23dnl Other interesting options: color-tests (unsupported on mine), dist-bzip2
24dnl filename-length-max=99 (automake >= 1.9), check-news
25dnl 1.7 is the minimum automake version supported (on systems with more than
26dnl one version available, use aclocal-VERSION && automake-VERSION to test
27dnl compatibility
28AM_INIT_AUTOMAKE([foreign no-dependencies 1.7])
29
30AC_REVISION(SVN $Rev: 1344 $)
31
32AC_LANG_CPLUSPLUS
33
34AM_CONFIG_HEADER(src/config.h)
35
36AUTHOR="Toni Corvera"
37UPSTREAM_URL=http://p.outlyer.net/mp3plot
38
39AC_DEFINE(DESCRIPTION,"MP3 bitrate plot tool",[Program description])
40AC_DEFINE(COPYRIGHT_YEAR,["2007, 2009"],[Years of development])
41AC_DEFINE_UNQUOTED(AUTHOR,"$AUTHOR",[The author's name])
42AC_DEFINE_UNQUOTED(UPSTREAM_URL, "$UPSTREAM_URL", [Homepage])
43AC_DEFINE(PLOT_SYMBOL,".",[This is the symbol used in the plot 'bar'])
44
45dnl Export to the AC_OUTPUT files, at least mp3plot.spec.in uses these
46AC_SUBST(UPSTREAM_URL)
47AC_SUBST(AUTHOR)
48
49dnl Autotools standard macro reference
50dnl Ref: <http://sourceware.org/autobook/autobook/autobook_283.html>
51
52AC_PROG_INSTALL
53AC_PROG_CXX
54AC_PROG_CXXCPP
55dnl Used in Makefile.am:
56AC_PROG_MAKE_SET
57AC_PROG_LN_S
58AC_PROG_MKDIR_P
59dnl Used for sub-subdirectory linking
60dnl Ref: <http://www.openismus.com/documents/linux/automake/automake.shtml>
61AC_PROG_RANLIB
62
63dnl Probably unneeded
64AC_TYPE_SIZE_T
65
66# Required headers
67AC_CHECK_HEADERS([stdint.h], [], AC_MSG_ERROR([Missing required header]))
68dnl AC_CHECK_HEADERS has the advantage over AC_CHECK_HEADER of defining HAVE_ automatically
69# If no sysexits is found, generate the used constants
70AC_CHECK_HEADERS(sysexits.h)
71# Let's assume the C++ standard library and C compatibility headers are not broken
72#AC_CHECK_HEADERS([algorithm fstream iostream memory ostream sstream string vector map],
73#				[],
74#				AC_MSG_ERROR([Missing STL header])
75#)
76# C++ compatibility headers with C
77#AC_CHECK_HEADERS([cctype cassert], [], AC_MSG_ERROR([Missing C/C++ header]))
78
79###############################################################################
80##
81## Boost
82##
83###############################################################################
84
85dnl Reference:
86dnl http://randspringer.de/boost/ucl-sbs.html
87dnl FIXME: The AX_BOOST_* macros allow disabling boost (--without...) which
88dnl        isn't really desired
89dnl http://autoconf-archive.cryp.to/ax_boost_base.html
90dnl My use of Boost.Thread requires 1.34.1 at least
91AX_BOOST_BASE([1.34.1])
92
93dnl If boost_base is present then shared_ptr should be
94
95dnl http://autoconf-archive.cryp.to/ax_boost_program_options.html
96AX_BOOST_PROGRAM_OPTIONS
97dnl Check manually for appearance
98dnl These are the cached values used in the AX_BOOST_* macros
99if test x$ax_cv_boost_program_options != xyes ; then
100	AC_MSG_ERROR([Boost.Program_Options is a mandatory requirement])
101fi
102
103dnl http://autoconf-archive.cryp.to/ax_boost_thread.html
104AX_BOOST_THREAD
105if test x$ax_cv_boost_thread != xyes ; then
106	AC_MSG_ERROR([Boost.Thread is a mandatory requirement])
107fi
108
109##########################################################
110# Initial values (needed to "pretty-print" config results)
111##########################################################
112
113have_gd="no"
114have_magick="no"
115have_graphics="no"
116
117###############################################################################
118##
119## Graphics Support: GD detection
120##
121## In source, use HAVE_GD to detect its presence
122##
123###############################################################################
124
125dnl Allow disabling gd support (--disable-gd)
126AC_ARG_ENABLE(gd,
127		AC_HELP_STRING([--enable-gd],
128					   [enable support for gdlib (default=yes if found)]
129		)
130)
131
132# If GD is not disabled...
133if test x$enableval != xno ; then
134
135	dnl Allow specifying GD prefix
136	dnl http://www.bioinf.uni-freiburg.de/~mmann/HowTo/automake.html
137	AC_ARG_WITH(gd,
138				AC_HELP_STRING([--with-gd=prefix],
139							   [where to find gd library]),,
140				with_gdpath=no,
141	)
142	dnl FIXME: When no argument is given (--with-gd) it defaults to "yes", which
143	dnl        doesn't make sense for the following block
144
145	dnl Try to use the gdlib-config if the provided prefix, or use
146	dnl a system-wide one if there's none in the prefix
147	dnl TODO: Is it fine to use the system version silently?
148	if test x$with_gdpath != xno ; then
149		extrapath="$with_gd/bin"
150	fi
151	AC_PATH_PROG([GDLIB_CONFIG], [gdlib-config], ,[$extrapath$PATH_SEPARATOR$PATH])
152	extrapath=""
153
154	if ! test -x "$GDLIB_CONFIG" ; then
155		AC_MSG_WARN([gdlib-config not found[,] GD support disabled])
156	else
157		gdlib_CPPFLAGS=`$GDLIB_CONFIG --cflags`
158		gdlib_LDFLAGS=`$GDLIB_CONFIG --ldflags`
159		gdlib_LIBS=`$GDLIB_CONFIG --libs`
160		oldCPPFLAGS="$CPPFLAGS"
161		# Instruct AC_CHECK_HEADERS where to search
162		CPPFLAGS="$CPPFLAGS $gdlib_CPPFLAGS"
163
164		# if more than one header is used on the same AC_CHECK_HEADERS,
165		# the actions ("if-found") are run for each header provided
166		AC_CHECK_HEADERS(gd.h,
167			[
168			 AC_CHECK_HEADER(gdfontl.h,
169				[have_gd=yes],
170			 )
171			],
172		)
173
174		if test x$have_gd = xyes ; then
175		  LDFLAGS="$LDFLAGS $gdlib_LDFLAGS"
176		  LIBS="$LIBS $gdlib_LIBS -lgd" # -lgd!!
177		else
178		  CPPFLAGS="$oldCPPFLAGS"
179		  AC_MSG_WARN([GD not found[,] module disabled])
180		fi
181	fi # GDLIB_CONFIG present
182
183	if test x$have_gd = xyes ; then
184		AC_DEFINE(HAVE_GD,1,[Set to 1 if gdlib is present])
185	fi
186
187fi # gd enabled
188
189###############################################################################
190##
191## Graphics Support: Magick++ detection
192##    note it can be provided by either ImageMagick or GraphicsMagick!
193##
194## In source, use HAVE_MAGICKPP to detect its presence
195##
196###############################################################################
197
198preferred_magick=im # TODO
199
200enableval= # unset
201dnl Allow disabling magick support (--disable-magick)
202AC_ARG_ENABLE(magick,
203		AC_HELP_STRING([--enable-magick],
204					   [enable support for Magick++ (default=yes if found)]
205		)
206)
207
208# If Magick not disabled...
209if test x$enableval != xno ; then
210
211	AC_ARG_WITH(magick,
212				AC_HELP_STRING([--with-magick=prefix],
213							   [where to find Magick++]),,
214				with_magick=no,
215	)
216
217	# TODO: What's the right way to use --with + pkg-config?
218	# Note that Magick++-config might also be provided by GraphicsMagick!
219
220	####################
221	##
222	## GraphicsMagick++
223	##
224	####################
225
226	gm_bypass_pc=no
227	# Let's assume the user is right about the location
228	if test x$with_magick != xno ; then
229		pc_file="$with_magick/lib/pkgconfig/GraphicsMagick.pc"
230		if ! test -e "$pc_file" ; then
231			# Fallback to *-config
232			gm_config="$with_magick/bin/GraphicsMagick++-config"
233			gm_bypass_pc=yes
234			if ! test -x "$gm_config" ; then
235				gm_config=""
236				AC_MSG_NOTICE([GraphicsMagick++ not detected in the supplied path])
237			fi
238		fi
239	else
240		# If no --with-magick is provided ONLY pkg-config will be tested
241		pc_file=
242	fi
243
244	if test $gm_bypass_pc = no ; then
245		# Use pkg-config
246		# Look for package-config...
247		PKG_PROG_PKG_CONFIG
248		AC_MSG_CHECKING([for GraphicsMagick++])
249		PKG_CHECK_EXISTS(GraphicsMagick++,
250			[
251			 AC_MSG_RESULT(yes)
252			 gmCPPFLAGS=`$PKG_CONFIG $pc_file --cflags GraphicsMagick++`
253			 gmLDFLAGS=`$PKG_CONFIG $pc_file --libs-only-L GraphicsMagick++`
254			 gmLIBS=`$PKG_CONFIG $pc_file --libs-only-l GraphicsMagick++`
255			],
256			 AC_MSG_RESULT(no)
257		)
258	else
259		# Don't use package-config...
260		if test -n "$gm_config" ; then
261			gmCPPFLAGS=`"$gm_config" --cppflags`
262			gmLDFLAGS=`"$gm_config" --ldflags`
263			gmLIBS=`"$gm-config" --libs`
264		fi
265	fi
266
267	unset gm_bypass_pc
268	unset gm_config
269	unset pc_file
270
271	#################
272	##
273	## ImageMagick++
274	##
275	#################
276
277	im_bypass_pc=no
278	# Let's assume the user is right about the location
279	if test x$with_magick != xno ; then
280		pc_file="$with_magick/lib/pkgconfig/ImageMagick.pc"
281		if ! test -e "$pc_file" ; then
282			# Fallback to *-config
283			im_config="$with_magick/bin/ImageMagick++-config"
284			im_bypass_pc=yes
285			if ! test -x "$im_config" ; then
286				im_config=""
287				AC_MSG_NOTICE([ImageMagick++ not detected in the supplied path])
288			fi
289		fi
290	else
291		# If no --with-magick is provided ONLY pkg-config will be tested
292		pc_file=
293	fi
294
295	if test $im_bypass_pc = no ; then
296		# Use pkg-config
297		# Look for package-config...
298		PKG_PROG_PKG_CONFIG
299		AC_MSG_CHECKING([for ImageMagick++])
300		PKG_CHECK_EXISTS(ImageMagick++,
301			[
302			 AC_MSG_RESULT(yes)
303			 imCPPFLAGS=`$PKG_CONFIG $pc_file --cflags ImageMagick++`
304			 imLDFLAGS=`$PKG_CONFIG $pc_file --libs-only-L ImageMagick++`
305			 imLIBS=`$PKG_CONFIG $pc_file --libs-only-l ImageMagick++`
306			],
307			 AC_MSG_RESULT(no)
308		)
309	else
310		# Don't use package-config...
311		if test -n "$im_config" ; then
312			imCPPFLAGS=`"$im_config" --cppflags`
313			imLDFLAGS=`"$im_config" --ldflags`
314			imLIBS=`"$im-config" --libs`
315		fi
316	fi
317
318	unset im_bypass_pc
319	unset im_config
320	unset pc_file
321
322	#############
323	##
324	## Selection
325	##
326	#############
327
328	im=""
329	# If both GraphicsMagick++ and ImageMagick++ are present, use the preferred
330	# one
331	if test -n "$gmCPPFLAGS" && test -n "$imCPPFLAGS" ; then
332		if test x$preferred_magick = xim ; then
333			AC_MSG_NOTICE([Both GraphicsMagick++ and ImageMagick++ available, using ImageMagick++])
334			im=im
335		else
336			AC_MSG_NOTICE([Both GraphicsMagick++ and ImageMagick++ available, using GraphicsMagick++])
337			im=gm
338		fi
339	else
340		if test -n "$gmCPPFLAGS" ; then
341			AC_MSG_NOTICE([Magick++ support provided by GraphicsMagick++])
342			im=gm
343		else
344			if test -n "$imCPPFLAGS" ; then
345				AC_MSG_NOTICE([Magick++ support provided by ImageMagick++])
346				im=im
347			fi
348		fi
349	fi
350
351	# Do we have any Magick support at all?
352	if test -n "$im" ; then
353		if test $im = im ; then
354			magick_CPPFLAGS="$imCPPFLAGS"
355			magick_LDFLAGS="$imLDFLAGS"
356			magick_LIBS="$imLIBS"
357			im_flavour_str=", ImageMagick++"
358		else
359			if test $im = gm ; then
360				magick_CPPFLAGS="$gmCPPFLAGS"
361				magick_LDFLAGS="$gmLDFLAGS"
362				magick_LIBS="$gmLIBS"
363				im_flavour_str=", GraphicsMagick++"
364			fi
365		fi
366
367		if test -n "$magick_CPPFLAGS" ; then
368			# Direct AC_CHECK_HEADER to the right include dir...
369			oldCPPFLAGS="$CPPFLAGS"
370			CPPFLAGS="$CPPFLAGS $magick_CPPFLAGS"
371			# ... and check for Magick++.h
372			AC_CHECK_HEADER(Magick++.h,
373				[have_magick=yes
374			 	 LDFLAGS="$LDFLAGS $magick_LDFLAGS"
375				 LIBS="$LIBS $magick_LIBS"
376				 AC_DEFINE(HAVE_MAGICKPP,1,[Set to 1 if Magick++ is available])
377				],
378				[
379				 CPPFLAGS="$oldCPPFLAGS"
380				 AC_MSG_WARN([Magick++.h not found[,] module disabled])
381				]
382			)
383		fi
384	else
385		AC_MSG_WARN([No Magick++ implementation found[,] Magick++ support disabled])
386	fi # MAGICKPP_CONFIG present
387
388fi # magick enabled
389
390###############################################################################
391##
392## Graphics Support: common
393##
394## In source, use HAVE_GRAPHICS_SUPPORT to detect its presence
395##
396###############################################################################
397
398if test x$have_gd = xyes || test x$have_magick = xyes ; then
399	have_graphics="yes"
400	AC_DEFINE(HAVE_GRAPHICS_SUPPORT,1,[Set to 1 if some kind of graphics support is available])
401else
402	AC_MSG_WARN([No graphics support available])
403fi
404
405###############################################################################
406##
407## Debug, aggressively optimised or "final" build?
408##
409###############################################################################
410dnl defines variables bldtype_CPPFLAGS and bldtype_CXXFLAGS
411dnl http://www.bioinf.uni-freiburg.de/~mmann/HowTo/automake.html
412
413enableval=
414AC_MSG_CHECKING([wether this is a final build])
415AC_ARG_ENABLE(debug,
416		AC_HELP_STRING([--enable-debug],
417					   [enable debug support (default=no)]
418		),
419		[]
420)
421enabledbg=$enableval
422if test x$enabledbg = xyes ; then
423	# Debug
424	dnl -Werror + -pedantic is a bit too much even during development
425	dnl -pedantic conlficts with GraphicsMagick++ since it uses long long
426	dnl           (forbidden by C++98), which is a problem in 32 bits
427	dnl           systems at least
428	bldtype_CPPFLAGS="-Wall -UNDEBUG"
429	bldtype_CXXFLAGS="$CXXFLAGS -O0 -g3" # Override any default -O
430	is_final="no"
431	AC_MSG_RESULT(no)
432else
433	# Final
434	bldtype_CPPFLAGS="-DNDEBUG"
435	# If on release, honor any provided CXXFLAGS or fall back to -O2, but
436	# don't force-fed it
437	if test -n "$CXXFLAGS" ; then
438		bldtype_CXXFLAGS="$CXXFLAGS"
439	else
440		bldtype_CXXFLAGS="-O2"
441	fi
442	is_final="yes"
443	AC_MSG_RESULT(yes)
444fi
445CXXFLAGS= # Set below
446
447# Aggressive optimisation, it doesn't make a difference really in this program
448# but I prefer to have it available
449enableval=
450AC_MSG_CHECKING([whether aggressive optimisation should be used])
451AC_ARG_ENABLE(aggressive,
452		AC_HELP_STRING([--enable-aggressive],
453					   [enable aggressive optimisation (default=no)]
454		),
455		[
456		# Aggressive optimisations
457		bldtype_CPPFLAGS="-DNDEBUG"
458		# TODO: Is -mtune=native supported outside x86/x64?
459		bldtype_CXXFLAGS="-O3 -funroll-loops -march=native -mtune=native"
460		AC_MSG_RESULT(yes)
461		]
462)
463if test x$enableval != xyes ; then
464	AC_MSG_RESULT(no)
465fi
466
467# Extra values
468extra_LDFLAGS="-Wl,--as-needed"
469
470CXXFLAGS="$bldtype_CXXFLAGS"
471CPPFLAGS="$bldtype_CPPFLAGS $CPPFLAGS"
472LDFLAGS="$BOOST_LDFLAGS $extra_LDFLAGS $LDFLAGS"
473LIBS="$BOOST_THREAD_LIB $BOOST_PROGRAM_OPTIONS_LIB $LIBS"
474
475cat <<EOF
476
477##############################################################################
478# Config:
479#  Final build:      $is_final
480#  Graphics support: $have_graphics
481#     Magick++:      $have_magick$im_flavour_str
482#     GD:            $have_gd
483# Flags:
484#  CPPFLAGS = $CPPFLAGS
485#  CXXFLAGS = $CXXFLAGS
486#  LDFLAGS  = $LDFLAGS
487#  LIBS     = $LIBS
488#  LDADD    = $LDADD
489#  (Ignored) CFLAGS = $CFLAGS
490##############################################################################
491
492EOF
493
494AC_OUTPUT([Makefile
495	src/Makefile
496	src/mp3/Makefile
497	src/plotters/Makefile
498	src/utils/Makefile
499	freebsd/Makefile
500	mp3plot.spec
501	doxygen.cfg
502])
503
504dnl vim:set ts=4:
505