2a6b4e38934d2bf23a17c315a4a6f07c6a8b24bc
[sfrench/samba-autobuild/.git] / source / build / m4 / public.m4
1 dnl SMB Build System
2 dnl ----------------
3 dnl Copyright (C) 2004 Stefan Metzmacher
4 dnl Copyright (C) 2004 Jelmer Vernooij
5 dnl Published under the GPL
6 dnl
7 dnl SMB_MODULE_DEFAULT(
8 dnl             1:name,
9 dnl             2:default_build
10 dnl             )
11 dnl
12 dnl SMB_SUBSYSTEM_ENABLE(
13 dnl             1:name,
14 dnl             2:default_build
15 dnl             )
16 dnl
17 dnl SMB_SUBSYSTEM(
18 dnl             1:name,
19 dnl             2:init_obj_files,
20 dnl             3:add_obj_files,
21 dnl             4:required_libraries,
22 dnl             5:required_subsystems
23 dnl             )
24 dnl
25 dnl SMB_EXT_LIB_ENABLE(
26 dnl             1:name,
27 dnl             2:default_build
28 dnl             )
29 dnl
30 dnl SMB_EXT_LIB_FROM_PKGCONFIG(
31 dnl             1:name,
32 dnl             2:pkg-config name
33 dnl             )
34 dnl
35 dnl SMB_EXT_LIB(
36 dnl             1:name,
37 dnl             2:libs,
38 dnl             3:cflags,
39 dnl             4:cppflags,
40 dnl             5:ldflags
41 dnl             )
42 dnl
43 dnl SMB_LIBRARY_ENABLE(
44 dnl             1:name,
45 dnl             2:default_build
46 dnl             )
47 dnl
48 dnl SMB_BINARY_ENABLE(
49 dnl             1:name,
50 dnl             2:default_build
51 dnl             )
52 dnl
53 dnl SMB_MAKE_TARGET(
54 dnl             1:name
55 dnl             2:calledname
56 dnl             )
57 dnl
58 dnl SMB_ENV_CHECK(
59 dnl             1:dummy
60 dnl             )
61 dnl
62 dnl SMB_AC_OUTPUT(
63 dnl             1: outputfile
64 dnl             )
65
66 dnl #######################################################
67 dnl ### And now the implementation                      ###
68 dnl #######################################################
69
70 AC_DEFUN([STR2ARRAY], [@<:@ input::str2array(\"$1\") @:>@])
71
72
73 dnl SMB_MODULE_DEFAULT(
74 dnl             1:name,
75 dnl             2:default_build
76 dnl             )
77 AC_DEFUN([SMB_MODULE_DEFAULT],
78 [
79         [SMB_MODULE_DEFAULT][$1]="$2"
80 SMB_INFO_MODULES="$SMB_INFO_MODULES
81 \$INPUT{$1}{DEFAULT_BUILD} = \"$2\";"
82 ])
83
84 dnl SMB_SUBSYSTEM_ENABLE(
85 dnl             1:name,
86 dnl             2:default_build
87 dnl             )
88 AC_DEFUN([SMB_SUBSYSTEM_ENABLE],
89 [
90         [SMB_SUBSYSTEM_ENABLE_][$1]="$2"
91 SMB_INFO_SUBSYSTEMS="$SMB_INFO_SUBSYSTEMS
92 \$INPUT{$1}{ENABLE} = \"$2\";"
93 ])
94
95 dnl SMB_SUBSYSTEM(
96 dnl             1:name,
97 dnl             2:init_obj_files,
98 dnl             3:add_obj_files,
99 dnl             4:required_libs,
100 dnl             5:required_subsystems
101 dnl             )
102 AC_DEFUN([SMB_SUBSYSTEM],
103 [
104
105         if test -z "$[SMB_SUBSYSTEM_ENABLE_][$1]"; then
106                 [SMB_SUBSYSTEM_ENABLE_][$1]="YES";
107         fi
108
109         if test -z "$[SMB_SUBSYSTEM_NOPROTO_][$1]"; then
110                 [SMB_SUBSYSTEM_NOPROTO_][$1]="NO";
111         fi
112
113 SMB_INFO_SUBSYSTEMS="$SMB_INFO_SUBSYSTEMS
114 ###################################
115 # Start Subsystem $1
116 \$INPUT{$1} = {
117         TYPE => \"SUBSYSTEM\",
118         NAME => \"$1\",
119         INIT_OBJ_FILES => ][STR2ARRAY([$2])][,
120         ADD_OBJ_FILES => ][STR2ARRAY([$3])][,
121         REQUIRED_LIBRARIES => ][STR2ARRAY([$4])][,
122         REQUIRED_SUBSYSTEMS => ][STR2ARRAY([$5])][,
123         ENABLE => \"YES\"
124 };
125 # End Subsystem $1
126 ###################################
127 "
128 ])
129
130 dnl SMB_EXT_LIB_ENABLE(
131 dnl             1:name,
132 dnl             2:default_build
133 dnl             )
134 AC_DEFUN([SMB_EXT_LIB_ENABLE],
135 [
136 [SMB_EXT_LIB_ENABLE_][$1]="$2"
137 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
138 \$INPUT{EXT_LIB_$1}{ENABLE} = \"$2\";"
139 ])
140
141 dnl SMB_EXT_LIB_FROM_PKGCONFIG(
142 dnl             1:name,
143 dnl             2:pkg-config name
144 dnl )
145 AC_DEFUN([SMB_EXT_LIB_FROM_PKGCONFIG], 
146 [
147         dnl Figure out the correct variables and call SMB_EXT_LIB()
148
149         if test -z "$PKG_CONFIG"; then
150                 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
151         fi
152
153         if test "$PKG_CONFIG" = "no" ; then
154                 echo "*** The pkg-config script could not be found. Make sure it is"
155                 echo "*** in your path, or set the PKG_CONFIG environment variable"
156                 echo "*** to the full path to pkg-config."
157                 echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
158                         SMB_EXT_LIB($1)
159                         SMB_EXT_LIB_ENABLE($1, NO)
160         else
161                 if $PKG_CONFIG --atleast-pkgconfig-version 0.9.0; then
162                         AC_MSG_CHECKING(for $2)
163
164                         if test "$SMB_EXT_LIB_$1"x = "NO"x ; then
165                                 SMB_EXT_LIB_ENABLE($1, NO)
166                                 AC_MSG_RESULT(disabled)         
167                         elif $PKG_CONFIG --exists '$2' ; then
168                                 AC_MSG_RESULT(yes)
169
170
171                                 $1_CFLAGS="`$PKG_CONFIG --cflags '$2'`"
172                         OLD_CFLAGS="$CFLAGS"
173                         CFLAGS="$CFLAGS $$1_CFLAGS"
174                         AC_MSG_CHECKING([that the C compiler can use the $1_CFLAGS])
175                         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
176                                         SMB_EXT_LIB_ENABLE($1, YES)
177                                 AC_MSG_RESULT(yes),
178                                         AC_MSG_RESULT(no),
179                                 CFLAGS="$OLD_CFLAGS"
180                                         AC_MSG_WARN([cannot run when cross-compiling]))
181
182
183                                 SMB_EXT_LIB($1, 
184                                         [`$PKG_CONFIG --libs-only-l '$2'`], 
185                                         [`$PKG_CONFIG --cflags-only-other '$2'`],
186                                         [`$PKG_CONFIG --cflags-only-I '$2'`],
187                                         [`$PKG_CONFIG --libs-only-other '$2'` `$PKG_CONFIG --libs-only-L '$2'`])
188
189                         else
190                                 SMB_EXT_LIB($1)
191                                 SMB_EXT_LIB_ENABLE($1, NO)
192                                 AC_MSG_RESULT(no)
193                                 $PKG_CONFIG --errors-to-stdout --print-errors '$2'
194                         fi
195                 else
196                         echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
197                                 echo "*** See http://www.freedesktop.org/software/pkgconfig"
198                                 SMB_EXT_LIB($1)
199                                 SMB_EXT_LIB_ENABLE($1, NO)
200                 fi
201         fi
202 ])
203
204 dnl SMB_EXT_LIB(
205 dnl             1:name,
206 dnl             2:libs,
207 dnl             3:cflags,
208 dnl             4:cppflags,
209 dnl             5:ldflags
210 dnl             )
211 AC_DEFUN([SMB_EXT_LIB],
212 [
213
214 SMB_INFO_EXT_LIBS="$SMB_INFO_EXT_LIBS
215 ###################################
216 # Start Ext Lib $1
217 \$INPUT{EXT_LIB_$1} = {
218         TYPE => \"EXT_LIB\",
219         NAME => \"EXT_LIB_$1\",
220         LIBS => ][STR2ARRAY([$2])][,
221         CFLAGS => ][STR2ARRAY([$3])][,
222         CPPFLAGS => ][STR2ARRAY([$4])][,
223         LDFLAGS => ][STR2ARRAY([$5])][
224 };
225 # End Ext Lib $1
226 ###################################
227 "
228 ])
229
230
231 dnl SMB_LIBRARY_ENABLE(
232 dnl             1:name,
233 dnl             2:default_build
234 dnl             )
235 AC_DEFUN([SMB_LIBRARY_ENABLE],
236 [
237 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
238 \$INPUT{$1}{ENABLE} = \"$2\";"
239 ])
240
241 dnl SMB_BINARY_ENABLE(
242 dnl             1:name,
243 dnl             2:default_build
244 dnl             )
245 AC_DEFUN([SMB_BINARY_ENABLE],
246 [
247         [SMB_BINARY_ENABLE_][$1]="$2";
248
249 SMB_INFO_BINARIES="$SMB_INFO_BINARIES
250 \$INPUT{$1}{ENABLE} = \"$2\";"
251 ])
252
253 dnl SMB_MAKE_TARGET(
254 dnl             1:name
255 dnl             2:calledname
256 dnl             )
257 AC_DEFUN([SMB_MAKE_TARGET],
258 [
259         echo "#SMB_MAKE_TARGET TOTO"
260 ])
261
262 dnl SMB_ENV_CHECK(
263 dnl             1:dummy
264 dnl             )
265 AC_DEFUN([SMB_ENV_CHECK],
266 [
267         _SMB_BUILD_ENV($1)
268 ])
269
270 dnl SMB_AC_OUTPUT(
271 dnl             1: outputfile
272 dnl             )
273 AC_DEFUN([SMB_AC_OUTPUT],
274 [
275         AC_OUTPUT([$1],[],[_SMB_BUILD_CORE([[$1][.in]])])
276 ])