Move irc python module to libirc/
[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 headers = src/admin.h \
104                   src/ctcp.h \
105                   src/ctrlproxy.h \
106                   src/hooks.h \
107                   src/linestack.h \
108                   src/log_support.h \
109                   src/repl.h \
110                   src/settings.h \
111                   src/ssl.h \
112                   src/log.h \
113                   src/cache.h
114 dep_files = $(patsubst %.o, %.d, $(objs))
115
116 linestack-cmd$(EXEEXT): src/linestack-cmd.o $(objs) $(LIBIRC)
117         @echo Linking $@
118         @$(LD) $(LIBS) -lreadline -rdynamic -o $@ $^
119
120 ctrlproxy$(EXEEXT): src/main.o $(objs) $(LIBIRC)
121         @echo Linking $@
122         @$(LD) $(LDFLAGS) -rdynamic -o $@ $^ $(LIBS)
123
124 src/settings.o: CFLAGS+=-DSYSCONFDIR=\"${sysconfdir}\"
125
126 daemon/main.o: CFLAGS+=-DDEFAULT_CONFIG_FILE=\"${sysconfdir}/ctrlproxyd.conf\" \
127                            -DSSL_CREDENTIALS_DIR=\"${sysconfdir}/ctrlproxy/ssl\" \
128                                            -DPIDFILE=\"${localstatedir}/run/ctrlproxyd.pid\"
129
130 daemon_objs += daemon/main.o daemon/user.o daemon/client.o daemon/backend.o
131
132 ctrlproxyd$(EXEEXT): $(daemon_objs) $(objs) $(LIBIRC)
133         @echo Linking $@
134         @$(LD) $(LDFLAGS) -rdynamic -o $@ $^ $(LIBS)
135
136 ctrlproxy-admin$(EXEEXT): src/admin-cmd.o
137         @echo Linking $@
138         @$(LD) $(LDFLAGS) -rdynamic -o $@ $^ $(LIBS)
139
140 %.o: %.c
141         @echo Compiling $<
142         @$(CC) -I. -I$(libircdir) -Isrc $(CFLAGS) $(GCOV_CFLAGS) -c $< -o $@
143
144 %.d: %.c config.h
145         @$(CC) -I. -I$(libircdir) -Isrc -M -MT $(<:.c=.o) $(CFLAGS) $(PYTHON_CFLAGS) $< -o $@
146
147 # This looks a bit weird but is here to ensure that we never try to 
148 # run ./autogen.sh outside of bzr checkouts
149 ifeq ($(BZR_CHECKOUT),yes)
150 configure: autogen.sh configure.ac acinclude.m4
151         ./$<
152 else
153 configure:
154         ./autogen.sh
155 endif
156
157 ctrlproxy.pc Makefile.settings config.h: configure Makefile.settings.in ctrlproxy.pc.in
158         ./$<
159
160 install: all install-dirs install-bin install-header install-data install-pkgconfig $(EXTRA_INSTALL_TARGETS)
161 install-dirs:
162         $(INSTALL) -d $(DESTDIR)$(modulesdir)
163
164 uninstall: uninstall-bin uninstall-header uninstall-data uninstall-pkgconfig $(patsubst install-%,uninstall-%,$(EXTRA_INSTALL_TARGETS))
165 uninstall-bin:
166         -rm -f $(DESTDIR)$(bindir)/ctrlproxy$(EXEEXT) \
167                    $(DESTDIR)$(bindir)/ctrlproxy-admin$(EXEEXT) \
168                    $(DESTDIR)$(sbindir)/ctrlproxyd$(EXEEXT)
169         -rmdir $(DESTDIR)$(bindir)
170         -rmdir $(DESTDIR)$(sbindir)
171         -rmdir $(DESTDIR)$(modulesdir)
172
173 install-bin:
174         $(INSTALL) -d $(DESTDIR)$(bindir)
175         $(INSTALL) -d $(DESTDIR)$(sbindir)
176         $(INSTALL) $(BINS) $(DESTDIR)$(bindir)
177         $(INSTALL) $(SBINS) $(DESTDIR)$(sbindir)
178
179 uninstall-header:
180         -rm -f $(patsubst %,$(DESTDIR)$(destincludedir)/%,$(notdir $(headers) $(libirc_headers)))
181         -rmdir $(DESTDIR)$(destincludedir)
182
183 install-header::
184         $(INSTALL) -d $(DESTDIR)$(destincludedir)
185         $(INSTALL) -m 0644 $(libirc_headers) $(headers) $(DESTDIR)$(destincludedir)
186
187 doc::
188         $(MAKE) -C doc PACKAGE_VERSION=$(PACKAGE_VERSION)
189
190 install-doc:: doc
191         $(INSTALL) -d $(DESTDIR)$(docdir)
192         $(MAKE) -C doc install PACKAGE_VERSION=$(PACKAGE_VERSION)
193
194 uninstall-doc: 
195         $(MAKE) -C doc uninstall
196         -rmdir $(DESTDIR)$(docdir)
197
198 uninstall-data::
199         -rm -f $(DESTDIR)$(DEFAULT_CONFIG_DIR)/motd
200         -rm -f $(DESTDIR)$(DEFAULT_CONFIG_DIR)/config
201         -rmdir $(DESTDIR)$(DEFAULT_CONFIG_DIR)
202         -rmdir $(DESTDIR)$(sysconfdir)
203
204 install-data:
205         $(INSTALL) -d $(DESTDIR)$(sysconfdir)
206         $(INSTALL) -d $(DESTDIR)$(DEFAULT_CONFIG_DIR)
207         $(INSTALL) -m 0644 motd $(DESTDIR)$(DEFAULT_CONFIG_DIR)
208         $(INSTALL) -m 0644 config.default $(DESTDIR)$(DEFAULT_CONFIG_DIR)/config
209
210 install-pkgconfig:
211         $(INSTALL) -d $(DESTDIR)$(libdir)/pkgconfig
212         $(INSTALL) -m 0644 ctrlproxy.pc $(DESTDIR)$(libdir)/pkgconfig
213
214 uninstall-pkgconfig:
215         -rm -f $(DESTDIR)$(libdir)/pkgconfig/ctrlproxy.pc
216         -rmdir $(DESTDIR)$(libdir)/pkgconfig
217
218 gcov: check
219         $(GCOV) -f -p -o src/ src/*.c 
220
221 lcov:
222         lcov --base-directory `pwd` --directory . --capture --output-file ctrlproxy.info
223         genhtml -o coverage ctrlproxy.info
224
225 $(libirc_objs): CFLAGS+=-fPIC
226
227 $(LIBIRC_STATIC): $(libirc_objs)
228         @echo Linking $@
229         @ar -rcs $@ $^
230
231 $(LIBIRC_SHARED): $(libirc_objs)
232         $(LD) -shared $(LDFLAGS) -Wl,-soname,$(LIBIRC_SONAME) -o $@ $^
233
234 %.$(SHLIBEXT):
235         $(LD) -shared $(LDFLAGS) -o $@ $^
236
237 cscope.out::
238         cscope -b -R
239
240 clean::
241         @echo Removing object files and executables
242         @rm -f src/*.o $(libircdir)/*.o daemon/*.o python/*.o testsuite/check ctrlproxy$(EXEEXT) testsuite/*.o *~
243         @rm -f linestack-cmd$(EXEEXT) ctrlproxy-admin$(EXEEXT)
244         @rm -f ctrlproxyd$(EXEEXT)
245         @rm -f $(LIBIRC_STATIC) $(LIBIRC_SHARED)
246         @echo Removing gcov output
247         @rm -f *.gcov *.gcno *.gcda  */*.gcda */*.gcno */*.gcov
248         @echo Removing test output
249         @rm -rf test-*
250
251 doc-dist:: configure
252         $(MAKE) -C doc dist
253
254 dist: configure doc-dist distclean
255
256 distclean:: clean 
257         rm -f build config.h ctrlproxy.pc *.log
258         rm -rf autom4te.cache/ config.log config.status
259
260 realclean:: distclean
261         @$(MAKE) -C doc clean
262
263 ctags:
264         ctags -R .
265
266 # Python specific stuff below this line
267 mods/python.o python/ctrlproxy.o: CFLAGS+=$(PYTHON_CFLAGS)
268 mods/python.o python/ctrlproxy.o: CFLAGS+=-fPIC
269 mods/libpython.so: mods/python.o python/ctrlproxy.o libirc/python/irc.o
270 mods/libpython.so: LDFLAGS+=$(PYTHON_LDFLAGS)
271
272 .PRECIOUS: python/irc.c python/ctrlproxy.c
273
274 libirc/python/irc.o: CFLAGS+=$(PYTHON_CFLAGS) -fPIC
275 python/irc.$(SHLIBEXT): libirc/python/irc.o $(LIBIRC)
276 python/irc.$(SHLIBEXT): LDFLAGS+=$(PYTHON_LDFLAGS) $(LIBS)
277
278 ifeq ($(HAVE_PYTHON),yes)
279 all_objs += libirc/python/irc.o mods/python.o python/ctrlproxy.o
280 endif
281
282 python:: python/irc.$(SHLIBEXT) mods/libpython.$(SHLIBEXT)
283
284 check-python:: python/irc.$(SHLIBEXT)
285         PYTHONPATH=python trial tests.test_irc
286
287 install-python: all
288         $(PYTHON) setup.py install --root="$(DESTDIR)"
289
290 clean::
291         @rm -f python/tests/*.pyc
292 #       $(PYTHON) setup.py clean
293
294 # RFC compliance testing using ircdtorture
295
296 TEST_SERVER := localhost
297 TEST_PORT := 6667
298
299 testsuite/ctrlproxyrc.torture: testsuite/ctrlproxyrc.torture.in
300         sed -e 's/@SERVER@/$(TEST_SERVER)/;s/@PORT@/$(TEST_PORT)/;' < $< > $@
301
302 rfctest: testsuite/ctrlproxyrc.torture
303         @$(IRCDTORTURE) -- ./ctrlproxy -d 0 -i TEST -r $<
304
305 # Unit tests
306 check_objs = testsuite/test-cmp.o testsuite/test-user.o \
307                          testsuite/test-admin.o testsuite/test-isupport.o \
308                          testsuite/test-parser.o testsuite/test-state.o \
309                          testsuite/test-util.o testsuite/test-line.o \
310                          testsuite/torture.o testsuite/test-linestack.o \
311                          testsuite/test-client.o testsuite/test-network.o \
312                          testsuite/test-tls.o testsuite/test-redirect.o \
313                          testsuite/test-networkinfo.o testsuite/test-ctcp.o \
314                          testsuite/test-help.o testsuite/test-nickserv.o \
315                          testsuite/test-url.o testsuite/test-motd.o \
316                          testsuite/test-log-subst.o testsuite/test-transport.o
317
318 testsuite/check: $(check_objs) $(objs) $(LIBIRC)
319         @echo Linking $@
320         @$(CC) $(LIBS) -o $@ $^ $(CHECK_LIBS)
321
322 check:: testsuite/check
323         @echo Running testsuite
324         @$(DEBUGGER) ./testsuite/check $(CHECK_OPTIONS)
325
326 check-nofork:: 
327         $(MAKE) check CHECK_OPTIONS=-nsv
328
329 check-gdb: 
330         $(MAKE) check-nofork DEBUGGER="gdb --args"
331
332 clean::
333         @echo Removing dependency files
334         @rm -f $(dep_files)
335
336 examples:: example/libfoo.$(SHLIBEXT) example/libirc-simple
337
338 example/libfoo.$(SHLIBEXT): example/foo.o
339 example/foo.o: CFLAGS+=-I$(libircdir)
340
341 example/libirc-simple: example/irc_simple.o $(LIBIRC)
342         $(CC) -o $@ $^
343
344 example/irc_simple.o: CFLAGS+=-I$(libircdir)
345
346 -include $(dep_files)