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