r8826: Make configure generate config.mk files (with the external libraries
[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-2005 Jelmer Vernooij
5 dnl Published under the GPL
6 dnl
7 dnl SMB_MODULE_DEFAULT(name,default_build)
8 dnl
9 dnl SMB_SUBSYSTEM_ENABLE(name,default_build)
10 dnl
11 dnl SMB_SUBSYSTEM(name,init_obj_files,add_obj_files,required_subsystems)
12 dnl
13 dnl SMB_EXT_LIB_ENABLE(name,default_build)
14 dnl
15 dnl SMB_EXT_LIB_FROM_PKGCONFIG(name,pkg-config name)
16 dnl
17 dnl SMB_EXT_LIB(name,libs,cflags,cppflags,ldflags)
18 dnl
19 dnl SMB_LIBRARY_ENABLE(name,default_build)
20 dnl
21 dnl SMB_BINARY_ENABLE(name,default_build)
22 dnl
23 dnl #######################################################
24 dnl ### And now the implementation                      ###
25 dnl #######################################################
26
27 dnl SMB_MODULE_DEFAULT(name,default_build)
28 AC_DEFUN([SMB_MODULE_DEFAULT],
29 [
30         [SMB_MODULE_DEFAULT][$1]="$2"
31 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
32 \$enabled{$1} = \"$2\";"
33 ])
34
35 dnl SMB_SUBSYSTEM_ENABLE(name,default_build)
36 AC_DEFUN([SMB_SUBSYSTEM_ENABLE],
37 [
38         [SMB_SUBSYSTEM_ENABLE_][$1]="$2"
39 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
40 \$enabled{$1} = \"$2\";"
41 ])
42
43 dnl SMB_SUBSYSTEM(name,init_obj_files,add_obj_files,required_subsystems)
44 AC_DEFUN([SMB_SUBSYSTEM],
45 [
46
47         if test -z "$[SMB_SUBSYSTEM_ENABLE_][$1]"; then
48                 [SMB_SUBSYSTEM_ENABLE_][$1]="YES";
49         fi
50
51         if test -z "$[SMB_SUBSYSTEM_NOPROTO_][$1]"; then
52                 [SMB_SUBSYSTEM_NOPROTO_][$1]="NO";
53         fi
54
55 SMB_INFO_SUBSYSTEMS="$SMB_INFO_SUBSYSTEMS
56 ###################################
57 # Start Subsystem $1
58 @<:@SUBSYSTEM::$1@:>@
59 INIT_OBJ_FILES = $2
60 ADD_OBJ_FILES = $3
61 REQUIRED_SUBSYSTEMS = $4
62 ENABLE = YES
63 # End Subsystem $1
64 ###################################
65 "
66 ])
67
68 dnl SMB_EXT_LIB_ENABLE(name,default_build)
69 AC_DEFUN([SMB_EXT_LIB_ENABLE],
70 [
71 [SMB_EXT_LIB_ENABLE_][$1]="$2"
72 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
73 \$enabled{EXT_LIB_$1} = \"$2\";"
74 ])
75
76 dnl SMB_EXT_LIB_FROM_PKGCONFIG(name,pkg-config name)
77 AC_DEFUN([SMB_EXT_LIB_FROM_PKGCONFIG], 
78 [
79         dnl Figure out the correct variables and call SMB_EXT_LIB()
80
81         if test -z "$PKG_CONFIG"; then
82                 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
83         fi
84
85         if test "$PKG_CONFIG" = "no" ; then
86                 echo "*** The pkg-config script could not be found. Make sure it is"
87                 echo "*** in your path, or set the PKG_CONFIG environment variable"
88                 echo "*** to the full path to pkg-config."
89                 echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
90                         SMB_EXT_LIB($1)
91                         SMB_EXT_LIB_ENABLE($1, NO)
92         else
93                 if $PKG_CONFIG --atleast-pkgconfig-version 0.9.0; then
94                         AC_MSG_CHECKING(for $2)
95
96                         if test "$SMB_EXT_LIB_$1"x = "NO"x ; then
97                                 SMB_EXT_LIB_ENABLE($1, NO)
98                                 AC_MSG_RESULT(disabled)         
99                         elif $PKG_CONFIG --exists '$2' ; then
100                                 AC_MSG_RESULT(yes)
101
102
103                                 $1_CFLAGS="`$PKG_CONFIG --cflags '$2'`"
104                         OLD_CFLAGS="$CFLAGS"
105                         CFLAGS="$CFLAGS $$1_CFLAGS"
106                         AC_MSG_CHECKING([that the C compiler can use the $1_CFLAGS])
107                         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
108                                         SMB_EXT_LIB_ENABLE($1, YES)
109                                 AC_MSG_RESULT(yes),
110                                         AC_MSG_RESULT(no),
111                                 CFLAGS="$OLD_CFLAGS"
112                                         AC_MSG_WARN([cannot run when cross-compiling]))
113
114
115                                 SMB_EXT_LIB($1, 
116                                         [`$PKG_CONFIG --libs-only-l '$2'`], 
117                                         [`$PKG_CONFIG --cflags-only-other '$2'`],
118                                         [`$PKG_CONFIG --cflags-only-I '$2'`],
119                                         [`$PKG_CONFIG --libs-only-other '$2'` `$PKG_CONFIG --libs-only-L '$2'`])
120
121                         else
122                                 SMB_EXT_LIB($1)
123                                 SMB_EXT_LIB_ENABLE($1, NO)
124                                 AC_MSG_RESULT(no)
125                                 $PKG_CONFIG --errors-to-stdout --print-errors '$2'
126                         fi
127                 else
128                         echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
129                                 echo "*** See http://www.freedesktop.org/software/pkgconfig"
130                                 SMB_EXT_LIB($1)
131                                 SMB_EXT_LIB_ENABLE($1, NO)
132                 fi
133         fi
134 ])
135
136 dnl SMB_EXT_LIB(name,libs,cflags,cppflags,ldflags)
137 AC_DEFUN([SMB_EXT_LIB],
138 [
139
140 SMB_INFO_EXT_LIBS="$SMB_INFO_EXT_LIBS
141 ###################################
142 # Start Ext Lib $1
143 @<:@EXT_LIB::EXT_LIB_$1@:>@
144 LIBS = $2
145 CFLAGS = $3
146 CPPFLAGS = $4
147 LDFLAGS = $5
148 # End Ext Lib $1
149 ###################################
150 "
151 ])
152
153 dnl SMB_LIBRARY_ENABLE(name,default_build)
154 AC_DEFUN([SMB_LIBRARY_ENABLE],
155 [
156 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
157 \$enabled{$1} = \"$2\";"
158 ])
159
160 dnl SMB_BINARY_ENABLE(name,default_build)
161 AC_DEFUN([SMB_BINARY_ENABLE],
162 [
163         [SMB_BINARY_ENABLE_][$1]="$2";
164
165 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
166 \$enabled{$1} = \"$2\";"
167 ])