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