UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / autoconf / targets.mak
blobb2dce8fd44b0c28226dc571d7deeb9e27476051e
1 # Pull in autoconf variables
2 include $(topdir)/autoconf/variables.mak
4 # Now that we have autoconf vars, overwrite $(topdir) with absolute path
5 # version instead of relative version we inherited. The easy way to do this
6 # would be to use $(abspath $(topdir)), but abspath is a gmake-3.81 feature.
7 # So we let autoconf figure it out for us.
8 topdir := $(abstopdir)
10 # Older (pre-3.79) gmake does not have $(CURDIR)
11 ifeq ($(CURDIR),)
12 CURDIR := $(shell pwd)
13 endif
15 # By default we do pretty-printing only
16 V := @
17 VV := @
18 NPD := --no-print-directory
20 # Check verbose flag
21 ifeq ($(strip $(VERBOSE)),1)
22 V :=
23 NPD :=
24 endif
25 ifeq ($(strip $(VERBOSE)),2)
26 V :=
27 VV :=
28 NPD :=
29 endif
31 # Relative path to this dir from $(topdir)
32 RELDIR := $(patsubst /%,%,$(subst $(topdir),,$(CURDIR)))
33 ifneq ($(strip $(RELDIR)),)
34 RELDIR := $(RELDIR)/
35 endif
37 # Strip extensions
38 STRIPEXT = $(foreach file,$(1),$(basename $(file)))
40 # Convert a list of sources to a list of objects in OBJDIR
41 SRC2OBJ = $(foreach obj,$(call STRIPEXT,$(1)),$(dir $(obj))$(OBJDIR)/$(notdir $(obj)).o)
43 # All objects, derived from all sources
44 OBJS = $(call SRC2OBJ,$(SRCS))
46 # Dependency files, derived from all sources
47 DEPS = $(foreach dep,$(call STRIPEXT,$(SRCS)),$(DEPDIR)/$(dep).P)
49 # Default target: Build all subdirs, then reinvoke make to build local
50 # targets. This is a little gross, but necessary to force make to build
51 # subdirs first when running in parallel via 'make -jN'. Hopefully I will
52 # discover a cleaner way to solve this someday.
53 .PHONY: all
54 all: all-subdirs
55 $(VV)+$(MAKE) $(NPD) all-targets
57 # 'all-targets' is supplied by lower level Makefile. It represents
58 # all targets to be built at that level. We list it here with a do-nothing
59 # action in order to suppress the "Nothing to do for all-targets" message
60 # when all targets are up to date.
61 .PHONY: all-targets
62 all-targets:
65 # standard install target: Same logic as 'all'.
66 .PHONY: install
67 install: all-subdirs
68 $(VV)+$(MAKE) $(NPD) all-targets
69 $(VV)+$(MAKE) $(NPD) all-install
71 # 'all-install' is extended by lower-level Makefile to perform any
72 # required install actions.
73 .PHONY: all-install
74 all-install:
77 # no-op targets for use by lower-level Makefiles when a particular
78 # component is not being installed.
79 .PHONY: install- uninstall-
80 install-:
81 uninstall-:
83 # standard uninstall target: Depends on subdirs to force recursion,
84 # then reinvokes make to uninstall local targets. Same logic as 'install'.
85 .PHONY: uninstall
86 uninstall: all-subdirs
87 $(VV)+$(MAKE) $(NPD) all-uninstall
89 # 'all-uninstall' is extended by lower-level Makefiles to perform
90 # any required uninstall actions.
91 .PHONY: all-uninstall
92 all-uninstall:
95 # Typical clean target: Remove all objects and dependency files.
96 .PHONY: clean
97 clean:
98 $(V)find . -depth \
99 \( -name $(OBJDIR) -o -name $(DEPDIR) -o -name \*.a \) \
100 -exec $(ECHO) " CLEAN" \{\} \; -exec $(RMF) \{\} \;
102 # Template rule to build a subdirectory
103 .PHONY: %_DIR
104 %_DIR:
105 @$(ECHO) " " $(RELDIR)$*
106 $(VV)+$(MAKE) -C $* $(NPD) $(MAKECMDGOALS)
108 # Collective all-subdirs target depends on subdir rule
109 .PHONY: all-subdirs
110 all-subdirs: $(foreach subdir,$(SUBDIRS),$(subdir)_DIR)
112 # Echo with no newline
113 # Pipline here is silly, but should be more portable
114 # than 'echo -n' or 'echo ...\c'. Cannot use autoconf
115 # to figure this out since 'make install' may be run
116 # with root's shell when ./configure was run with user's
117 # shell. Could also use 'printf' but not certain how
118 # universal that is.
119 define ECHO_N
120 $(ECHO) $(1) | tr -d '\n'
121 endef
123 # How to build dependencies
124 MAKEDEPEND = $(CC) -M $(CPPFLAGS) $< > $(df).d
125 ifeq ($(strip $(NODEPS)),)
126 define DEPENDS
127 if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi; \
128 $(MAKEDEPEND); \
129 $(call ECHO_N,$(OBJDIR)/) > $(df).P; \
130 $(SED) -e 's/#.*//' -e '/^$$/ d' < $(df).d >> $(df).P; \
131 $(SED) -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
132 -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
133 $(RMF) $(df).d
134 endef
135 else
136 DEPENDS :=
137 endif
139 # Rule to build *.o from *.c and generate dependencies for it
140 $(OBJDIR)/%.o: %.c
141 @$(ECHO) " CXX " $(RELDIR)$<
142 $(VV)if test ! -d $(OBJDIR); then mkdir -p $(OBJDIR); fi
143 $(V)$(CXX) $(CXXFLAGS) -c -o $@ $<
144 $(VV)$(DEPENDS)
146 # Rule to build *.o from *.cpp and generate dependencies for it
147 $(OBJDIR)/%.o: %.cpp
148 @$(ECHO) " CXX " $(RELDIR)$<
149 $(VV)if test ! -d $(OBJDIR); then mkdir -p $(OBJDIR); fi
150 $(V)$(CXX) $(CXXFLAGS) -c -o $@ $<
151 $(VV)$(DEPENDS)
153 # Rule to build *.o from *.m and generate dependencies for it
154 $(OBJDIR)/%.o: %.m
155 @$(ECHO) " OBJC " $(RELDIR)$<
156 $(VV)if test ! -d $(OBJDIR); then mkdir -p $(OBJDIR); fi
157 $(V)$(OBJC) $(OBJCFLAGS) -c -o $@ $<
158 $(VV)$(DEPENDS)
160 # Rule to link an executable
161 define LINK
162 @$(ECHO) " LD " $(RELDIR)$@
163 $(V)$(LD) $(LDFLAGS) $^ -o $@ $(LIBS)
164 endef
166 # Rule to generate an archive (library)
167 MAKELIB=$(call ARCHIVE,$@,$(OBJS))
168 define ARCHIVE
169 @$(ECHO) " AR " $(RELDIR)$(1)
170 $(VV)$(RMF) $(1)
171 $(V)$(AR) rc $(1) $(2)
172 $(V)$(RANLIB) $(1)
173 endef
175 # How to generate a *.nib from a *.xib
176 %.nib: %.xib
177 @$(ECHO) " NIB " $(RELDIR)$<
178 $(VV)if test ! -d $(OBJDIR); then mkdir -p $(OBJDIR); fi
179 $(V)$(NIB) $(NIBFLAGS) --compile $@ $<
181 # Rule to create a directory during install
182 define MKDIR
183 $(if $(wildcard $(DESTDIR)$(1)),, \
184 @$(ECHO) " MKDIR" $(DESTDIR)$(1))
185 $(if $(wildcard $(DESTDIR)$(1)),, \
186 $(V)$(MKINSTALLDIRS) $(DESTDIR)$(1))
187 endef
189 # Install a program file, given mode, src, and dest
190 define INSTPROG
191 @$(ECHO) " COPY " $(2) =\> $(DESTDIR)$(3)
192 $(V)$(INSTALL_PROGRAM) $(STRIP) -m $(1) $(2) $(DESTDIR)$(3)
193 endef
195 # Install a data file, given mode, src, and dest
196 define INSTDATA
197 @$(ECHO) " COPY " $(2) =\> $(DESTDIR)$(3)
198 $(V)$(INSTALL_DATA) -m $(1) $(2) $(DESTDIR)$(3)
199 endef
201 # Install a data file, given mode, src, and dest.
202 # Existing dest file is preserved; new file is named *.new if dest exists.
203 define INSTNEW
204 @$(ECHO) " COPY " $(notdir $(2)) =\> $(DESTDIR)$(3)/$(notdir $(2))$(if $(wildcard $(DESTDIR)$(3)/$(notdir $(2))),.new,)
205 $(V)$(INSTALL_DATA) -m $(1) $(2) $(DESTDIR)$(3)/$(notdir $(2))$(if $(wildcard $(DESTDIR)$(3)/$(notdir $(2))),.new,)
206 endef
208 # Install a data file, given mode, src, and dest.
209 # Existing dest file is renamed to *.orig if it exists.
210 define INSTORIG
211 $(if $(wildcard $(DESTDIR)$(3)/$(notdir $(2))), \
212 @$(ECHO) " MV " $(DESTDIR)$(3)/$(notdir $(2)) =\> \
213 $(DESTDIR)$(3)/$(notdir $(2)).orig,)
214 $(if $(wildcard $(DESTDIR)$(3)/$(notdir $(2))), \
215 $(V)$(MV) $(DESTDIR)$(3)/$(notdir $(2)) $(DESTDIR)$(3)/$(notdir $(2)).orig,)
216 @$(ECHO) " COPY " $(notdir $(2)) =\> $(DESTDIR)$(3)/$(notdir $(2))
217 $(V)$(INSTALL_SCRIPT) -m $(1) $(2) $(DESTDIR)$(3)
218 endef
220 # Make a symlink
221 define SYMLINK
222 @$(ECHO) " LN " $(DESTDIR)/$(2) -\> $(1)
223 $(V)$(LN) -sf $(1) $(DESTDIR)/$(2)
224 endef
226 # Copy a file
227 define COPY
228 @$(ECHO) " CP " $(1) =\> $(DESTDIR)/$(2)
229 $(V)$(CP) -fR $(1) $(DESTDIR)/$(2)
230 endef
232 # Uninstall a file
233 define UNINST
234 @$(ECHO) " RM " $(DESTDIR)$(1)
235 $(V)$(RMF) $(DESTDIR)$(1)
236 endef
238 # Announce distro install
239 define DISTINST
240 @$(ECHO) " ------------------------------------------------------------"
241 @$(ECHO) " $(1) distribution installation"
242 @$(ECHO) " ------------------------------------------------------------"
243 endef
245 # Announce distro uninstall
246 define DISTUNINST
247 @$(ECHO) " ------------------------------------------------------------"
248 @$(ECHO) " $(1) distribution uninstall"
249 @$(ECHO) " ------------------------------------------------------------"
250 endef
252 # If DESTDIR is set, we do no chkconfig processing
253 ifeq ($(DESTDIR),)
254 define CHKCFG
255 $(if $(wildcard $(2)),@$(ECHO) " CKCFG" $(1):$(2))
256 $(if $(wildcard $(2)),$(V)$(CHKCONFIG) --$(1) apcupsd)
257 endef
258 endif
260 # How to massage dependency list from rst2html
261 ifeq ($(strip $(NODEPS)),)
262 define RSTDEPENDS
263 $(ECHO) $@: $< \\ > $(df).P; \
264 $(SED) -e '$$q' -e 's/^.*$$/& \\/' < $(df).d >> $(df).P; \
265 $(ECHO) $<: >> $(df).P; \
266 $(SED) -e 's/^.*$$/&:/' < $(df).d >> $(df).P; \
267 $(RMF) $(df).d
268 endef
269 else
270 RSTDEPENDS :=
271 endif
273 # Build *.html from *.rst and generate dependencies for it
274 %.html: %.rst
275 @$(ECHO) " HTML " $<
276 ifneq ($(strip $(RST2HTML)),)
277 $(VV)if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi;
278 $(V)$(RST2HTML) $(RST2HTMLOPTS) $< $@
279 $(VV)$(RSTDEPENDS)
280 else
281 @$(ECHO) "--> Not building HTML due to missing rst2html"
282 endif
284 # Build *.pdf from *.rst
285 %.pdf: %.rst
286 @$(ECHO) " PDF " $<
287 ifneq ($(strip $(RST2PDF)),)
288 $(V)$(RST2PDF) $(RST2PDFOPTS) -o $@ $<
289 else
290 @$(ECHO) "--> Not building PDF due to missing rst2pdf"
291 endif
293 # Format a manpage into plain text
294 define MANIFY
295 @$(ECHO) " MAN " $(1) -\> $(2)
296 $(V)man ./$(1) | col -b > $(2)
297 endef