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