9e82e6aaf199e7c7e2e47d8dae1aa83123deb4bc
[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)
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,description,obj_files,required_subsystems,version,so_version,cflags,ldflags)
38 AC_DEFUN([SMB_LIBRARY],
39 [
40 SMB_INFO_LIBRARIES="$SMB_INFO_LIBRARIES
41 ###################################
42 # Start Library $1
43 @<:@LIBRARY::$1@:>@
44 DESCRIPTION = $2
45 OBJ_FILES = $3
46 PRIVATE_DEPENDENCIES = $4
47 VERSION = $5
48 SO_VERSION = $6 
49 CFLAGS = $7
50 LDFLAGS = $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
80                                 $1_CFLAGS="`$PKG_CONFIG --cflags '$2'`"
81                         OLD_CFLAGS="$CFLAGS"
82                         CFLAGS="$CFLAGS $$1_CFLAGS"
83                         AC_MSG_CHECKING([that the C compiler can use the $1_CFLAGS])
84                         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
85                                         SMB_ENABLE($1, YES)
86                                 AC_MSG_RESULT(yes),
87                                         AC_MSG_RESULT(no),
88                                         AC_MSG_WARN([cannot run when cross-compiling]))
89                         CFLAGS="$OLD_CFLAGS"
90
91
92                                 SMB_EXT_LIB($1, 
93                                         [`$PKG_CONFIG --libs-only-l '$2'`], 
94                                         [`$PKG_CONFIG --cflags-only-other '$2'`],
95                                         [`$PKG_CONFIG --cflags-only-I '$2'`],
96                                         [`$PKG_CONFIG --libs-only-other '$2'` `$PKG_CONFIG --libs-only-L '$2'`])
97                                 ac_cv_$1_found=yes
98
99                         else
100                                 AC_MSG_RESULT(no)
101                                 $PKG_CONFIG --errors-to-stdout --print-errors '$2'
102                                 ac_cv_$1_found=no
103                         fi
104                 else
105                         echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
106                                 echo "*** See http://pkg-config.freedesktop.org/"
107                                 ac_cv_$1_found=no
108                 fi
109         fi
110         if test x$ac_cv_$1_found = x"yes"; then
111                 ifelse([$3], [], [echo -n ""], [$3])
112         else
113                 ifelse([$4], [], [
114                           SMB_EXT_LIB($1)
115                           SMB_ENABLE($1, NO)
116                 ], [$4])
117         fi
118 ])
119
120 dnl SMB_INCLUDE_MK(file)
121 AC_DEFUN([SMB_INCLUDE_MK],
122 [
123 SMB_INFO_EXT_LIBS="$SMB_INFO_EXT_LIBS
124 include $1
125 "
126 ])
127
128 dnl SMB_EXT_LIB(name,libs,cflags,cppflags,ldflags)
129 AC_DEFUN([SMB_EXT_LIB],
130 [
131
132 SMB_INFO_EXT_LIBS="$SMB_INFO_EXT_LIBS
133 ###################################
134 # Start Ext Lib $1
135 @<:@EXT_LIB::$1@:>@
136 LIBS = $2
137 CFLAGS = $3
138 CPPFLAGS = $4
139 LDFLAGS = $5
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 ])