1# Process this file with autoconf to create configure.
2
3AC_PREREQ([2.65])
4
5# ====================
6# Version informations
7# ====================
8m4_define([libwps_version_major],[0])
9m4_define([libwps_version_minor],[3])
10m4_define([libwps_version_micro],[1])
11m4_define([libwps_version],[libwps_version_major.libwps_version_minor.libwps_version_micro])
12
13# =============
14# Automake init
15# =============
16AC_INIT([libwps],[libwps_version])
17AC_CONFIG_MACRO_DIR([m4])
18AC_CONFIG_HEADER([config.h])
19AM_INIT_AUTOMAKE([1.11 foreign dist-xz dist-bzip2])
20AM_SILENT_RULES([yes])
21AC_LANG([C++])
22
23# ===========================
24# Find required base packages
25# ===========================
26m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
27AC_PROG_CC
28AC_PROG_CPP
29AC_PROG_CXX
30AC_PROG_INSTALL
31AC_PROG_LN_S
32AC_PROG_MAKE_SET
33LT_INIT([win32-dll disable-static pic-only])
34AC_CANONICAL_HOST
35
36PKG_PROG_PKG_CONFIG([0.20])
37
38# =================================
39# Libtool/Version Makefile settings
40# =================================
41AC_SUBST(WPS_MAJOR_VERSION, [libwps_version_major])
42AC_SUBST(WPS_MINOR_VERSION, [libwps_version_minor])
43AC_SUBST(WPS_MICRO_VERSION, [libwps_version_micro])
44AC_SUBST(WPS_VERSION, [libwps_version])
45# AC_SUBST(LT_RELEASE, [libwps_version_major.libwps_version_minor])
46LT_CURRENT=`expr 100 '*' libwps_version_major + libwps_version_minor`
47# For 1.0.0 comment the first line and uncomment the second
48LT_AGE=0
49AC_SUBST(LT_CURRENT)
50AC_SUBST(LT_REVISION, [libwps_version_micro])
51AC_SUBST(LT_AGE)
52
53# ==========================
54# Platform check for windows
55# ==========================
56AC_MSG_CHECKING([for native Win32])
57AS_CASE([$host],
58	[*-*-mingw*], [
59		native_win32=yes
60		LIBWPS_WIN32_RESOURCE=libwps-win32res.lo
61		LIBWPS_STREAM_WIN32_RESOURCE=libwps-stream-win32res.lo
62		WKS2CSV_WIN32_RESOURCE=wks2csv-win32res.lo
63		WKS2RAW_WIN32_RESOURCE=wks2raw-win32res.lo
64		WKS2TEXT_WIN32_RESOURCE=wks2text-win32res.lo
65		WPS2HTML_WIN32_RESOURCE=wps2html-win32res.lo
66		WPS2RAW_WIN32_RESOURCE=wps2raw-win32res.lo
67		WPS2TEXT_WIN32_RESOURCE=wps2text-win32res.lo
68	], [
69		native_win32=no
70		LIBWPS_WIN32_RESOURCE=
71		LIBWPS_STREAM_WIN32_RESOURCE=
72		WKS2CSV_WIN32_RESOURCE=
73		WKS2RAW_WIN32_RESOURCE=
74		WKS2TEXT_WIN32_RESOURCE=
75		WPS2HTML_WIN32_RESOURCE=
76		WPS2RAW_WIN32_RESOURCE=
77		WPS2TEXT_WIN32_RESOURCE=
78	]
79)
80AM_CONDITIONAL(OS_WIN32, [test "x$native_win32" = "xyes"])
81AC_SUBST(LIBWPS_WIN32_RESOURCE)
82AC_SUBST(LIBWPS_STREAM_WIN32_RESOURCE)
83AC_SUBST(WKS2CSV_WIN32_RESOURCE)
84AC_SUBST(WKS2RAW_WIN32_RESOURCE)
85AC_SUBST(WKS2TEXT_WIN32_RESOURCE)
86AC_SUBST(WPS2HTML_WIN32_RESOURCE)
87AC_SUBST(WPS2RAW_WIN32_RESOURCE)
88AC_SUBST(WPS2TEXT_WIN32_RESOURCE)
89
90AC_MSG_CHECKING([for Win32 platform in general])
91AS_CASE([$host],
92	[*-*-mingw*|*-*-cygwin*], [platform_win32=yes],
93	[platform_win32=no]
94)
95AC_MSG_RESULT([$platform_win32])
96AM_CONDITIONAL([PLATFORM_WIN32], [test "x$platform_win32" = "xyes"])
97
98AS_IF([test "x$platform_win32" == "xyes"],
99    [],
100    [
101        AC_MSG_CHECKING([for -fvisibility=hidden compiler flag])
102        saved_CXXFLAGS="$CXXFLAGS"
103        CXXFLAGS="$CXXFLAGS -fvisibility=hidden"
104        AC_TRY_COMPILE([], [],
105            [
106                AC_MSG_RESULT([yes])
107                CXXFLAGS="$CXXFLAGS -DLIBWPS_VISIBILITY"
108            ],
109            [
110                AC_MSG_RESULT([no])
111                CXXFLAGS="$saved_CXXFLAGS"
112            ]
113        )
114    ]
115)
116
117# =========================
118# Platform check for darwin
119# =========================
120AC_MSG_CHECKING([for Darwin (Mac OS X) platform])
121AS_CASE([$host],
122	[*-*-darwin*], [platform_darwin=yes],
123	[platform_darwin=no]
124)
125AC_MSG_RESULT([$platform_darwin])
126AM_CONDITIONAL(PLATFORM_DARWIN, [test "x$platform_darwin" = "xyes"])
127
128# ================
129# Check for cflags
130# ================
131AC_ARG_ENABLE([werror],
132	[AS_HELP_STRING([--disable-werror], [Treat all warnings as errors, usefull for development])],
133	[enable_werror="$enableval"],
134	[enable_werror=yes]
135)
136AS_IF([test x"$enable_werror" != "xno"], [
137	CFLAGS="$CFLAGS -Werror"
138	CXXFLAGS="$CXXFLAGS -Werror"
139])
140AC_ARG_ENABLE([weffc],
141	[AS_HELP_STRING([--disable-weffc], [ Disable -Weffc++ warnings, usefull when using an old version of gcc or of boost])],
142	[enable_weffc="$enableval"],
143	[enable_weffc=yes]
144)
145AC_ARG_ENABLE([wparanoic],
146	[AS_HELP_STRING([--enable-wparanoic], [Enable a lot of warnings...])],
147	[enable_wparanoic="$enableval"],
148	[enable_wparanoic=no]
149)
150# Courtesy of Glib: Ensure MSVC-compatible struct packing convention
151# is used when compiling for Win32 with gcc.
152AS_IF([test "x$native_win32" = "xyes"], [
153	AC_CHECK_TOOL(WINDRES, windres)
154	AS_IF([test x"$GCC" = xyes], [
155		AC_MSG_CHECKING([how to get MSVC-compatible struct packing])
156		AS_IF([test -z "$ac_cv_prog_CC"], [
157			our_gcc="$CC"
158		], [
159			our_gcc="$ac_cv_prog_CC"
160		])
161		AS_IF([$our_gcc -v --help 2>/dev/null | grep ms-bitfields >/dev/null], [
162			msnative_struct="-mms-bitfields"
163			CFLAGS="$CFLAGS $msnative_struct"
164			CXXFLAGS="$CXXFLAGS $msnative_struct"
165			AC_MSG_RESULT([${msnative_struct}])
166		], [
167			AC_MSG_RESULT([no way])
168			AC_MSG_WARN([produced libraries might be incompatible with MSVC-compiled code])
169		])
170	])
171	CFLAGS="$CFLAGS -Wall -Wextra -pedantic"
172	CXXFLAGS="$CXXFLAGS -Wall -Wextra -pedantic"
173], [
174	AS_IF([test x"$GCC" = xyes], [
175		# Be tough with warnings and produce less careless code
176		CFLAGS="$CFLAGS -Wall -Wextra -pedantic"
177		CXXFLAGS="$CXXFLAGS -Wall -Wextra -pedantic -Wshadow -Wunused-variable"
178		AS_IF([test x"$enable_weffc" != "xno"], [
179			CXXFLAGS="$CXXFLAGS -Weffc++"
180		])
181		AS_IF([test x"$enable_wparanoic" != "xno"], [
182			CXXFLAGS="$CXXFLAGS -Wcast-align -Wcast-qual -Wchar-subscripts"
183			CXXFLAGS="$CXXFLAGS -Wcomment -Wconversion -Wdisabled-optimization"
184			CXXFLAGS="$CXXFLAGS -Wfloat-equal -Wformat -Wformat=2"
185			CXXFLAGS="$CXXFLAGS -Wformat-nonliteral -Wformat-security"
186			CXXFLAGS="$CXXFLAGS -Wformat-y2k -Wimport -Winit-self -Winvalid-pch"
187			CXXFLAGS="$CXXFLAGS -Wmissing-braces -Wmissing-field-initializers"
188			CXXFLAGS="$CXXFLAGS -Wmissing-format-attribute -Wmissing-include-dirs"
189			CXXFLAGS="$CXXFLAGS -Wmissing-noreturn -Wpacked -Wparentheses"
190			CXXFLAGS="$CXXFLAGS -Wpointer-arith -Wredundant-decls -Wreturn-type"
191			CXXFLAGS="$CXXFLAGS -Wsequence-point -Wsign-compare -Wstrict-aliasing"
192			CXXFLAGS="$CXXFLAGS -Wstrict-aliasing=2 -Wswitch -Wswitch-default"
193			CXXFLAGS="$CXXFLAGS -Wswitch-enum -Wtrigraphs -Wunknown-pragmas -Wunused"
194			CXXFLAGS="$CXXFLAGS -Wunused-function -Wunused-label -Wunused-parameter"
195			CXXFLAGS="$CXXFLAGS -Wunused-value -Wvariadic-macros"
196			CXXFLAGS="$CXXFLAGS -Wvolatile-register-var -Wwrite-strings"
197		])
198	])
199])
200
201# ============
202# Debug switch
203# ============
204AC_ARG_ENABLE([debug],
205	[AS_HELP_STRING([--enable-debug], [Turn on debugging])],
206	[enable_debug="$enableval"],
207	[enable_debug=no]
208)
209AC_ARG_ENABLE([full-debug],
210	[AS_HELP_STRING([--enable-full-debug], [Turn on debugging and debug files' creation ])],
211	[enable_full_debug="$enableval"],
212	[enable_full_debug=no]
213)
214AS_IF([test "x$enable_full_debug" = "xyes"],
215	[ DEBUG_CXXFLAGS="-DDEBUG -DDEBUG_WITH_FILES -g" ],
216	[ AS_IF([test "x$enable_debug" = "xyes"],
217		[DEBUG_CXXFLAGS="-DDEBUG -g"],
218		[DEBUG_CXXFLAGS="-DNDEBUG"])
219	]
220)
221AC_SUBST(DEBUG_CXXFLAGS)
222
223# ============
224# Static tools
225# ============
226AC_ARG_ENABLE([static-tools],
227	[AS_HELP_STRING([--enable-static-tools], [Link tools (binaries) statically])],
228	[enable_static_tools="$enableval"],
229	[enable_static_tools=no]
230)
231AS_IF([test "x$enable_static_tools" = "xyes"], [
232	enable_static="yes"
233], [
234	AC_DISABLE_STATIC
235])
236AM_CONDITIONAL(STATIC_TOOLS, [test "x$enable_static_tools" = "xyes"])
237
238# ========
239# shared_ptr implementation
240# ========
241AC_ARG_WITH(sharedptr,
242	[AS_HELP_STRING([--with-sharedptr=boost|c++11|tr1],
243		[Use Boost|std::memory|std::tr1::memory for shared ptr implementation])],
244	[with_sharedptr="$withval"],
245	[with_sharedptr=boost]
246)
247AS_CASE([$with_sharedptr],
248	[boost|c++11|tr1], [],
249	[AC_MSG_ERROR([Unknown value of shared_ptr provider: $with_sharedptr])]
250)
251
252AS_IF([test "x$with_sharedptr" = "xc++11"], [
253	AC_MSG_CHECKING([for c++11 shared ptr])
254	AC_COMPILE_IFELSE([
255		AC_LANG_PROGRAM(
256			[[#include <memory>]],
257			[[std::shared_ptr<int> p;]]
258		)
259	], [
260		AC_MSG_RESULT([yes])
261		AC_DEFINE([SHAREDPTR_STD],[1],[Use C++11 implementation of shared_ptr])
262	], [
263		AC_MSG_RESULT([no])
264		AC_MSG_ERROR([Could not find C++11 implementation of shared_ptr])
265	], [
266		[#include <memory>]
267	])
268])
269AS_IF([test "x$with_sharedptr" = "xtr1"], [
270	AC_MSG_CHECKING([for tr1 shared ptr])
271	AC_COMPILE_IFELSE([
272		AC_LANG_PROGRAM(
273			[[#include <tr1/memory>]],
274			[[std::tr1::shared_ptr<int> p;]]
275		)
276	], [
277		AC_MSG_RESULT([yes])
278		AC_DEFINE([SHAREDPTR_TR1],[1],[Use TR1 implementation of shared_ptr])
279	], [
280		AC_MSG_RESULT([no])
281		AC_MSG_ERROR([Could not find TR1 implementation of shared_ptr])
282	], [
283		[#include <tr1/memory>]
284	])
285])
286AS_IF([test "x$with_sharedptr" = "xboost"], [
287	AC_MSG_CHECKING([for boost shared ptr])
288	AC_COMPILE_IFELSE([
289		AC_LANG_PROGRAM(
290			[[#include <boost/shared_ptr.hpp>]],
291			[[boost::shared_ptr<int> p;]]
292		)
293	], [
294		AC_MSG_RESULT([yes])
295		AC_DEFINE([SHAREDPTR_BOOST],[1],[Use Boost implementation of shared_ptr])
296	], [
297		AC_MSG_RESULT([no])
298		AC_MSG_ERROR([Could not find Boost implementation of shared_ptr])
299	])
300])
301
302# =============
303# Documentation
304# =============
305AC_ARG_WITH(docs,
306	[AS_HELP_STRING([--without-docs], [Do not build documentation])],
307	[with_docs="$withval"],
308	[AS_IF([test "x$native_win32" = "xyes"], [with_docs=no], [with_docs=yes])]
309)
310AS_IF([test "x$with_docs" != "xno"], [
311	AC_PATH_PROG(DOXYGEN, [doxygen])
312	AS_IF([test -z "$DOXYGEN"], [
313		AC_MSG_WARN([*** Could not find doxygen in your PATH.])
314		AC_MSG_WARN([*** The documentation will not be built.])
315		build_docs=no
316	], [build_docs=yes])
317], [build_docs=no])
318AM_CONDITIONAL([WITH_LIBWPS_DOCS], [test "x$build_docs" != "xno"])
319
320
321# ====================
322# Find librevenge
323# ====================
324PKG_CHECK_MODULES([REVENGE],[ librevenge-0.0 ])
325AC_SUBST(REVENGE_CFLAGS)
326AC_SUBST(REVENGE_LIBS)
327
328# =====
329# Tools
330# =====
331AC_ARG_ENABLE([tools],
332	[AS_HELP_STRING([--disable-tools], [Build conversion tools])],
333	[enable_tools="$enableval"],
334	[enable_tools=yes]
335)
336AS_IF([test "x$enable_tools" = "xyes"], [
337	PKG_CHECK_MODULES([REVENGE_GENERATORS],[
338		librevenge-generators-0.0
339	])
340	PKG_CHECK_MODULES([REVENGE_STREAM],[
341		librevenge-stream-0.0
342	])
343])
344AC_SUBST([REVENGE_GENERATORS_CFLAGS])
345AC_SUBST([REVENGE_GENERATORS_LIBS])
346AC_SUBST([REVENGE_STREAM_CFLAGS])
347AC_SUBST([REVENGE_STREAM_LIBS])
348AM_CONDITIONAL(BUILD_TOOLS, [test "x$enable_tools" = "xyes"])
349
350# =====================
351# Prepare all .in files
352# =====================
353AC_CONFIG_FILES([
354Makefile
355inc/Makefile
356inc/libwps/Makefile
357src/Makefile
358src/conv/Makefile
359src/conv/html/Makefile
360src/conv/html/wps2html.rc
361src/conv/raw/Makefile
362src/conv/raw/wps2raw.rc
363src/conv/text/Makefile
364src/conv/text/wps2text.rc
365src/conv/wks2csv/Makefile
366src/conv/wks2csv/wks2csv.rc
367src/conv/wks2raw/Makefile
368src/conv/wks2raw/wks2raw.rc
369src/conv/wks2text/Makefile
370src/conv/wks2text/wks2text.rc
371src/lib/Makefile
372src/lib/libwps.rc
373docs/Makefile
374docs/doxygen/Makefile
375build/Makefile
376build/win32/Makefile
377libwps-$WPS_MAJOR_VERSION.$WPS_MINOR_VERSION.pc:libwps.pc.in
378libwps-zip
379])
380AC_OUTPUT
381
382# ==============================================
383# Display final informations about configuration
384# ==============================================
385AC_MSG_NOTICE([
386==============================================================================
387Build configuration:
388	debug:           ${enable_debug}
389	full-debug:      ${enable_full_debug}
390	docs:            ${build_docs}
391	shared_ptr:      ${with_sharedptr}
392	static-tools:    ${enable_static_tools}
393	werror:          ${enable_werror}
394==============================================================================
395])
396