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