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