lib: Make pcre, libmagic and hivex libraries optional.
[libguestfs.git] / src / Makefile.am
1 # libguestfs
2 # Copyright (C) 2010 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 include $(top_srcdir)/subdir-rules.mk
19
20 generator_built = \
21         guestfs_protocol.x \
22         guestfs-structs.h \
23         guestfs-actions.h \
24         guestfs-internal-actions.h \
25         actions.c \
26         bindtests.c \
27         errnostring_gperf.gperf \
28         errnostring.c \
29         errnostring.h \
30         guestfs-actions.pod \
31         guestfs-availability.pod \
32         guestfs-structs.pod \
33         libguestfs.syms
34
35 BUILT_SOURCES = \
36         $(generator_built) \
37         guestfs_protocol.c \
38         guestfs_protocol.h \
39         errnostring_gperf.c
40
41 EXTRA_DIST = \
42         $(BUILT_SOURCES) \
43         MAX_PROC_NR \
44         libguestfs.3 \
45         guestfs.pod \
46         api-support/added \
47         api-support/README \
48         api-support/update-from-tarballs.sh
49
50 include_HEADERS = guestfs.h guestfs-actions.h guestfs-structs.h
51
52 lib_LTLIBRARIES = libguestfs.la
53
54 # This convenience library is solely to avoid compiler warnings
55 # in its generated sources.
56 libprotocol_la_SOURCES = \
57   guestfs_protocol.c \
58   guestfs_protocol.h
59
60 libprotocol_la_CFLAGS =
61
62 # Build the errnostring perfect hash code.  The generated code has lots
63 # of warnings so we must compile it in a separate mini-library.
64 liberrnostring_la_SOURCES = \
65         errnostring_gperf.c \
66         errnostring.h \
67         errnostring.c
68 liberrnostring_la_CFLAGS =
69
70 errnostring_gperf.c: errnostring_gperf.gperf
71         rm -f $@
72         $(GPERF) -t $< > $@-t
73         mv $@-t $@
74
75 # From the libtool info file, with comments:
76 #
77 # |  1. Start with version information of `0:0:0' for each libtool library.
78 # |
79 # |  2. Update the version information only immediately before a public
80 # |     release of your software.  More frequent updates are unnecessary,
81 # |     and only guarantee that the current interface number gets larger
82 # |     faster.
83 # |
84 # |  3. If the library source code has changed at all since the last
85 # |     update, then increment REVISION (`C:R:A' becomes `C:r+1:A').
86 #
87 # [So it seems like we should always update the middle 'R' field
88 # for any release.]
89 #
90 # |  4. If any interfaces have been added, removed, or changed since the
91 # |     last update, increment CURRENT, and set REVISION to 0.
92 # |
93 # |  5. If any interfaces have been added since the last public release,
94 # |     then increment AGE.
95 #
96 # [These two rules seem to mean that if any change is made to the
97 # generator, we should increment C and A, and set R to 0, so:
98 # C+1:0:A+1.]
99 #
100 # |  6. If any interfaces have been removed since the last public release,
101 # |     then set AGE to 0.
102 #
103 # [Our ABI guarantee means we won't remove interfaces except in
104 # very exceptional circumstances.]
105 #
106 # The maximum proc number (see guestfs_protocol.x:guestfs_procedure) is
107 # a mostly accurate stand-in for C & A in rules 5 & 6, so we use that.  It
108 # is always incremented when we add a new appliance interface, and easy to
109 # calculate.
110 #
111 # The middle number is hard to increment-and-reset as described in rules
112 # 4 & 5, so for the moment it is always set to 0.
113 #
114 # Note that this scheme means the real library version will always be
115 # 'libguestfs.so.0.$(MAX_PROC_NR).0'.
116 libguestfs_la_LDFLAGS = -version-info $(MAX_PROC_NR):0:$(MAX_PROC_NR)
117
118 libguestfs_la_LDFLAGS += $(VERSION_SCRIPT_FLAGS)libguestfs.syms
119
120 libguestfs_la_SOURCES = \
121         guestfs.c \
122         guestfs.h \
123         guestfs-actions.h \
124         guestfs-internal.h \
125         guestfs-structs.h \
126         guestfs_protocol.h \
127         gettext.h \
128         actions.c \
129         appliance.c \
130         bindtests.c \
131         filearch.c \
132         inspect.c \
133         launch.c \
134         listfs.c \
135         proto.c \
136         libguestfs.syms
137
138 libguestfs_la_LIBADD = $(HIVEX_LIBS) $(AUGEAS_LIBS) $(PCRE_LIBS) $(MAGIC_LIBS) $(LTLIBTHREAD) ../gnulib/lib/libgnu.la
139
140 # Make libguestfs include the convenience libraries.
141 noinst_LTLIBRARIES = liberrnostring.la libprotocol.la
142 libguestfs_la_LIBADD += liberrnostring.la libprotocol.la
143
144 libguestfs_la_CFLAGS = \
145   -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \
146   $(HIVEX_CFLAGS) $(AUGEAS_CFLAGS) $(PCRE_CFLAGS) \
147   $(WARN_CFLAGS) $(WERROR_CFLAGS)
148
149 libguestfs_la_CPPFLAGS = -I$(top_srcdir)/gnulib/lib
150
151 if HAVE_RPCGEN
152 guestfs_protocol.c: guestfs_protocol.x
153         rm -f $@-t $@-t2
154         $(RPCGEN) -c -o $@-t $<
155         sed 's,\.\./\.\./src/,,' < $@-t > $@-t2
156         rm $@-t
157         mv $@-t2 $@
158
159 guestfs_protocol.h: guestfs_protocol.x
160         rm -f $@-t
161         $(RPCGEN) -h -o $@-t $<
162         mv $@-t $@
163 endif
164
165 # Manual page.
166 # guestfs-actions.pod, guestfs-availability.pod and guestfs-structs
167 # are autogenerated.  There is no include mechanism for POD, so we
168 # have to do it by hand.
169
170 man_MANS = guestfs.3 libguestfs.3
171
172 guestfs.3: guestfs.pod \
173                 guestfs-actions.pod \
174                 guestfs-availability.pod \
175                 guestfs-structs.pod
176         sed \
177           -e '/@ACTIONS@/rguestfs-actions.pod' \
178           -e 's/@ACTIONS@//' \
179           -e '/@AVAILABILITY@/rguestfs-availability.pod' \
180           -e 's/@AVAILABILITY@//' \
181           -e '/@STRUCTS@/rguestfs-structs.pod' \
182           -e 's/@STRUCTS@//' \
183           < $< | \
184         $(POD2MAN) \
185           --section 3 \
186           -c "Virtualization Support" \
187           --name "guestfs" \
188           --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \
189           > $@
190
191 # Check user doesn't try to do 'make all' or 'make check' as root.
192 # https://www.redhat.com/archives/libguestfs/2010-April/msg00098.html
193
194 all-local: checkroot
195 check-local: checkroot
196 checkroot:
197         @if [ "`id -u`" = 0 ]; then \
198             echo "*** Error: Don't run 'make' or 'make check' as root."; \
199             exit 1; \
200         fi