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