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