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 "
28
29 SMB_INFO_SUBSYSTEMS="$SMB_INFO_SUBSYSTEMS
30 ###################################
31 # Start Subsystem $1
32 @<:@SUBSYSTEM::$1@:>@
33 OBJ_FILES = \$($1_OBJ_FILES)
34 PRIVATE_DEPENDENCIES = $3
35 CFLAGS = $4
36 ENABLE = YES
37 # End Subsystem $1
38 ###################################
39 "
40 ])
41
42 dnl SMB_LIBRARY(name,obj_files,required_subsystems,version,so_version,cflags,ldflags,pcname)
43 AC_DEFUN([SMB_LIBRARY],
44 [
45 MAKE_SETTINGS="$MAKE_SETTINGS
46 $1_OBJ_FILES = $2
47 $1_CFLAGS = $6
48 $1_LDFLAGS = $7
49 "
50
51 SMB_INFO_LIBRARIES="$SMB_INFO_LIBRARIES
52 ###################################
53 # Start Library $1
54 @<:@LIBRARY::$1@:>@
55 OBJ_FILES = \$($1_OBJ_FILES)
56 PRIVATE_DEPENDENCIES = $3
57 VERSION = $4
58 SO_VERSION = $5 
59 CFLAGS = $6
60 LDFLAGS = \$($1_LDFLAGS)
61 PC_NAME = $8
62 ENABLE = YES
63 # End Library $1
64 ###################################
65 "
66 ])
67
68 dnl SMB_EXT_LIB_FROM_PKGCONFIG(name,pkg-config name,[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
69 AC_DEFUN([SMB_EXT_LIB_FROM_PKGCONFIG], 
70 [
71         dnl Figure out the correct variables and call SMB_EXT_LIB()
72
73         if test -z "$PKG_CONFIG"; then
74                 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
75         fi
76
77         if test "$PKG_CONFIG" = "no" ; then
78                 echo "*** The pkg-config script could not be found. Make sure it is"
79                 echo "*** in your path, or set the PKG_CONFIG environment variable"
80                 echo "*** to the full path to pkg-config."
81                 echo "*** Or see http://pkg-config.freedesktop.org/ to get pkg-config."
82                         ac_cv_$1_found=no
83         else
84                 if $PKG_CONFIG --atleast-pkgconfig-version 0.9.0; then
85                         AC_MSG_CHECKING(for $2)
86
87                         if $PKG_CONFIG --exists '$2' ; then
88                                 AC_MSG_RESULT(yes)
89
90                                 $1_CFLAGS="`$PKG_CONFIG --cflags '$2'`"
91                                 OLD_CFLAGS="$CFLAGS"
92                                 CFLAGS="$CFLAGS $$1_CFLAGS"
93                                 AC_MSG_CHECKING([that the C compiler can use the $1_CFLAGS])
94                                 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
95                                         SMB_ENABLE($1, YES)
96                                         AC_MSG_RESULT(yes),
97                                         AC_MSG_RESULT(no),
98                                         AC_MSG_WARN([cannot run when cross-compiling]))
99                                 CFLAGS="$OLD_CFLAGS"
100
101                                 SMB_EXT_LIB($1, 
102                                         [`$PKG_CONFIG --libs-only-l '$2'`], 
103                                         [`$PKG_CONFIG --cflags-only-other '$2'`],
104                                         [`$PKG_CONFIG --cflags-only-I '$2'`],
105                                         [`$PKG_CONFIG --libs-only-other '$2'` `$PKG_CONFIG --libs-only-L '$2'`],
106                                         [ $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_INCLUDE_MK(file)
131 AC_DEFUN([SMB_INCLUDE_MK],
132 [
133 SMB_INFO_EXT_LIBS="$SMB_INFO_EXT_LIBS
134 include $1
135 "
136 ])
137
138 dnl SMB_EXT_LIB(name,libs,cflags,cppflags,ldflags,pcname)
139 AC_DEFUN([SMB_EXT_LIB],
140 [
141 MAKE_SETTINGS="$MAKE_SETTINGS
142 $1_LIBS = $2
143 $1_CFLAGS = $3
144 $1_CPPFLAGS = $4
145 $1_LDFLAGS = $5
146 "
147
148 SMB_INFO_EXT_LIBS="$SMB_INFO_EXT_LIBS
149 ###################################
150 # Start Ext Lib $1
151 @<:@EXT_LIB::$1@:>@
152 LIBS = \$($1_LIBS)
153 CFLAGS = $3
154 CPPFLAGS = $4
155 LDFLAGS = \$($1_LDFLAGS)
156 PC_NAME = $6
157 # End Ext Lib $1
158 ###################################
159 "
160 ])
161
162 dnl SMB_ENABLE(name,default_build)
163 AC_DEFUN([SMB_ENABLE],
164 [
165         [SMB_ENABLE_][$1]="$2";
166
167 SMB_INFO_ENABLES="$SMB_INFO_ENABLES
168 \$enabled{$1} = \"$2\";"
169 ])