Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-gmake3
[kai/samba.git] / source / build / make / rules.mk
1 # Rules file for Samba 4
2 # This relies on GNU make.
3 #
4 # Dependencies command
5 DEPENDS = $(CC) -M -MG -MP -MT $(<:.c=.o) -MT $@ \
6     $(CFLAGS) $(CPPFLAGS) $< -o $@
7 # Dependencies for host objects
8 HDEPENDS = $(CC) -M -MG -MP -MT $(<:.c=.ho) -MT $@ \
9     $(HOSTCC_FLAGS) $(CPPFLAGS) $< -o $@
10 # Dependencies for precompiled headers
11 PCHDEPENDS = $(CC) -M -MG -MT include/includes.h.gch -MT $@ \
12     $(CFLAGS) $(CPPFLAGS) $< -o $@
13
14 # Run a static analysis checker
15 CHECK = $(CC_CHECKER) $(CFLAGS) $(PICFLAG) $(CPPLAGS) -c $< -o $@
16
17 # Run the configured compiler
18 COMPILE = $(CC) $(CFLAGS) $(PICFLAG) \
19                   $(CPPFLAGS) \
20                   -c $< -o $@
21
22 # Run the compiler for the build host
23 HCOMPILE = $(HOSTCC) $(HOSTCC_FLAGS) $(CPPFLAGS) -c $< -o $@
24
25 # Precompile headers
26 PCHCOMPILE = @$(CC) -Ilib/replace \
27     $(CFLAGS) $(PICFLAG) $(CPPFLAGS) -c $< -o $@
28
29 # Partial linking
30 PARTLINK = @$(PROG_LD) -r
31
32 make_utility_dir = $(srcdir)/build/make/
33
34 include/config.h:
35         @echo "include/config.h not present"
36         @echo "You need to rerun ./autogen.sh and ./configure"
37         @/bin/false
38
39 pch::
40
41 clean:: clean_pch
42         @echo Removing objects
43         @-find . -name '*.o' -exec rm -f '{}' \;
44         @echo Removing hostcc objects
45         @-find . -name '*.ho' -exec rm -f '{}' \;
46         @echo Removing binaries
47         @-rm -f $(BIN_PROGS) $(SBIN_PROGS) $(BINARIES) $(TORTURE_PROGS)
48         @echo Removing libraries
49         @-rm -f $(STATIC_LIBS) $(SHARED_LIBS)
50         @-rm -f bin/static/*.a bin/shared/*.$(SHLIBEXT) bin/mergedobj/*.o
51         @echo Removing modules
52         @-rm -f bin/modules/*/*.$(SHLIBEXT)
53         @-rm -f bin/*_init_module.c
54         @echo Removing dummy targets
55         @-rm -f bin/.*_*
56         @echo Removing generated files
57         @-rm -f bin/*_init_module.c
58         @-rm -rf librpc/gen_* 
59         @echo Removing proto headers
60         @-rm -f $(PROTO_HEADERS)
61
62 distclean:: clean
63         -rm -f include/config.h include/config_tmp.h include/build.h
64         -rm -f data.mk
65         -rm -f config.status
66         -rm -f config.log config.cache
67         -rm -f config.pm config.mk
68         -rm -f $(PC_FILES)
69
70 removebackup::
71         -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
72
73 realdistclean:: distclean removebackup
74         -rm -f include/config_tmp.h.in
75         -rm -f version.h
76         -rm -f configure
77         -rm -f $(MANPAGES)
78
79 check:: test
80
81 unused_macros:
82         $(srcdir)/script/find_unused_macros.pl `find . -name "*.[ch]"` | sort
83
84 # Create a static library
85 %.a:
86         @echo Linking $@
87         @rm -f $@
88         @mkdir -p $(@D)
89         @$(STLD) $(STLD_FLAGS) $@ $^
90
91 ###############################################################################
92 # Templates
93 ###############################################################################
94
95 # Partially link
96 # Arguments: target object file, source object files
97 define partial_link_template 
98 $(1): $(2) ;
99         @echo Partially linking $$@
100         @mkdir -p $$(@D)
101         $$(PARTLINK) -o $$@ $$^
102 endef
103
104 # Link a binary
105 # Arguments: target file, depends, flags
106 define binary_link_template
107 $(1): $(2) ;
108         @echo Linking $$@
109         @$$(BNLD) $$(BNLD_FLAGS) $$(INTERN_LDFLAGS) -o $$@ $$(INSTALL_LINK_FLAGS) $(3)
110 endef
111
112 # Link a host-machine binary
113 # Arguments: target file, depends, flags
114 define host_binary_link_template
115 $(1): $(2) ;
116         @echo Linking $$@
117         @$$(HOSTLD) $$(HOSTLD_FLAGS) -L$${builddir}/bin/static -o $$@ $$(INSTALL_LINK_FLAGS) $(3)
118 endef
119
120 # Create a prototype header
121 # Arguments: header file, c files
122 define proto_header_template
123 $(1): $(2) ;
124         @echo "Creating $$@"
125         @$$(PERL) $$(srcdir)/script/mkproto.pl --srcdir=$$(srcdir) --builddir=$$(builddir) --public=/dev/null --private=$$@ $$^
126 endef
127
128 # Shared module
129 # Arguments: Target, dependencies, objects
130 define shared_module_template
131
132 $(1): $(2) ;
133         @echo Linking $$@
134         @mkdir -p $$(@D)
135         @$$(MDLD) $$(LDFLAGS) $$(MDLD_FLAGS) $$(INTERN_LDFLAGS) -o $$@ $$(INSTALL_LINK_FLAGS) $(3)
136
137 endef
138
139 # Shared library
140 # Arguments: Target, dependencies, link flags, soname
141 define shared_library_template
142 $(1): $(2)
143         @echo Linking $$@
144         @mkdir -p $$(@D)
145         @$$(SHLD) $$(LDFLAGS) $$(SHLD_FLAGS) $$(INTERN_LDFLAGS) -o $$@ $$(INSTALL_LINK_FLAGS) \
146                 $(3) \
147                 $$(if $$(SONAMEFLAG), $$(SONAMEFLAG)$(notdir $(4)))
148
149 ifneq ($(notdir $(1)),$(notdir $(4)))
150 $(4): $(1)
151         @echo "Creating symbolic link for $$@"
152         @ln -fs $$(<F) $$@
153 endif
154
155 ifneq ($(notdir $(1)),$(notdir $(5)))
156 $(5): $(1)
157         @echo "Creating symbolic link for $$@"
158         @ln -fs $$(<F) $$@
159 endif
160 endef
161
162 # Shared alias
163 # Arguments: Target, subsystem name, alias name
164 define shared_module_alias_template
165 bin/modules/$(2)/$(3).$$(SHLIBEXT): $(1)
166         @ln -fs $$(<F) $$@
167
168 PLUGINS += bin/modules/$(2)/$(3).$$(SHLIBEXT)
169
170 uninstallplugins::
171         @-rm $$(DESTDIR)$$(modulesdir)/$(2)/$(3).$$(SHLIBEXT)
172 installplugins::
173         @ln -fs $(1) $$(DESTDIR)$$(modulesdir)/$(2)/$(3).$$(SHLIBEXT)
174
175 endef
176
177 define shared_module_install_template
178 installplugins:: bin/modules/$(1)/$(2)
179         @echo Installing$(2) as $$(DESTDIR)$$(modulesdir)/$(1)/$(2)
180         @mkdir -p $$(DESTDIR)$$(modulesdir)/$(1)/
181         @cp bin/modules/$(1)/$(2) $$(DESTDIR)$$(modulesdir)/$(1)/$(2)
182 uninstallplugins::
183         @echo Uninstalling $$(DESTDIR)$$(modulesdir)/$(1)/$(2)
184         @-rm $$(DESTDIR)$$(modulesdir)/$(1)/$(2)
185
186 endef
187
188 ###############################################################################
189 # File types
190 ###############################################################################
191
192 .SUFFIXES: .x .c .et .y .l .d .o .h .h.gch .a .$(SHLIBEXT) .1 .1.xml .3 .3.xml .5 .5.xml .7 .7.xml .8 .8.xml .ho .idl .hd
193
194 .c.d:
195         @echo "Generating dependencies for $<"
196         @$(DEPENDS)
197
198 .c.hd:
199         @echo "Generating host-compiler dependencies for $<"
200         @$(HDEPENDS)
201
202 include/includes.d: include/includes.h
203         @echo "Generating dependencies for $<"
204         @$(PCHDEPENDS)
205
206 .c.o:
207         @if test -n "$(CC_CHECKER)"; then \
208                 echo "Checking  $< with '$(CC_CHECKER)'"; \
209                 $(CHECK) ; \
210         fi
211         @echo "Compiling $<"
212         @-mkdir -p `dirname $@`
213         @$(COMPILE) && exit 0 ; \
214                 echo "The following command failed:" 1>&2;\
215                 echo "$(COMPILE)" 1>&2;\
216                 $(COMPILE) >/dev/null 2>&1
217
218
219 .c.ho:
220         @echo "Compiling $< with host compiler"
221         @-mkdir -p `dirname $@`
222         @$(HCOMPILE) && exit 0;\
223                 echo "The following command failed:" 1>&2;\
224                 echo "$(HCOMPILE)" 1>&2;\
225                 $(HCOMPILE) >/dev/null 2>&1
226
227 .h.h.gch:
228         @echo "Precompiling $<"
229         @$(PCHCOMPILE)
230
231 .y.c:
232         @echo "Building $< with $(YACC)"
233         @-$(make_utility_dir)/yacc_compile.sh "$(YACC)" "$<" "$@"
234
235 .l.c:
236         @echo "Building $< with $(LEX)"
237         @-$(make_utility_dir)/script/lex_compile.sh "$(LEX)" "$<" "$@"
238
239 %.a:
240         @echo Linking $@
241         @rm -f $@
242         @mkdir -p $(@D)
243         @$(STLD) $(STLD_FLAGS) $@ $^
244
245
246 DOCBOOK_MANPAGE_URL = http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
247
248 .1.xml.1:
249         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
250
251 .3.xml.3:
252         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
253
254 .5.xml.5:
255         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
256
257 .7.xml.7:
258         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
259
260 .8.xml.8:
261         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
262
263 dist:: idl_full manpages configure distclean 
264
265 configure: 
266         ./autogen.sh
267
268 showflags::
269         @echo 'Samba will be compiled with flags:'
270         @echo '  CPP        = $(CPP)'
271         @echo '  CPPFLAGS   = $(CPPFLAGS)'
272         @echo '  CC         = $(CC)'
273         @echo '  CFLAGS     = $(CFLAGS)'
274         @echo '  PICFLAG    = $(PICFLAG)'
275         @echo '  BNLD       = $(BNLD)'
276         @echo '  BNLD_FLAGS = $(BNLD_FLAGS)'
277         @echo '  STLD       = $(STLD)'
278         @echo '  STLD_FLAGS = $(STLD_FLAGS)'
279         @echo '  SHLD       = $(SHLD)'
280         @echo '  SHLD_FLAGS = $(SHLD_FLAGS)'
281         @echo '  MDLD       = $(MDLD)'
282         @echo '  MDLD_FLAGS = $(MDLD_FLAGS)'
283         @echo '  SHLIBEXT   = $(SHLIBEXT)'
284
285 etags:
286         etags `find $(srcdir) -name "*.[ch]"`
287
288 ctags:
289         ctags `find $(srcdir) -name "*.[ch]"`