BUILT_SOURCES now depends on running the generator.
[libguestfs.git] / src / Makefile.am
1 # libguestfs
2 # Copyright (C) 2009 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 EXTRA_DIST = \
19         guestfs_protocol.x \
20         MAX_PROC_NR \
21         stamp-generator \
22         generator.ml \
23         guestfs-internal-actions.h
24
25 # Rerun the generator if it has changed.
26 # Git removes empty directories, so in cases where the
27 # generator is creating the sole file in a directory, we
28 # have to create the directory first.
29 noinst_DATA = stamp-generator
30
31 stamp-generator: generator.ml
32         mkdir -p $(top_srcdir)/perl/lib/Sys
33         mkdir -p $(top_srcdir)/ruby/ext/guestfs
34         mkdir -p $(top_srcdir)/java/com/redhat/et/libguestfs
35         cd $(top_srcdir) && ocaml -warn-error A src/generator.ml
36
37 $(BUILT_SOURCES): stamp-generator
38
39 include_HEADERS = guestfs.h guestfs-actions.h guestfs-structs.h
40
41 lib_LTLIBRARIES = libguestfs.la
42
43 BUILT_SOURCES = \
44   guestfs_protocol.x \
45   guestfs_protocol.c \
46   guestfs_protocol.h \
47   guestfs-structs.h \
48   guestfs-actions.h \
49   guestfs-actions.c \
50   guestfs-bindtests.c
51
52 # This convenience library is solely to avoid compiler warnings
53 # in its generated sources.
54 libprotocol_la_SOURCES = \
55   guestfs_protocol.c \
56   guestfs_protocol.h
57
58 libprotocol_la_CFLAGS =
59
60 CLEANFILES = guestfs_protocol.c guestfs_protocol.h
61
62 # From the libtool info file, with comments:
63 #
64 # |  1. Start with version information of `0:0:0' for each libtool library.
65 # |
66 # |  2. Update the version information only immediately before a public
67 # |     release of your software.  More frequent updates are unnecessary,
68 # |     and only guarantee that the current interface number gets larger
69 # |     faster.
70 # |
71 # |  3. If the library source code has changed at all since the last
72 # |     update, then increment REVISION (`C:R:A' becomes `C:r+1:A').
73 #
74 # [So it seems like we should always update the middle 'R' field
75 # for any release.]
76 #
77 # |  4. If any interfaces have been added, removed, or changed since the
78 # |     last update, increment CURRENT, and set REVISION to 0.
79 # |
80 # |  5. If any interfaces have been added since the last public release,
81 # |     then increment AGE.
82 #
83 # [These two rules seem to mean that if any change is made to the
84 # generator, we should increment C and A, and set R to 0, so:
85 # C+1:0:A+1.]
86 #
87 # |  6. If any interfaces have been removed since the last public release,
88 # |     then set AGE to 0.
89 #
90 # [Our ABI guarantee means we won't remove interfaces except in
91 # very exceptional circumstances.]
92 #
93 # The maximum proc number (see guestfs_protocol.x:guestfs_procedure) is
94 # a mostly accurate stand-in for C & A in rules 5 & 6, so we use that.  It
95 # is always incremented when we add a new appliance interface, and easy to
96 # calculate.
97 #
98 # The middle number is hard to increment-and-reset as described in rules
99 # 4 & 5, so for the moment it is always set to 0.
100 #
101 # Note that this scheme means the real library version will always be
102 # 'libguestfs.so.0.$(MAX_PROC_NR).0'.
103
104 libguestfs_la_LDFLAGS = -version-info $(MAX_PROC_NR):0:$(MAX_PROC_NR)
105 libguestfs_la_SOURCES = \
106         guestfs.c \
107         guestfs.h \
108         guestfs-actions.h \
109         guestfs-actions.c \
110         guestfs-bindtests.c \
111         guestfs-internal.h \
112         gettext.h
113
114 # Make libguestfs include the convenience library.
115 noinst_LTLIBRARIES = libprotocol.la
116 libguestfs_la_LIBADD = libprotocol.la
117
118 libguestfs_la_CFLAGS = \
119   -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \
120   $(WARN_CFLAGS) $(WERROR_CFLAGS)
121
122 libguestfs_la_CPPFLAGS = -I$(top_srcdir)/gnulib/lib
123
124 if HAVE_RPCGEN
125 guestfs_protocol.c: guestfs_protocol.x
126         rm -f $@-t $@-t2
127         $(RPCGEN) -c -o $@-t $<
128         sed 's,\.\./\.\./src/,,' < $@-t > $@-t2
129         rm $@-t
130         mv $@-t2 $@
131
132 guestfs_protocol.h: guestfs_protocol.x
133         rm -f $@-t
134         $(RPCGEN) -h -o $@-t $<
135         mv $@-t $@
136 endif