ff03b188efed38436042325a5c28e38fb0223ad4
[udpgate.git] / configure.ac
1 # $Id$
2 # Source file to generate "./configure" to prepare package for compilation
3 # Copyright (C) 2004 Jan Kratochvil <project-udpgate@jankratochvil.net>
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; exactly version 2 of June 1991 is required
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19 AC_INIT(src/main.c)
20 dnl 2.53 for AM_GLIB_GNU_GETTEXT:
21 AC_PREREQ(2.53)
22 dnl Not yet present in: Red Hat autoconf-2.57-3
23 dnl AC_CONFIG_MACRO_DIR(macros)
24 AM_INIT_AUTOMAKE(udpgate,1.0cvs)
25 AM_CONFIG_HEADER(config.h)
26 AM_MAINTAINER_MODE
27 dnl Prevent "AC_TRY_COMPILE was called before AC_ISC_POSIX":
28 AC_ISC_POSIX
29 AM_DISABLE_STATIC
30 AM_ENABLE_SHARED
31 AM_PROG_LIBTOOL
32
33 dnl Workaround for autoconf-2.57:
34 m4_pattern_allow([AC_MSG_WARN])
35 m4_pattern_allow([AC_CHECK_LIB])
36 m4_pattern_allow([AC_CHECK_HEADERS])
37
38 dnl gettext localization.
39 dnl Use simpler AM_GLIB_GNU_GETTEXT instead of AM_GNU_GETTEXT
40 dnl as we depend on glib and glib requires system installed gettext anyway.
41 dnl http://lists.gnome.org/archives/gtk-devel-list/2003-April/msg00066.html
42 dnl Special 'GETTEXT_PACKAGE' is required by glib gettext.
43 ALL_LINGUAS="cs"
44 GETTEXT_PACKAGE="$PACKAGE"
45 AC_SUBST(GETTEXT_PACKAGE)
46 AM_GLIB_GNU_GETTEXT
47
48 dnl Do not discard 'CFLAGS' settings as they may have been passed us by rpmbuild(8)
49
50 dnl Define MAINTAINER_MODE in config.h.
51 if test "$USE_MAINTAINER_MODE" = "yes";then
52         AC_DEFINE(MAINTAINER_MODE,,[Turn even some software behaviour according to MAINTAINER_MODE.])
53         CFLAGS="$CFLAGS -ggdb3 -Wall -Wstrict-prototypes -Wsign-compare"
54         fi
55 dnl Some Makefiles use additional tests etc.
56 AM_CONDITIONAL(MAINTAINER_MODE,[test "$USE_MAINTAINER_MODE" = "yes"])
57
58
59 AC_ARG_ENABLE(man-pages,
60                 [  --enable-man-pages=no/yes/auto   pod2man(1) required for man pages (def.=yes)],,enable_man_pages=yes)
61 AC_ARG_ENABLE(bundle,
62                 [  --enable-bundle                  Build single binary containing locale and init.d files (def.=no)],,enable_bundle=no)
63
64
65 PERL=
66 AC_PATH_PROGS(PERL,perl5 perl)
67 AM_CONDITIONAL(HAVE_PERL,test -n "$PERL")
68
69 AM_CONDITIONAL(ENABLE_BUNDLE,[ test "x$enable_bundle" = "xyes" ])
70 if test "x$enable_bundle" = "xyes"
71 then
72         AC_DEFINE(ENABLE_BUNDLE,,[Build single binary containing locale and init.d files.])
73         if test -f src/bundle.c
74         then
75                 if test -z "$PERL"
76                 then
77                         AC_MSG_WARN([Perl not found (see above). The --enable-bundle files cannot be updated yourself.])
78                 fi
79         else
80                 if test -z "$PERL"
81                 then
82                         AC_MSG_ERROR([Perl not found (see above). --enable-bundle is not possible as src/bundle.c is missing.])
83                 fi
84         fi
85 fi
86
87 POD2MAN=
88 AC_PATH_PROGS(POD2MAN,pod2man)
89 AM_CONDITIONAL(HAVE_POD2MAN,[ test -n "$POD2MAN" ])
90 if test x$enable_man_pages = xyes;then
91         if test -z "$POD2MAN";then
92                 AC_MSG_ERROR([udpgate requires pod2man(1) for man pages; try --disable-man-pages.])
93         fi
94         if test -z "$PERL";then
95                 AC_MSG_ERROR([udpgate requires perl(1) for man pages; try --disable-man-pages.])
96         fi
97 elif test x$enable_man_pages != xno;then
98         if test -z "$POD2MAN";then
99                 AC_MSG_WARN([udpgate requires pod2man(1) for man pages by --enable-man-pages; mans will not be installed.])
100         fi
101         if test -z "$PERL";then
102                 AC_MSG_WARN([udpgate requires perl(1) for man pages by --enable-man-pages; mans will not be installed.])
103         fi
104 fi
105 AM_CONDITIONAL(ENABLE_MAN_PAGES,[ test x$enable_man_pages != xno -a -n "$POD2MAN" -a -n "$PERL" ])
106
107 dnl Separate 'acconfig.h' is no longer recommended by autoconf
108 AH_TOP([
109 #ifndef _UDPGATE_CONFIG_H
110 #define _UDPGATE_CONFIG_H 1
111 ])
112 AH_BOTTOM([
113 /* Do not place any stuff to AH_TOP as some of its includes
114  * would discard the effect of _FILE_OFFSET_BITS by AC_SYS_LARGEFILE.
115  */
116
117 #ifdef ENABLE_NLS
118 /* <libintl.h> is taken from "$(top_srcdir)/intl" if system doesn't provide intl */
119 #       include <libintl.h>
120 #define _(String) gettext (String)
121 #       ifdef gettext_noop
122 #               define N_(String) gettext_noop (String)
123 #       else
124 #               define N_(String) (String)
125 #       endif
126 #else /* !ENABLE_NLS */
127 /* Stubs that do something close enough.  */
128 #       define textdomain(String) (String)
129 #       define gettext(String) (String)
130 #       define dgettext(Domain,Message) (Message)
131 #       define dcgettext(Domain,Message,Type) (Message)
132 #       define bindtextdomain(Domain,Directory) (Domain)
133 #       define _(String) (String)
134 #       define N_(String) (String)
135 #endif /* !ENABLE_NLS */
136
137 #include <glib/gtypes.h>        /* for 'gchar' */
138 #define G_LOG_DOMAIN ((const gchar *)"UDPGate")
139
140 /**
141  * udpgate_newn:
142  * @objp: Variable with the pointer to the objects wished to be allocated.
143  * Original value is discarded.
144  * @n: Numbers of objects to be allocated. Value %0 is permitted (%NULL assignment effect).
145  *
146  * Macro to allocate @n objects of type *@objp and to assign the resulting pointer to @objp.
147  * Allocated memory may contain garbage.
148  *
149  * @Returns: Initialized @objp value as the memory of size #sizeof(typeof(*objp))*n.
150  * Value %NULL is returned iff @n==%0;
151  */
152 #define udpgate_newn(objp,n) ((objp)=g_new(typeof(*(objp)),(n)))
153
154 /**
155  * udpgate_new:
156  * @objp: Variable with the pointer to the object wished to be allocated.
157  * Original value is discarded.
158  *
159  * Macro to allocate one object of type *@objp and to assign the resulting pointer to @objp.
160  * Allocated memory may contain garbage. Equivalent to udpgate_newn(objp,1) call.
161  *
162  * @Returns: Initialized @objp value as the memory of size #sizeof(typeof(*objp)).
163  * Value %NULL is never returned.
164  */
165 #define udpgate_new(objp) (udpgate_newn((objp),1))
166
167 /**
168  * UDPGATE_MEMZERO:
169  * @objp: Pointer to the variable to be cleared.
170  *
171  * Clears the sizeof(*@objp) bytes of the given pointer with memset().
172  * Pass _pointer_ to the object to be cleared.
173  */
174 #define UDPGATE_MEMZERO(objp) (memset((objp),0,sizeof(*(objp))))
175
176 /**
177  * udpgate_printf_alloca:
178  * @format: Format string. See the sprintf() documentation.
179  * @args...: Arguments for @format. See the sprintf() documentation.
180  *
181  * Format the given format string @format as in sprintf().
182  * Output buffer is allocated automatically and it does not need to be deallocated
183  * manually as it is managed by g_alloca().
184  *
185  * @Returns: Formatted output string located in g_alloca() memory.
186  */
187 #include <glib/galloca.h>
188 #include <glib/gutils.h>
189 #define udpgate_printf_alloca(format,args...) ({ \
190                 gsize _udpgate_printf_alloca_size=udpgate_nv_printf_string_upper_bound((format) , ## args); \
191                 gchar *_udpgate_printf_alloca_r=g_alloca(_udpgate_printf_alloca_size); \
192                 g_snprintf(_udpgate_printf_alloca_r,_udpgate_printf_alloca_size,(format) , ## args); \
193                 (const gchar *)_udpgate_printf_alloca_r; \
194                 })
195 #include <stdarg.h>
196 #include <glib/gmessages.h>     /* for g_printf_string_upper_bound() */
197 static inline gsize udpgate_nv_printf_string_upper_bound(const gchar *format,...) G_GNUC_PRINTF(1,0) G_GNUC_UNUSED;
198 static inline gsize udpgate_nv_printf_string_upper_bound(const gchar *format,...)
199 {
200 va_list ap;
201 gsize r;
202
203         va_start(ap,format);
204         r=g_printf_string_upper_bound(format,ap);
205         va_end(ap);
206         return r;
207 }
208
209 #endif /* !_UDPGATE_CONFIG_H */
210 ])
211
212 dnl Do not use PKG_CHECK_MODULES() as it would not set 'GLIB_GENMARSHAL' etc.
213 AM_PATH_GLIB_2_0(,,[AC_MSG_ERROR([UDPGate requires glib-2.0 library.])],[])
214 dnl Force glib for the whole package
215 CFLAGS="$CFLAGS $GLIB_CFLAGS"
216 LIBS="$LIBS $GLIB_LIBS"
217
218 dnl popt
219 AC_CHECK_LIB(popt,poptParseArgvString,[POPT_LIBS="-lpopt"],[AC_MSG_ERROR([UDPGate requires popt library.])])
220 AC_SUBST(POPT_LIBS)
221
222 GLADE_W_INIT([
223         ./src/ui-gnome-interface.c
224         ./src/ui-gnome-interface.h
225         ./src/ui-gnome-callbacks.h
226         ./src/ui-gnome-support.c
227         ./src/ui-gnome-support.h
228         ])
229 AC_SUBST(GNOMEUI_CFLAGS)
230 AC_SUBST(GNOMEUI_LIBS)
231 if $have_gnome
232 then
233         AC_DEFINE(HAVE_GNOME,,[Compile Gnome support.])
234 fi
235 AM_CONDITIONAL(HAVE_GNOME,[ $have_gnome ])
236 AM_CONDITIONAL(HAVE_GLADE_WRITESOURCE,[ test "x$PATH_GLADE" != "x" ])
237 dnl Do not: AM_CONDITIONAL(BUILD_GLADESRC,[ test "xyes" = "x$BUILD_GLADESRC" ])
238 dnl as we do not need it as we are conditioned by ENABLE_INSTALL_PKG
239 GNOME_ADDON_LIBS=""
240 if test "x$BUILD_GLADESRC_TRUE" = "x"
241 then
242         AC_CHECK_LIB(Xi,XOpenDevice,GNOME_ADDON_LIBS="$GNOME_ADDON_LIBS -lXi")
243 fi
244 AC_SUBST(GNOME_ADDON_LIBS)
245
246 AC_SUBST(CFLAGS)
247 AC_SUBST(LIBS)
248
249 dnl "Makefile" output files MUST have pathnames incl./excl. "./" prefix as specified!
250 dnl FIXME: Why the rule above was written here?
251 AC_OUTPUT([
252 udpgate.spec
253 ./src/udpgate.pod.pl
254 ./po/Makefile.in
255 ./macros/glade-w.sh
256 Makefile
257 ./macros/Makefile
258 ./init.d/Makefile
259 ./src/Makefile
260 ])
261
262 dnl FIXME: Why is "po/POTFILES" being substituted?
263 make -C src distfiles DISTFILES_PRINT=1 \
264                 |sed -n 's/^:DISTFILES: *\(.*\)$/\1/p'|tr ' ' '\n'|grep . >po/POTFILES.in
265 make -C po Makefile
266
267 echo done.