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