1XEN_ROOT=$(CURDIR)/../..
2include $(XEN_ROOT)/tools/Rules.mk
3
4MAJOR = 3.0
5MINOR = 3
6
7CFLAGS += -Werror
8CFLAGS += -I.
9# Include configure output (config.h)
10CFLAGS += -include $(XEN_ROOT)/tools/config.h
11CFLAGS += -I./include
12CFLAGS += $(CFLAGS_libxenevtchn)
13CFLAGS += $(CFLAGS_libxenctrl)
14CFLAGS += $(CFLAGS_libxentoolcore)
15CFLAGS += -DXEN_LIB_STORED="\"$(XEN_LIB_STORED)\""
16CFLAGS += -DXEN_RUN_STORED="\"$(XEN_RUN_STORED)\""
17
18CFLAGS  += $(CFLAGS-y)
19LDFLAGS += $(LDFLAGS-y)
20
21CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod
22CLIENTS += xenstore-write xenstore-ls xenstore-watch
23
24XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o
25XENSTORED_OBJS += xenstored_transaction.o xenstored_control.o
26XENSTORED_OBJS += xs_lib.o talloc.o utils.o tdb.o hashtable.o
27
28XENSTORED_OBJS_$(CONFIG_Linux) = xenstored_posix.o
29XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o xenstored_posix.o xenstored_probes.o
30XENSTORED_OBJS_$(CONFIG_NetBSD) = xenstored_posix.o
31XENSTORED_OBJS_$(CONFIG_FreeBSD) = xenstored_posix.o
32XENSTORED_OBJS_$(CONFIG_MiniOS) = xenstored_minios.o
33
34XENSTORED_OBJS += $(XENSTORED_OBJS_y)
35LDLIBS_xenstored += -lrt
36
37ifneq ($(XENSTORE_STATIC_CLIENTS),y)
38LIBXENSTORE := libxenstore.so
39else
40LIBXENSTORE := libxenstore.a
41xenstore xenstore-control: CFLAGS += -static
42endif
43
44ALL_TARGETS = libxenstore.a clients
45ifneq ($(nosharedlibs),y)
46ALL_TARGETS += libxenstore.so
47endif
48ifeq ($(XENSTORE_XENSTORED),y)
49ALL_TARGETS += xs_tdb_dump xenstored
50endif
51
52ifdef CONFIG_STUBDOM
53CFLAGS += -DNO_SOCKETS=1
54endif
55
56.PHONY: all
57all: $(ALL_TARGETS)
58
59.PHONY: clients
60clients: xenstore $(CLIENTS) xenstore-control
61
62ifeq ($(CONFIG_SunOS),y)
63xenstored_probes.h: xenstored_probes.d
64	dtrace -C -h -s xenstored_probes.d
65
66xenstored_solaris.o: xenstored_probes.h
67
68xenstored_probes.o: xenstored_solaris.o
69	dtrace -C -G -s xenstored_probes.d xenstored_solaris.o
70
71CFLAGS += -DHAVE_DTRACE=1
72endif
73
74ifeq ($(CONFIG_SYSTEMD),y)
75$(XENSTORED_OBJS): CFLAGS += $(SYSTEMD_CFLAGS)
76xenstored: LDFLAGS += $(SYSTEMD_LIBS)
77endif
78
79$(XENSTORED_OBJS): CFLAGS += $(CFLAGS_libxengnttab)
80
81xenstored: $(XENSTORED_OBJS)
82	$(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxenctrl) $(LDLIBS_xenstored) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
83
84xenstored.a: $(XENSTORED_OBJS)
85	$(AR) cr $@ $^
86
87$(CLIENTS): xenstore
88	ln -f xenstore $@
89
90xenstore: xenstore_client.o $(LIBXENSTORE)
91	$(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
92
93xenstore-control: xenstore_control.o $(LIBXENSTORE)
94	$(CC) $< $(LDFLAGS) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
95
96xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o
97	$(CC) $^ $(LDFLAGS) -o $@ $(APPEND_LDFLAGS)
98
99libxenstore.so: libxenstore.so.$(MAJOR)
100	ln -sf $< $@
101libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR)
102	ln -sf $< $@
103
104xs.opic: CFLAGS += -DUSE_PTHREAD
105ifeq ($(CONFIG_Linux),y)
106xs.opic: CFLAGS += -DUSE_DLSYM
107libxenstore.so.$(MAJOR).$(MINOR): APPEND_LDFLAGS += -ldl
108else
109PKG_CONFIG_REMOVE += -ldl
110endif
111
112libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
113	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
114
115libxenstore.a: xs.o xs_lib.o
116	$(AR) rcs $@ $^
117
118PKG_CONFIG := xenstore.pc
119PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
120
121ifneq ($(CONFIG_LIBXC_MINIOS),y)
122PKG_CONFIG_INST := $(PKG_CONFIG)
123$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
124$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
125$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
126endif
127
128PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
129
130$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
131$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_XENSTORE)/include
132$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
133$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
134
135$(LIBXENSTORE): $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
136
137.PHONY: clean
138clean:
139	rm -f *.a *.o *.opic *.so* xenstored_probes.h
140	rm -f xenstored xs_random xs_stress xs_crashme
141	rm -f xs_tdb_dump xenstore-control init-xenstore-domain
142	rm -f xenstore $(CLIENTS)
143	rm -f xenstore.pc
144	$(RM) $(DEPS_RM)
145
146.PHONY: distclean
147distclean: clean
148
149.PHONY: TAGS
150TAGS:
151	etags `find . -name '*.[ch]'`
152
153.PHONY: tarball
154tarball: clean
155	cd .. && tar -c -j -v -h -f xenstore.tar.bz2 xenstore/
156
157.PHONY: install
158install: all
159	$(INSTALL_DIR) $(DESTDIR)$(bindir)
160	$(INSTALL_DIR) $(DESTDIR)$(includedir)
161	$(INSTALL_DIR) $(DESTDIR)$(includedir)/xenstore-compat
162ifeq ($(XENSTORE_XENSTORED),y)
163	$(INSTALL_DIR) $(DESTDIR)$(sbindir)
164	$(INSTALL_DIR) $(DESTDIR)$(XEN_LIB_STORED)
165	$(INSTALL_PROG) xenstored $(DESTDIR)$(sbindir)
166endif
167	$(INSTALL_PROG) xenstore-control $(DESTDIR)$(bindir)
168	$(INSTALL_PROG) xenstore $(DESTDIR)$(bindir)
169	set -e ; for c in $(CLIENTS) ; do \
170		ln -f $(DESTDIR)$(bindir)/xenstore $(DESTDIR)$(bindir)/$${c} ; \
171	done
172	$(INSTALL_DIR) $(DESTDIR)$(libdir)
173	$(INSTALL_SHLIB) libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
174	ln -sf libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR)
175	ln -sf libxenstore.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenstore.so
176	$(INSTALL_DATA) libxenstore.a $(DESTDIR)$(libdir)
177	$(INSTALL_DATA) include/xenstore.h $(DESTDIR)$(includedir)
178	$(INSTALL_DATA) include/xenstore_lib.h $(DESTDIR)$(includedir)
179	$(INSTALL_DATA) include/compat/xs.h $(DESTDIR)$(includedir)/xenstore-compat/xs.h
180	$(INSTALL_DATA) include/compat/xs_lib.h $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
181	ln -sf xenstore-compat/xs.h  $(DESTDIR)$(includedir)/xs.h
182	ln -sf xenstore-compat/xs_lib.h $(DESTDIR)$(includedir)/xs_lib.h
183	$(INSTALL_DATA) xenstore.pc $(DESTDIR)$(PKG_INSTALLDIR)
184
185.PHONY: uninstall
186uninstall:
187	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xenstore.pc
188	rm -f $(DESTDIR)$(includedir)/xs_lib.h
189	rm -f $(DESTDIR)$(includedir)/xs.h
190	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs_lib.h
191	rm -f $(DESTDIR)$(includedir)/xenstore-compat/xs.h
192	rm -f $(DESTDIR)$(includedir)/xenstore_lib.h
193	rm -f $(DESTDIR)$(includedir)/xenstore.h
194	rm -f $(DESTDIR)$(libdir)/libxenstore.a
195	rm -f $(DESTDIR)$(libdir)/libxenstore.so
196	rm -f $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR)
197	rm -f $(DESTDIR)$(libdir)/libxenstore.so.$(MAJOR).$(MINOR)
198	rm -f $(addprefix $(DESTDIR)$(bindir)/, $(CLIENTS))
199	rm -f $(DESTDIR)$(bindir)/xenstore
200	rm -f $(DESTDIR)$(bindir)/xenstore-control
201ifeq ($(XENSTORE_XENSTORED),y)
202	rm -f $(DESTDIR)$(sbindir)/xenstored
203	if [ -d $(DESTDIR)$(XEN_LIB_STORED) ]; then \
204		rmdir --ignore-fail-on-non-empty $(DESTDIR)$(XEN_LIB_STORED); \
205	fi
206endif
207	if [ -d $(DESTDIR)$(includedir)/xenstore-compat ]; then \
208		rmdir --ignore-fail-on-non-empty $(DESTDIR)$(includedir)/xenstore-compat; \
209	fi
210
211.PHONY: clients-uninstall
212clients-uninstall:
213	rm -f $(addprefix $(DESTDIR)$(bindir)/, $(CLIENTS))
214
215.PHONY: clients-install
216clients-install: clients
217	$(INSTALL_DIR) $(DESTDIR)$(bindir)
218	$(INSTALL_PROG) xenstore $(DESTDIR)$(bindir)
219	set -e ; for c in $(CLIENTS) ; do \
220		ln -f $(DESTDIR)$(bindir)/xenstore $(DESTDIR)$(bindir)/$${c} ; \
221	done
222
223-include $(DEPS_INCLUDE)
224
225# never delete any intermediate files.
226.SECONDARY:
227