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.
10 # Older (pre-3.79) gmake does not have $(CURDIR)
12 CURDIR
:= $(shell pwd
)
15 # By default we do pretty-printing only
18 NPD
:= --no-print-directory
21 ifeq ($(strip $(VERBOSE
)),1)
25 ifeq ($(strip $(VERBOSE
)),2)
31 # Relative path to this dir from $(topdir)
32 RELDIR
:= $(patsubst /%,%,$(subst $(topdir
),,$(CURDIR
)))
33 ifneq ($(strip $(RELDIR
)),)
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.
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.
65 # standard install target: Same logic as 'all'.
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.
77 # no-op targets for use by lower-level Makefiles when a particular
78 # component is not being installed.
79 .PHONY
: install- uninstall-
83 # standard uninstall target: Depends on subdirs to force recursion,
84 # then reinvokes make to uninstall local targets. Same logic as 'install'.
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.
95 # Typical clean target: Remove all objects and dependency files.
99 \
( -name
$(OBJDIR
) -o
-name
$(DEPDIR
) -o
-name \
*.a \
) \
100 -exec
$(ECHO
) " CLEAN" \
{\
} \
; -exec
$(RMF
) \
{\
} \
;
102 # Template rule to build a subdirectory
105 @
$(ECHO
) " " $(RELDIR
)$*
106 $(VV
)+$(MAKE
) -C
$* $(NPD
) $(MAKECMDGOALS
)
108 # Collective all-subdirs target depends on subdir rule
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
120 $(ECHO
) $(1) | tr
-d
'\n'
123 # How to build dependencies
124 MAKEDEPEND
= $(CC
) -M
$(CPPFLAGS
) $< > $(df
).d
125 ifeq ($(strip $(NODEPS
)),)
127 if
test ! -d
$(DEPDIR
); then mkdir
-p
$(DEPDIR
); fi
; \
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
; \
139 # Rule to build *.o from *.c and generate dependencies for it
141 @
$(ECHO
) " CXX " $(RELDIR
)$<
142 $(VV
)if
test ! -d
$(OBJDIR
); then mkdir
-p
$(OBJDIR
); fi
143 $(V
)$(CXX
) $(CXXFLAGS
) -c
-o
$@
$<
146 # Rule to build *.o from *.cpp and generate dependencies for it
148 @
$(ECHO
) " CXX " $(RELDIR
)$<
149 $(VV
)if
test ! -d
$(OBJDIR
); then mkdir
-p
$(OBJDIR
); fi
150 $(V
)$(CXX
) $(CXXFLAGS
) -c
-o
$@
$<
153 # Rule to build *.o from *.m and generate dependencies for it
155 @
$(ECHO
) " OBJC " $(RELDIR
)$<
156 $(VV
)if
test ! -d
$(OBJDIR
); then mkdir
-p
$(OBJDIR
); fi
157 $(V
)$(OBJC
) $(OBJCFLAGS
) -c
-o
$@
$<
160 # Rule to link an executable
162 @
$(ECHO
) " LD " $(RELDIR
)$@
163 $(V
)$(LD
) $(LDFLAGS
) $^
-o
$@
$(LIBS
)
166 # Rule to generate an archive (library)
167 MAKELIB
=$(call ARCHIVE
,$@
,$(OBJS
))
169 @
$(ECHO
) " AR " $(RELDIR
)$(1)
171 $(V
)$(AR
) rc
$(1) $(2)
175 # How to generate a *.nib from a *.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
183 $(if
$(wildcard $(DESTDIR
)$(1)),, \
184 @
$(ECHO
) " MKDIR" $(DESTDIR
)$(1))
185 $(if
$(wildcard $(DESTDIR
)$(1)),, \
186 $(V
)$(MKINSTALLDIRS
) $(DESTDIR
)$(1))
189 # Install a program file, given mode, src, and dest
191 @
$(ECHO
) " COPY " $(2) =\
> $(DESTDIR
)$(3)
192 $(V
)$(INSTALL_PROGRAM
) $(STRIP
) -m
$(1) $(2) $(DESTDIR
)$(3)
195 # Install a data file, given mode, src, and dest
197 @
$(ECHO
) " COPY " $(2) =\
> $(DESTDIR
)$(3)
198 $(V
)$(INSTALL_DATA
) -m
$(1) $(2) $(DESTDIR
)$(3)
201 # Install a data file, given mode, src, and dest.
202 # Existing dest file is preserved; new file is named *.new if dest exists.
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
,)
208 # Install a data file, given mode, src, and dest.
209 # Existing dest file is renamed to *.orig if it exists.
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)
222 @
$(ECHO
) " LN " $(DESTDIR
)/$(2) -\
> $(1)
223 $(V
)$(LN
) -sf
$(1) $(DESTDIR
)/$(2)
228 @
$(ECHO
) " CP " $(1) =\
> $(DESTDIR
)/$(2)
229 $(V
)$(CP
) -fR
$(1) $(DESTDIR
)/$(2)
234 @
$(ECHO
) " RM " $(DESTDIR
)$(1)
235 $(V
)$(RMF
) $(DESTDIR
)$(1)
238 # Announce distro install
240 @
$(ECHO
) " ------------------------------------------------------------"
241 @
$(ECHO
) " $(1) distribution installation"
242 @
$(ECHO
) " ------------------------------------------------------------"
245 # Announce distro uninstall
247 @
$(ECHO
) " ------------------------------------------------------------"
248 @
$(ECHO
) " $(1) distribution uninstall"
249 @
$(ECHO
) " ------------------------------------------------------------"
252 # If DESTDIR is set, we do no chkconfig processing
255 $(if
$(wildcard $(2)),@
$(ECHO
) " CKCFG" $(1):$(2))
256 $(if
$(wildcard $(2)),$(V
)$(CHKCONFIG
) --$(1) apcupsd
)
260 # How to massage dependency list from rst2html
261 ifeq ($(strip $(NODEPS
)),)
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
; \
273 # Build *.html from *.rst and generate dependencies for it
276 ifneq ($(strip $(RST2HTML
)),)
277 $(VV
)if
test ! -d
$(DEPDIR
); then mkdir
-p
$(DEPDIR
); fi
;
278 $(V
)$(RST2HTML
) $(RST2HTMLOPTS
) $< $@
281 @
$(ECHO
) "--> Not building HTML due to missing rst2html"
284 # Build *.pdf from *.rst
287 ifneq ($(strip $(RST2PDF
)),)
288 $(V
)$(RST2PDF
) $(RST2PDFOPTS
) -o
$@
$<
290 @
$(ECHO
) "--> Not building PDF due to missing rst2pdf"
293 # Format a manpage into plain text
295 @
$(ECHO
) " MAN " $(1) -\
> $(2)
296 $(V
)man .
/$(1) | col
-b
> $(2)