Clean up data.mk file in distclean.
[samba.git] / source4 / 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 include/config.h:
41         @echo "include/config.h not present"
42         @echo "You need to rerun ./autogen.sh and ./configure"
43         @/bin/false
44
45 $(srcdir)/version.h: $(srcdir)/VERSION
46         @$(SHELL) script/mkversion.sh VERSION $(srcdir)/version.h $(srcdir)/
47
48 regen_version::
49         @$(SHELL) script/mkversion.sh VERSION $(srcdir)/version.h $(srcdir)/
50
51 clean_pch::
52         @echo "Removing precompiled headers"
53         @-rm -f include/includes.h.gch
54
55 pch:: clean_pch include/includes.h.gch
56
57 clean:: clean_pch
58         @echo Removing objects
59         @-find . -name '*.o' -exec rm -f '{}' \;
60         @echo Removing hostcc objects
61         @-find . -name '*.ho' -exec rm -f '{}' \;
62         @echo Removing binaries
63         @-rm -f $(BIN_PROGS) $(SBIN_PROGS) $(BINARIES) $(TORTURE_PROGS)
64         @echo Removing libraries
65         @-rm -f $(STATIC_LIBRARIES) $(SHARED_LIBRARIES)
66         @-rm -f bin/static/*.a bin/shared/*.$(SHLIBEXT)
67         @echo Removing modules
68         @-rm -f bin/modules/*/*.$(SHLIBEXT)
69         @-rm -f bin/*_init_module.c
70         @echo Removing dummy targets
71         @-rm -f bin/.*_*
72         @echo Removing generated files
73         @-rm -f bin/*_init_module.c
74         @-rm -rf librpc/gen_* 
75         @echo Removing proto headers
76         @-rm -f $(PROTO_HEADERS)
77
78 distclean:: clean
79         -rm -f include/config.h include/config_tmp.h include/build.h
80         -rm -f data.mk
81         -rm -f config.status
82         -rm -f config.log config.cache
83         -rm -f config.pm config.mk
84         -rm -f $(PC_FILES)
85
86 removebackup::
87         -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
88
89 realdistclean:: distclean removebackup
90         -rm -f include/config_tmp.h.in
91         -rm -f version.h
92         -rm -f configure
93         -rm -f $(MANPAGES)
94
95 check:: test
96
97 unused_macros:
98         $(srcdir)/script/find_unused_macros.pl `find . -name "*.[ch]"` | sort
99
100 ###############################################################################
101 # File types
102 ###############################################################################
103
104 .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
105
106 .c.d:
107         @echo "Generating dependencies for $<"
108         @$(DEPENDS)
109
110 .c.hd:
111         @echo "Generating host-compiler dependencies for $<"
112         @$(HDEPENDS)
113
114 include/includes.d: include/includes.h
115         @echo "Generating dependencies for $<"
116         @$(PCHDEPENDS)
117
118 .c.o:
119         @if test -n "$(CC_CHECKER)"; then \
120                 echo "Checking  $< with '$(CC_CHECKER)'"; \
121                 $(CHECK) ; \
122         fi
123         @echo "Compiling $<"
124         @-mkdir -p `dirname $@`
125         @$(COMPILE) && exit 0 ; \
126                 echo "The following command failed:" 1>&2;\
127                 echo "$(COMPILE)" 1>&2;\
128                 $(COMPILE) >/dev/null 2>&1
129
130 .c.ho:
131         @echo "Compiling $< with host compiler"
132         @-mkdir -p `dirname $@`
133         @$(HCOMPILE) && exit 0;\
134                 echo "The following command failed:" 1>&2;\
135                 echo "$(HCOMPILE)" 1>&2;\
136                 $(HCOMPILE) >/dev/null 2>&1
137
138 .h.h.gch:
139         @echo "Precompiling $<"
140         @$(PCHCOMPILE)
141
142 .y.c:
143         @echo "Building $< with $(YACC)"
144         @-$(srcdir)/script/yacc_compile.sh "$(YACC)" "$<" "$@"
145
146 .l.c:
147         @echo "Building $< with $(LEX)"
148         @-$(srcdir)/script/lex_compile.sh "$(LEX)" "$<" "$@"
149
150 DOCBOOK_MANPAGE_URL = http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
151
152 .1.xml.1:
153         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
154
155 .3.xml.3:
156         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
157
158 .5.xml.5:
159         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
160
161 .7.xml.7:
162         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
163
164 .8.xml.8:
165         $(XSLTPROC) -o $@ $(DOCBOOK_MANPAGE_URL) $<
166
167 DEP_FILES = $(patsubst %.ho,%.hd,$(patsubst %.o,%.d,$(ALL_OBJS))) \
168                    include/includes.d
169
170 dist:: idl_full manpages configure distclean 
171
172 configure: 
173         ./autogen.sh
174
175 showflags::
176         @echo 'Samba will be compiled with flags:'
177         @echo '  CPP        = $(CPP)'
178         @echo '  CPPFLAGS   = $(CPPFLAGS)'
179         @echo '  CC         = $(CC)'
180         @echo '  CFLAGS     = $(CFLAGS)'
181         @echo '  PICFLAG    = $(PICFLAG)'
182         @echo '  BNLD       = $(BNLD)'
183         @echo '  BNLD_FLAGS = $(BNLD_FLAGS)'
184         @echo '  STLD       = $(STLD)'
185         @echo '  STLD_FLAGS = $(STLD_FLAGS)'
186         @echo '  SHLD       = $(SHLD)'
187         @echo '  SHLD_FLAGS = $(SHLD_FLAGS)'
188         @echo '  MDLD       = $(MDLD)'
189         @echo '  MDLD_FLAGS = $(MDLD_FLAGS)'
190         @echo '  SHLIBEXT   = $(SHLIBEXT)'
191
192 etags:
193         etags `find $(srcdir) -name "*.[ch]"`
194
195 ctags:
196         ctags `find $(srcdir) -name "*.[ch]"`