Fix clean for libirc python module.
[jelmer/ctrlproxy.git] / Makefile
1 # Makefile for ctrlproxy
2 # Copyright (C) 2002-2009 Jelmer Vernooij <jelmer@samba.org>
3 # NOTE: This file is *NOT* autogenerated.
4
5 include Makefile.settings
6
7 BINS += ctrlproxy$(EXEEXT)
8 SBINS += ctrlproxyd$(EXEEXT)
9
10 GCOV = gcov
11
12 ifeq ($(WITH_GCOV),1)
13 CFLAGS += --coverage
14 LIBS += --coverage
15 endif
16
17 LIBS += $(GNUTLS_LIBS)
18 CFLAGS += $(GNUTLS_CFLAGS)
19
20 CFLAGS+=-DHAVE_CONFIG_H -DDEFAULT_CONFIG_DIR=\"$(DEFAULT_CONFIG_DIR)\" -DHELPFILE=\"$(HELPFILE)\"
21 CFLAGS+=-ansi -Wall -DMODULESDIR=\"$(modulesdir)\" -DSTRICT_MEMORY_ALLOCS=
22
23 LIBIRC_STATIC = libirc.a
24 LIBIRC = $(LIBIRC_STATIC)
25
26 LIBIRC_SHARED = libirc.$(SHLIBEXT).$(PACKAGE_VERSION)
27 LIBIRC_SOVERSION = 1.0
28 LIBIRC_SONAME = libirc.$(SHLIBEXT).$(LIBIRC_SOVERSION)
29
30 .PHONY: all clean distclean install install-bin install-dirs install-doc install-data install-pkgconfig
31
32 all:: $(BINS) $(SBINS)
33
34 ifeq ($(HAVE_PYTHON),yes)
35 check:: check-python
36 all:: python
37 endif
38
39 experimental:: all 
40
41 doxygen:
42         doxygen
43
44 libircdir = libirc
45
46 objs = src/posix.o \
47            src/redirect.o \
48            src/cache.o \
49            src/util.o \
50            src/hooks.o \
51            src/linestack.o \
52            src/plugins.o \
53            src/settings.o \
54            src/log.o \
55            src/client.o \
56            src/gen_config.o \
57            src/repl.o \
58            src/linestack_file.o \
59            src/ctcp_redirect.o \
60            src/ctcp.o \
61            src/motd.o \
62            src/nickserv.o \
63            src/keyfile.o \
64            src/admin.o \
65            src/user.o \
66            src/help.o \
67            src/repl_backends.o \
68            src/listener.o \
69            src/log_support.o \
70            src/log_custom.o \
71            src/log_subst.o \
72            src/auto_away.o \
73            src/network.o \
74            $(CTRLPROXY_SSL_OBJS)
75 all_objs += $(objs)
76
77 libirc_objs = \
78            $(libircdir)/state.o \
79            $(libircdir)/client.o \
80            $(libircdir)/transport.o \
81            $(libircdir)/transport_ioc.o \
82            $(libircdir)/line.o \
83            $(libircdir)/isupport.o \
84            $(libircdir)/connection.o \
85            $(libircdir)/redirect.o \
86            $(libircdir)/url.o \
87            $(libircdir)/util.o \
88            $(libircdir)/listener.o \
89            $(LIBIRC_SSL_OBJS)
90
91 libirc_headers = \
92                   $(libircdir)/state.h \
93                   $(libircdir)/client.h \
94                   $(libircdir)/line.h \
95                   $(libircdir)/isupport.h \
96                   $(libircdir)/irc.h \
97                   $(libircdir)/connection.h \
98                   $(libircdir)/redirect.h \
99                   $(libircdir)/url.h \
100                   $(libircdir)/listener.h \
101                   $(libircdir)/util.h
102
103 pyirc_objs = $(libircdir)/python/irc.o \
104                          $(libircdir)/python/transport.o \
105                          $(libircdir)/python/state.o
106
107 headers = src/admin.h \
108                   src/ctcp.h \
109                   src/ctrlproxy.h \
110                   src/hooks.h \
111                   src/linestack.h \
112                   src/log_support.h \
113                   src/repl.h \
114                   src/settings.h \
115                   src/ssl.h \
116                   src/log.h \
117                   src/cache.h
118 dep_files = $(patsubst %.o, %.d, $(objs))
119
120 linestack-cmd$(EXEEXT): src/linestack-cmd.o $(objs) $(LIBIRC)
121         @echo Linking $@
122         @$(LD) $(LIBS) -lreadline -rdynamic -o $@ $^
123
124 ctrlproxy$(EXEEXT): src/main.o $(objs) $(LIBIRC)
125         @echo Linking $@
126         @$(LD) $(LDFLAGS) -rdynamic -o $@ $^ $(LIBS)
127
128 src/settings.o: CFLAGS+=-DSYSCONFDIR=\"${sysconfdir}\"
129
130 daemon/main.o: CFLAGS+=-DDEFAULT_CONFIG_FILE=\"${sysconfdir}/ctrlproxyd.conf\" \
131                            -DSSL_CREDENTIALS_DIR=\"${sysconfdir}/ctrlproxy/ssl\" \
132                                            -DPIDFILE=\"${localstatedir}/run/ctrlproxyd.pid\"
133
134 daemon_objs += daemon/main.o daemon/user.o daemon/client.o daemon/backend.o
135
136 ctrlproxyd$(EXEEXT): $(daemon_objs) $(objs) $(LIBIRC)
137         @echo Linking $@
138         @$(LD) $(LDFLAGS) -rdynamic -o $@ $^ $(LIBS)
139
140 ctrlproxy-admin$(EXEEXT): src/admin-cmd.o
141         @echo Linking $@
142         @$(LD) $(LDFLAGS) -rdynamic -o $@ $^ $(LIBS)
143
144 %.o: %.c
145         @echo Compiling $<
146         @$(CC) -I. -I$(libircdir) -Isrc $(CFLAGS) $(GCOV_CFLAGS) -c $< -o $@
147
148 %.d: %.c config.h
149         @$(CC) -I. -I$(libircdir) -Isrc -M -MT $(<:.c=.o) $(CFLAGS) $(PYTHON_CFLAGS) $< -o $@
150
151 # This looks a bit weird but is here to ensure that we never try to 
152 # run ./autogen.sh outside of bzr checkouts
153 ifeq ($(BZR_CHECKOUT),yes)
154 configure: autogen.sh configure.ac acinclude.m4
155         ./$<
156 else
157 configure:
158         ./autogen.sh
159 endif
160
161 ctrlproxy.pc Makefile.settings config.h: configure Makefile.settings.in ctrlproxy.pc.in
162         ./$<
163
164 install: all install-dirs install-bin install-header install-data install-pkgconfig $(EXTRA_INSTALL_TARGETS)
165 install-dirs:
166         $(INSTALL) -d $(DESTDIR)$(modulesdir)
167
168 uninstall: uninstall-bin uninstall-header uninstall-data uninstall-pkgconfig $(patsubst install-%,uninstall-%,$(EXTRA_INSTALL_TARGETS))
169 uninstall-bin:
170         -rm -f $(DESTDIR)$(bindir)/ctrlproxy$(EXEEXT) \
171                    $(DESTDIR)$(bindir)/ctrlproxy-admin$(EXEEXT) \
172                    $(DESTDIR)$(sbindir)/ctrlproxyd$(EXEEXT)
173         -rmdir $(DESTDIR)$(bindir)
174         -rmdir $(DESTDIR)$(sbindir)
175         -rmdir $(DESTDIR)$(modulesdir)
176
177 install-bin:
178         $(INSTALL) -d $(DESTDIR)$(bindir)
179         $(INSTALL) -d $(DESTDIR)$(sbindir)
180         $(INSTALL) $(BINS) $(DESTDIR)$(bindir)
181         $(INSTALL) $(SBINS) $(DESTDIR)$(sbindir)
182
183 uninstall-header:
184         -rm -f $(patsubst %,$(DESTDIR)$(destincludedir)/%,$(notdir $(headers) $(libirc_headers)))
185         -rmdir $(DESTDIR)$(destincludedir)
186
187 install-header::
188         $(INSTALL) -d $(DESTDIR)$(destincludedir)
189         $(INSTALL) -m 0644 $(libirc_headers) $(headers) $(DESTDIR)$(destincludedir)
190
191 doc::
192         $(MAKE) -C doc PACKAGE_VERSION=$(PACKAGE_VERSION)
193
194 install-doc:: doc
195         $(INSTALL) -d $(DESTDIR)$(docdir)
196         $(MAKE) -C doc install PACKAGE_VERSION=$(PACKAGE_VERSION)
197
198 uninstall-doc: 
199         $(MAKE) -C doc uninstall
200         -rmdir $(DESTDIR)$(docdir)
201
202 uninstall-data::
203         -rm -f $(DESTDIR)$(DEFAULT_CONFIG_DIR)/motd
204         -rm -f $(DESTDIR)$(DEFAULT_CONFIG_DIR)/config
205         -rmdir $(DESTDIR)$(DEFAULT_CONFIG_DIR)
206         -rmdir $(DESTDIR)$(sysconfdir)
207
208 install-data:
209         $(INSTALL) -d $(DESTDIR)$(sysconfdir)
210         $(INSTALL) -d $(DESTDIR)$(DEFAULT_CONFIG_DIR)
211         $(INSTALL) -m 0644 motd $(DESTDIR)$(DEFAULT_CONFIG_DIR)
212         $(INSTALL) -m 0644 config.default $(DESTDIR)$(DEFAULT_CONFIG_DIR)/config
213
214 install-pkgconfig:
215         $(INSTALL) -d $(DESTDIR)$(libdir)/pkgconfig
216         $(INSTALL) -m 0644 ctrlproxy.pc $(DESTDIR)$(libdir)/pkgconfig
217
218 uninstall-pkgconfig:
219         -rm -f $(DESTDIR)$(libdir)/pkgconfig/ctrlproxy.pc
220         -rmdir $(DESTDIR)$(libdir)/pkgconfig
221
222 gcov: check
223         $(GCOV) -f -p -o src/ src/*.c 
224
225 lcov:
226         lcov --base-directory `pwd` --directory . --capture --output-file ctrlproxy.info
227         genhtml -o coverage ctrlproxy.info
228
229 $(libirc_objs): CFLAGS+=-fPIC
230
231 $(LIBIRC_STATIC): $(libirc_objs)
232         @echo Linking $@
233         @ar -rcs $@ $^
234
235 $(LIBIRC_SHARED): $(libirc_objs)
236         $(LD) -shared $(LDFLAGS) -Wl,-soname,$(LIBIRC_SONAME) -o $@ $^
237
238 %.$(SHLIBEXT):
239         $(LD) -shared $(LDFLAGS) -o $@ $^
240
241 cscope.out::
242         cscope -b -R
243
244 clean::
245         @echo Removing object files and executables
246         @rm -f src/*.o $(libircdir)/*.o daemon/*.o python/*.o testsuite/check ctrlproxy$(EXEEXT) testsuite/*.o *~
247         @rm -f linestack-cmd$(EXEEXT) ctrlproxy-admin$(EXEEXT)
248         @rm -f ctrlproxyd$(EXEEXT)
249         @rm -f $(LIBIRC_STATIC) $(LIBIRC_SHARED)
250         @echo Removing gcov output
251         @rm -f *.gcov *.gcno *.gcda  */*.gcda */*.gcno */*.gcov
252         @echo Removing test output
253         @rm -rf test-*
254
255 doc-dist:: configure
256         $(MAKE) -C doc dist
257
258 dist: configure doc-dist distclean
259
260 distclean:: clean 
261         rm -f build config.h ctrlproxy.pc *.log
262         rm -rf autom4te.cache/ config.log config.status
263
264 realclean:: distclean
265         @$(MAKE) -C doc clean
266
267 ctags:
268         ctags -R .
269
270 # Python specific stuff below this line
271 mods/python.o python/ctrlproxy.o: CFLAGS+=$(PYTHON_CFLAGS)
272 mods/python.o python/ctrlproxy.o: CFLAGS+=-fPIC
273 mods/libpython.so: mods/python.o python/ctrlproxy.o $(pyirc_objs)
274 mods/libpython.so: LDFLAGS+=$(PYTHON_LDFLAGS)
275
276 .PRECIOUS: python/irc.c python/ctrlproxy.c
277
278 $(pyirc_objs): CFLAGS+=$(PYTHON_CFLAGS) -fPIC
279 libirc/python/irc.$(SHLIBEXT): $(pyirc_objs) $(LIBIRC)
280 libirc/python/irc.$(SHLIBEXT): LDFLAGS+=$(PYTHON_LDFLAGS) $(LIBS)
281
282 ifeq ($(HAVE_PYTHON),yes)
283 all_objs += $(pyirc_objs) mods/python.o python/ctrlproxy.o
284 endif
285
286 python:: libirc/python/irc.$(SHLIBEXT) mods/libpython.$(SHLIBEXT)
287
288 check-python:: libirc/python/irc.$(SHLIBEXT)
289         PYTHONPATH=libirc/python trial tests.test_irc
290
291 install-python: all
292         $(PYTHON) setup.py install --root="$(DESTDIR)"
293
294 clean::
295         @rm -f python/tests/*.pyc
296         @rm -f libirc/python/tests/*.pyc
297         @rm -f libirc/python/*.$(SHLIBEXT) libirc/python/*.o
298 #       $(PYTHON) setup.py clean
299
300 # RFC compliance testing using ircdtorture
301
302 TEST_SERVER := localhost
303 TEST_PORT := 6667
304
305 testsuite/ctrlproxyrc.torture: testsuite/ctrlproxyrc.torture.in
306         sed -e 's/@SERVER@/$(TEST_SERVER)/;s/@PORT@/$(TEST_PORT)/;' < $< > $@
307
308 rfctest: testsuite/ctrlproxyrc.torture
309         @$(IRCDTORTURE) -- ./ctrlproxy -d 0 -i TEST -r $<
310
311 # Unit tests
312 check_objs = testsuite/test-cmp.o testsuite/test-user.o \
313                          testsuite/test-admin.o testsuite/test-isupport.o \
314                          testsuite/test-parser.o testsuite/test-state.o \
315                          testsuite/test-util.o testsuite/test-line.o \
316                          testsuite/torture.o testsuite/test-linestack.o \
317                          testsuite/test-client.o testsuite/test-network.o \
318                          testsuite/test-tls.o testsuite/test-redirect.o \
319                          testsuite/test-networkinfo.o testsuite/test-ctcp.o \
320                          testsuite/test-help.o testsuite/test-nickserv.o \
321                          testsuite/test-url.o testsuite/test-motd.o \
322                          testsuite/test-log-subst.o testsuite/test-transport.o
323
324 testsuite/check: $(check_objs) $(objs) $(LIBIRC)
325         @echo Linking $@
326         @$(CC) $(LIBS) -o $@ $^ $(CHECK_LIBS)
327
328 check:: testsuite/check
329         @echo Running testsuite
330         @$(DEBUGGER) ./testsuite/check $(CHECK_OPTIONS)
331
332 check-nofork:: 
333         $(MAKE) check CHECK_OPTIONS=-nsv
334
335 check-gdb: 
336         $(MAKE) check-nofork DEBUGGER="gdb --args"
337
338 clean::
339         @echo Removing dependency files
340         @rm -f $(dep_files)
341
342 examples:: example/libfoo.$(SHLIBEXT) example/libirc-simple
343
344 example/libfoo.$(SHLIBEXT): example/foo.o
345 example/foo.o: CFLAGS+=-I$(libircdir)
346
347 example/libirc-simple: example/irc_simple.o $(LIBIRC)
348         $(CC) -o $@ $^
349
350 example/irc_simple.o: CFLAGS+=-I$(libircdir)
351
352 -include $(dep_files)