Add --enable-external-* flags for libraries shipped with Samba, to allow
[ira/wip.git] / source4 / build / m4 / public.m4
1 dnl SMB Build System
2 dnl ----------------
3 dnl Copyright (C) 2004 Stefan Metzmacher
4 dnl Copyright (C) 2004-2005 Jelmer Vernooij
5 dnl Published under the GPL
6 dnl
7 dnl SMB_EXT_LIB_FROM_PKGCONFIG(name,pkg-config name,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
8 dnl
9 dnl SMB_INCLUDED_LIB_PKGCONFIG(name,pkg-config name,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
10 dnl
11 dnl SMB_EXT_LIB(name,libs,cflags,cppflags,ldflags)
12 dnl
13 dnl SMB_ENABLE(name,default_build)
14 dnl
15 dnl SMB_INCLUDE_MK(file)
16 dnl
17 dnl SMB_WRITE_MAKEVARS(file)
18 dnl
19 dnl SMB_WRITE_PERLVARS(file)
20 dnl
21 dnl #######################################################
22 dnl ### And now the implementation                      ###
23 dnl #######################################################
24
25 dnl SMB_SUBSYSTEM(name,obj_files,required_subsystems,cflags)
26 AC_DEFUN([SMB_SUBSYSTEM],
27 [
28 MAKE_SETTINGS="$MAKE_SETTINGS
29 $1_CFLAGS = $4
30 $1_ENABLE = YES
31 $1_OBJ_FILES = $2
32 "
33
34 SMB_INFO_SUBSYSTEMS="$SMB_INFO_SUBSYSTEMS
35 ###################################
36 # Start Subsystem $1
37 @<:@SUBSYSTEM::$1@:>@
38 PRIVATE_DEPENDENCIES = $3
39 CFLAGS = \$($1_CFLAGS)
40 ENABLE = YES
41 # End Subsystem $1
42 ###################################
43 "
44 ])
45
46 dnl SMB_LIBRARY(name,obj_files,required_subsystems,cflags,ldflags)
47 AC_DEFUN([SMB_LIBRARY],
48 [
49 MAKE_SETTINGS="$MAKE_SETTINGS
50 $1_CFLAGS = $6
51 $1_LDFLAGS = $7
52 n1_ENABLE = YES
53 $1_OBJ_FILES = $2
54 "
55
56 SMB_INFO_LIBRARIES="$SMB_INFO_LIBRARIES
57 ###################################
58 # Start Library $1
59 @<:@LIBRARY::$1@:>@
60 PRIVATE_DEPENDENCIES = $3
61 CFLAGS = \$($1_CFLAGS)
62 LDFLAGS = \$($1_LDFLAGS)
63 ENABLE = YES
64 # End Library $1
65 ###################################
66 "
67 ])
68
69 dnl SMB_EXT_LIB_FROM_PKGCONFIG(name,pkg-config name,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
70 AC_DEFUN([SMB_EXT_LIB_FROM_PKGCONFIG], 
71 [
72         dnl Figure out the correct variables and call SMB_EXT_LIB()
73
74         if test -z "$PKG_CONFIG"; then
75                 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
76         fi
77
78         if test "$PKG_CONFIG" = "no" ; then
79                 echo "*** The pkg-config script could not be found. Make sure it is"
80                 echo "*** in your path, or set the PKG_CONFIG environment variable"
81                 echo "*** to the full path to pkg-config."
82                 echo "*** Or see http://pkg-config.freedesktop.org/ to get pkg-config."
83                         ac_cv_$1_found=no
84         else
85                 if $PKG_CONFIG --atleast-pkgconfig-version 0.9.0; then
86                         AC_MSG_CHECKING(for $2)
87
88                         if $PKG_CONFIG --exists '$2' ; then
89                                 AC_MSG_RESULT(yes)
90
91                                 $1_CFLAGS="`$PKG_CONFIG --cflags '$2'`"
92                                 OLD_CFLAGS="$CFLAGS"
93                                 CFLAGS="$CFLAGS $$1_CFLAGS"
94                                 AC_MSG_CHECKING([that the C compiler can use the $1_CFLAGS])
95                                 AC_TRY_RUN([#include "${srcdir-.}/../tests/trivial.c"],
96                                         SMB_ENABLE($1, YES)
97                                         AC_MSG_RESULT(yes),
98                                         AC_MSG_RESULT(no),
99                                         AC_MSG_WARN([cannot run when cross-compiling]))
100                                 CFLAGS="$OLD_CFLAGS"
101
102                                 SMB_EXT_LIB($1, 
103                                         [`$PKG_CONFIG --libs-only-l '$2'`], 
104                                         [`$PKG_CONFIG --cflags-only-other '$2'`],
105                                         [`$PKG_CONFIG --cflags-only-I '$2'`],
106                                         [`$PKG_CONFIG --libs-only-other '$2'` `$PKG_CONFIG --libs-only-L '$2'`])
107                                 ac_cv_$1_found=yes
108
109                         else
110                                 AC_MSG_RESULT(no)
111                                 $PKG_CONFIG --errors-to-stdout --print-errors '$2'
112                                 ac_cv_$1_found=no
113                         fi
114                 else
115                         echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
116                         echo "*** See http://pkg-config.freedesktop.org/"
117                         ac_cv_$1_found=no
118                 fi
119         fi
120         if test x$ac_cv_$1_found = x"yes"; then
121                 ifelse([$3], [], [echo -n ""], [$3])
122         else
123                 ifelse([$4], [], [
124                           SMB_EXT_LIB($1)
125                           SMB_ENABLE($1, NO)
126                 ], [$4])
127         fi
128 ])
129
130 dnl SMB_INCLUDED_LIB_PKGCONFIG(name,pkg-config name,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
131 AC_DEFUN([SMB_INCLUDED_LIB_PKGCONFIG],
132 [
133         AC_ARG_ENABLE([external-]translit($1,`A-Z',`a-z'),
134                 AS_HELP_STRING([--enable-external-]translit($1,`A-Z',`a-z'), [Use external $1 instead of built-in (default=auto)]), [], [enableval=auto])
135
136         if test $enableval = yes -o $enableval = auto; then
137                 SMB_EXT_LIB_FROM_PKGCONFIG([$1], [$2], [$3], [
138                         if test $enableval = yes; then
139                                 AC_MSG_ERROR([Unable to find external $1])
140                         fi
141                 ])
142         else
143                 ifelse([$4], [], [
144                           SMB_EXT_LIB($1)
145                           SMB_ENABLE($1, NO)
146                 ], [$4])
147         fi
148 ])
149
150 dnl SMB_INCLUDE_MK(file)
151 AC_DEFUN([SMB_INCLUDE_MK],
152 [
153 SMB_INFO_EXT_LIBS="$SMB_INFO_EXT_LIBS
154 mkinclude $1
155 "
156 ])
157
158 dnl SMB_EXT_LIB(name,libs,cflags,cppflags,ldflags)
159 AC_DEFUN([SMB_EXT_LIB],
160 [
161 MAKE_SETTINGS="$MAKE_SETTINGS
162 $1_LIBS = $2
163 $1_CFLAGS = $3
164 $1_CPPFLAGS = $4
165 $1_LDFLAGS = $5
166 "
167
168 ])
169
170 dnl SMB_ENABLE(name,default_build)
171 AC_DEFUN([SMB_ENABLE],
172 [
173         MAKE_SETTINGS="$MAKE_SETTINGS
174 $1_ENABLE = $2
175 "
176 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
177 \$enabled{$1} = \"$2\";"
178 ])
179
180 dnl SMB_MAKE_SETTINGS(text)
181 AC_DEFUN([SMB_MAKE_SETTINGS],
182 [
183 MAKE_SETTINGS="$MAKE_SETTINGS
184 $1
185 "
186 ])
187
188 dnl SMB_WRITE_MAKEVARS(path, skip_vars)
189 AC_DEFUN([SMB_WRITE_MAKEVARS],
190 [
191 echo "configure: creating $1"
192 cat >$1<<CEOF
193 # $1 - Autogenerated by configure, DO NOT EDIT!
194 $MAKE_SETTINGS
195 CEOF
196 skip_vars=" $2 "
197 for ac_var in $ac_subst_vars
198 do
199     eval ac_val=\$$ac_var
200         if echo "$skip_vars" | grep -v " $ac_var " >/dev/null 2>/dev/null; then
201                 echo "$ac_var = $ac_val" >> $1
202         fi
203 done
204 ])
205
206 dnl SMB_WRITE_PERLVARS(path)
207 AC_DEFUN([SMB_WRITE_PERLVARS],
208 [
209 echo "configure: creating $1"
210 cat >$1<<CEOF
211 # config.pm - Autogenerate by configure. DO NOT EDIT!
212
213 package config;
214 require Exporter;
215 @ISA = qw(Exporter);
216 @EXPORT_OK = qw(%enabled %config);
217 use strict;
218
219 use vars qw(%enabled %config);
220
221 %config = (
222 CEOF
223
224 for ac_var in $ac_subst_vars
225 do
226         eval ac_val=\$$ac_var
227         # quote ' (\x27) inside '...' and make sure \ isn't eaten by shells, so use perl:
228         QAC_VAL=$ac_val QAC_VAR=$ac_var perl -e '$myval="$ENV{QAC_VAL}"; $myval =~ s/\x27/\\\x27/g ; print $ENV{QAC_VAR}." => \x27$myval\x27,\n"' >> $1
229 done
230
231 cat >>$1<<CEOF
232 );
233 $SMB_INFO_ENABLES
234 1;
235 CEOF
236 ])
237
238 dnl SMB_BUILD_RUN(OUTPUT_FILE)
239 AC_DEFUN([SMB_BUILD_RUN],
240 [
241 AC_OUTPUT_COMMANDS(
242 [
243 test "x$ac_abs_srcdir" != "x$ac_abs_builddir" && (
244         cd $builddir;
245         # NOTE: We *must* use -R so we don't follow symlinks (at least on BSD
246         # systems).
247         test -d heimdal || cp -R $srcdir/heimdal $builddir/
248         test -d heimdal_build || cp -R $srcdir/heimdal_build $builddir/
249         test -d build || builddir="$builddir" \
250                         srcdir="$srcdir" \
251                         $PERL ${srcdir}/script/buildtree.pl
252  )
253
254 $PERL -I${builddir} -I${builddir}/build \
255     -I${srcdir} -I${srcdir}/build \
256     ${srcdir}/build/smb_build/main.pl --output=$1 main.mk || exit $?
257 ],
258 [
259 srcdir="$srcdir"
260 builddir="$builddir"
261 PERL="$PERL"
262
263 export PERL
264 export srcdir
265 export builddir
266 ])
267 ])