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