Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-gmake3
[ira/wip.git] / source4 / rules.mk
1 # Dependencies command
2 DEPENDS = $(CC) -M -MG -MP -MT $(<:.c=.o) -MT $@ \
3     $(CFLAGS) $(CPPFLAGS) $< -o $@
4 # Dependencies for host objects
5 HDEPENDS = $(CC) -M -MG -MP -MT $(<:.c=.ho) -MT $@ \
6     $(HOSTCC_FLAGS) $(CPPFLAGS) $< -o $@
7 # Dependencies for precompiled headers
8 PCHDEPENDS = $(CC) -M -MG -MT include/includes.h.gch -MT $@ \
9     $(CFLAGS) $(CPPFLAGS) $< -o $@
10
11 # Run a static analysis checker
12 CHECK = $(CC_CHECKER) $(CFLAGS) $(PICFLAG) $(CPPLAGS) -c $< -o $@
13
14 # Run the configured compiler
15 COMPILE = $(CC) $(CFLAGS) $(PICFLAG) \
16                   $(CPPFLAGS) \
17                   -c $< -o $@
18
19 # Run the compiler for the build host
20 HCOMPILE = $(HOSTCC) $(HOSTCC_FLAGS) $(CPPFLAGS) -c $< -o $@
21
22 # Precompile headers
23 PCHCOMPILE = @$(CC) -Ilib/replace \
24     $(CFLAGS) $(PICFLAG) $(CPPFLAGS) -c $< -o $@
25
26 # Partial linking
27 PARTLINK = @$(PROG_LD) -r
28
29 include/config.h:
30         @echo "include/config.h not present"
31         @echo "You need to rerun ./autogen.sh and ./configure"
32         @/bin/false
33
34 $(srcdir)/version.h: $(srcdir)/VERSION
35         @$(SHELL) script/mkversion.sh VERSION $(srcdir)/version.h $(srcdir)/
36
37 regen_version::
38         @$(SHELL) script/mkversion.sh VERSION $(srcdir)/version.h $(srcdir)/
39
40 clean_pch::
41         @echo "Removing precompiled headers"
42         @-rm -f include/includes.h.gch
43
44 pch:: clean_pch include/includes.h.gch
45
46 clean:: clean_pch
47         @echo Removing objects
48         @-find . -name '*.o' -exec rm -f '{}' \;
49         @echo Removing hostcc objects
50         @-find . -name '*.ho' -exec rm -f '{}' \;
51         @echo Removing binaries
52         @-rm -f $(BIN_PROGS) $(SBIN_PROGS) $(BINARIES) $(TORTURE_PROGS)
53         @echo Removing libraries
54         @-rm -f $(STATIC_LIBRARIES) $(SHARED_LIBRARIES)
55         @-rm -f bin/static/*.a bin/shared/*.$(SHLIBEXT) bin/mergedobj/*.o
56         @echo Removing modules
57         @-rm -f bin/modules/*/*.$(SHLIBEXT)
58         @-rm -f bin/*_init_module.c
59         @echo Removing dummy targets
60         @-rm -f bin/.*_*
61         @echo Removing generated files
62         @-rm -f bin/*_init_module.c
63         @-rm -rf librpc/gen_* 
64         @echo Removing proto headers
65         @-rm -f $(PROTO_HEADERS)
66
67 distclean:: clean
68         -rm -f include/config.h include/config_tmp.h include/build.h
69         -rm -f data.mk
70         -rm -f config.status
71         -rm -f config.log config.cache
72         -rm -f config.pm config.mk
73         -rm -f $(PC_FILES)
74
75 removebackup::
76         -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
77
78 realdistclean:: distclean removebackup
79         -rm -f include/config_tmp.h.in
80         -rm -f version.h
81         -rm -f configure
82         -rm -f $(MANPAGES)
83
84 check:: test
85
86 unused_macros:
87         $(srcdir)/script/find_unused_macros.pl `find . -name "*.[ch]"` | sort
88
89 ###############################################################################
90 # Templates
91 ###############################################################################
92
93 # Partially link
94 # Arguments: target object file, source object files
95 define partial_link_template 
96 $(1): $(2) ;
97         @echo Partially linking $$@
98         @mkdir -p $$(@D)
99         $$(PARTLINK) -o $$@ $$^
100 endef
101
102 # Link a binary
103 # Arguments: target file, depends, flags
104 define binary_link_template
105 $(1): $(2) ;
106         @echo Linking $$@
107         @$$(BNLD) $$(BNLD_FLAGS) $$(INTERN_LDFLAGS) -o $$@ $$(INSTALL_LINK_FLAGS) $(3)
108 endef
109
110 # Link a host-machine binary
111 # Arguments: target file, depends, flags
112 define host_binary_link_template
113 $(1): $(2) ;
114         @echo Linking $$@
115         @$$(HOSTLD) $$(HOSTLD_FLAGS) -L$${builddir}/bin/static -o $$@ $$(INSTALL_LINK_FLAGS) $(3)
116 endef
117
118 # Create a prototype header
119 # Arguments: header file, c files
120 define proto_header_template
121 $(1): $(2) ;
122         @echo "Creating $$@"
123         @$$(PERL) $$(srcdir)/script/mkproto.pl --srcdir=$$(srcdir) --builddir=$$(builddir) --all=$$@ $$^
124 endef
125
126 ###############################################################################
127 # File types
128 ###############################################################################
129
130 .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
131
132 .c.d:
133         @echo "Generating dependencies for $<"
134         @$(DEPENDS)
135
136 .c.hd:
137         @echo "Generating host-compiler dependencies for $<"
138         @$(HDEPENDS)
139
140 include/includes.d: include/includes.h
141         @echo "Generating dependencies for $<"
142         @$(PCHDEPENDS)
143
144 .c.o:
145         @if test -n "$(CC_CHECKER)"; then \
146                 echo "Checking  $< with '$(CC_CHECKER)'"; \
147                 $(CHECK) ; \
148         fi
149         @echo "Compiling $<"
150         @-mkdir -p `dirname $@`
151         @$(COMPILE) && exit 0 ; \
152                 echo "The following command failed:" 1>&2;\
153                 $(COMPILE) >/dev/null 2>&1
154
155
156 #               echo "$(COMPILE)" 1>&2;\
157
158 .c.ho:
159         @echo "Compiling $< with host compiler"
160         @-mkdir -p `dirname $@`
161         @$(HCOMPILE) && exit 0;\
162                 echo "The following command failed:" 1>&2;\
163                 echo "$(HCOMPILE)" 1>&2;\
164                 $(HCOMPILE) >/dev/null 2>&1
165
166 .h.h.gch:
167         @echo "Precompiling $<"
168         @$(PCHCOMPILE)
169
170 .y.c:
171         @echo "Building $< with $(YACC)"
172         @-$(srcdir)/script/yacc_compile.sh "$(YACC)" "$<" "$@"
173
174 .l.c:
175         @echo "Building $< with $(LEX)"
176         @-$(srcdir)/script/lex_compile.sh "$(LEX)" "$<" "$@"
177
178 %.a:
179         @echo Linking $@
180         @rm -f $@
181         @mkdir -p $(@D)
182         @$(STLD) $(STLD_FLAGS) $@ $^
183
184
185 DOCBOOK_MANPAGE_URL = http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
186
187 .1.xml.1:
188         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
189
190 .3.xml.3:
191         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
192
193 .5.xml.5:
194         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
195
196 .7.xml.7:
197         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
198
199 .8.xml.8:
200         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
201
202 dist:: idl_full manpages configure distclean 
203
204 configure: 
205         ./autogen.sh
206
207 showflags::
208         @echo 'Samba will be compiled with flags:'
209         @echo '  CPP        = $(CPP)'
210         @echo '  CPPFLAGS   = $(CPPFLAGS)'
211         @echo '  CC         = $(CC)'
212         @echo '  CFLAGS     = $(CFLAGS)'
213         @echo '  PICFLAG    = $(PICFLAG)'
214         @echo '  BNLD       = $(BNLD)'
215         @echo '  BNLD_FLAGS = $(BNLD_FLAGS)'
216         @echo '  STLD       = $(STLD)'
217         @echo '  STLD_FLAGS = $(STLD_FLAGS)'
218         @echo '  SHLD       = $(SHLD)'
219         @echo '  SHLD_FLAGS = $(SHLD_FLAGS)'
220         @echo '  MDLD       = $(MDLD)'
221         @echo '  MDLD_FLAGS = $(MDLD_FLAGS)'
222         @echo '  SHLIBEXT   = $(SHLIBEXT)'
223
224 etags:
225         etags `find $(srcdir) -name "*.[ch]"`
226
227 ctags:
228         ctags `find $(srcdir) -name "*.[ch]"`