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