Bug 1004: NEWS and AUTHORS
[elinks.git] / Makefile.lib
blob644955f085229ffdb817b2b6f52a9d097d68f1bf
1 ### The build commands and verbosity
3 # Colorize the build.
4 ifdef MAKE_COLOR
5         INFO_COLOR    = $(shell tput setaf 5)
6         CC_COLOR      = $(shell tput setaf 6)
7         LD_COLOR      = $(shell tput setaf 2)
8         PO_COLOR      = $(shell tput setaf 6)
9         LINK_COLOR    = $(shell tput bold;tput setaf 4)
10         INSTALL_COLOR = $(shell tput setaf 3)
11         END_COLOR     = $(shell tput sgr0)
12 endif
14 # sparse is architecture-neutral, which means that we need to tell it
15 # explicitly what architecture to check for. Fix this up for yours..
16 SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
19 #############################################################################
20 # Build recipies
22 # If we are verbose, we will show the "real" cmds instead of
23 # their quiet versions (which are used in the non-verbose mode).
24 # Inspired by the Linux kernel build system.
25 ifdef V
26         quiet =
27         mquiet = masq_
28 else
29         quiet = quiet_
30         mquiet = quiet_
31 endif
33 # Show the command (quiet or non-quiet version based on the assignment
34 # just above) and then execute it.
35 ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
36 cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
37 mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
38 ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
40 quiet_cmd_compile = '      [$(CC_COLOR)CC$(END_COLOR)]   $(RELPATH)$@'
41  masq_cmd_compile = $(COMPILE) -o $(@) -c $< $(2)
42       cmd_compile = $(COMPILE) -o $(@) -Wp,-MD,.deps/$(*F).pp -c $< $(2)
44 # Rule to compile a set of .o files into one .o file
45 quiet_cmd_ld_objs = "      [$(LD_COLOR)LD$(END_COLOR)]   $(RELPATH)$@"
46       cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^) \
47                     $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
48                             `test -e $(subdir)/$(LIB_O_NAME) && echo $(subdir)/$(LIB_O_NAME)`)
50    quiet_cmd_link = '    [$(LINK_COLOR)LINK$(END_COLOR)]   $(RELPATH)$@'
51          cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
53  quiet_cmd_sparse = '    [SPARSE]   $(RELPATH)$(2)'
54        cmd_sparse = $(SPARSE) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(SPARSE_FLAGS) $(2)
56 # Recursive make
57 quiet_cmd_recmake = "[$(INFO_COLOR)MAKE $(3)$(END_COLOR)]   $(RELPATH)$(2)"
58       cmd_recmake = $(MAKE) -C $(2) $(3)
60 quiet_cmd_installdata = "     [$(INSTALL_COLOR)INSTALL$(END_COLOR)]   $(RELPATH)$(2) -> $(3)"
61       cmd_installdata = $(INSTALL_DATA) $(2) $(3)
63 quiet_cmd_installprog = "     [$(INSTALL_COLOR)INSTALL$(END_COLOR)]   $(RELPATH)$(2) -> $(3)"
64       cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
67 #############################################################################
68 # Special handling of conditional variables
70 SUBDIRS += $(SUBDIRS-yes)
71 OBJS    += $(OBJS-yes)
73 ALTDIRS  = $(SUBDIRS-no) $(SUBDIRS-)
74 ALTOBJS  = $(OBJS-no) $(OBJS-)
76 ifneq ($(findstring cleanall,$(MAKECMDGOALS)),)
77 INCLUDE_ALL=1
78 endif
80 ifneq ($(findstring init,$(MAKECMDGOALS)),)
81 INCLUDE_ALL=1
82 ifndef SRC
83 SRC = $(shell cd $(top_srcdir) && pwd)
84 endif
85 endif
87 ifdef INCLUDE_ALL
88 SUBDIRS += $(ALTDIRS)
89 OBJS    += $(ALTOBJS)
90 endif
93 #############################################################################
94 # Internal build rules
96 # All files in $(OBJS) and any $(subdir)/lib.o are linked into lib.o.
97 # Sort them to filter out duplicated and get uniform order.
98 LIB_O_DEPS = \
99  $(sort $(filter-out $(LIB_O_NAME),$(OBJS))) \
100  $(foreach subdir,$(sort $(SUBDIRS)),$(wildcard $(subdir)/$(LIB_O_NAME)))
102 $(LIB_O_NAME): $(LIB_O_DEPS)
103         $(call cmd,ld_objs)
105 DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
106 DEP_FILES = $(DEP_FILES_1:%.o=%.P)
107 DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
109 ifneq ($(strip $(OBJS)),)
110 -include $(DEP_FILES)
111 ALL_OBJS = $(LIB_O_DEPS) $(LIB_O_NAME)
112 endif
114 %.o: $(srcdir)%.c
115         $(call mcmd,compile)
116         @-if test -e .deps/$(*F).pp; then \
117                 cp .deps/$(*F).pp .deps/$(*F).P; \
118                 tr ' ' '\012' < .deps/$(*F).pp \
119                         | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
120                         >> .deps/$(*F).P; \
121                 rm .deps/$(*F).pp; \
122         fi
124 CLEAN += $(PROG) $(OBJS)
127 #############################################################################
128 # The main default rules
130 all-default: $(ALL_OBJS) $(PROGS) $(MAN1) $(MAN5)
132 # Ensure that Makefiles in subdirs are created before we recursive into them
133 init-recursive: init-default
135 init-default:
136         @$(foreach subdir,$(sort $(SUBDIRS)), \
137                 $(MKINSTALLDIRS) $(subdir) >/dev/null; \
138                 test -e "$(subdir)/Makefile" \
139                 || echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;)
141 clean-default cleanall-default:
142         @-test -z "$(CLEAN)" || $(RM) $(CLEAN)
144 check-default:
145 ifneq ($(SPARSE),)
146         @$(foreach file, $(wildcard *.c), \
147                 $(call ncmd,sparse,$(file));)
148 endif
150 install-default: all-default
151 ifdef PROGS
152         @$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
153         @$(foreach file,$(PROGS), \
154                 $(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
155 endif
156 ifdef MAN1
157         @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
158         @$(foreach file,$(MAN1), \
159                 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
160 endif
161 ifdef MAN5
162         @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
163         @$(foreach file,$(MAN5), \
164                 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);)
165 endif
167 ##############################################################################
168 # Auto-testing infrastructure
170 test-default:
172 ifdef TEST_PROGS
173 TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o
174 TESTDEPS += $(TESTDEPS-yes)
176 TEST_LIB=$(top_srcdir)/test/libtest.sh
177 export TEST_LIB
179 # This does the work for the next rule. It is a very general rule
180 # but as long as we don't put test programs in src/ it should work.
181 %: %.o $(TESTDEPS)
182         $(call cmd,link)
184 $(TEST_PROGS): $(addsuffix .o,$(TEST_PROGS)) $(TESTDEPS)
186 TESTS = $(wildcard $(srcdir)test-*)
188 $(TESTS): $(TEST_PROGS)
189         @echo "*** $(notdir $@) ***"; \
190         $(call shellquote,$(SHELL)) $@ $(TEST_OPTS)
192 test-default: $(TESTS)
194 clean-test:
195         @rm -fr trash
197 CLEAN += $(TEST_PROGS) $(addsuffix .o,$(TEST_PROGS))
198 clean-default: clean-test
199 endif
201 .PHONY: $(TESTS)
202 .NOPARALLEL:
205 #############################################################################
206 # Basic recursion and dependencies setup
208 RULES    = all install clean cleanall init check test
210 RULES_LOCAL = $(addsuffix -local,$(RULES))
211 RULES_REC   = $(addsuffix -recursive,$(RULES))
213 .PHONY: $(RULES) $(RULES_LOCAL) $(RULES_REC) $(addsuffix -default,$(RULES))
215 # The -recursive rules decend all subdirs.
216 $(RULES_REC):
217         @$(foreach subdir,$(sort $(SUBDIRS)), \
218                 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
220 # Dummy -local rules
221 $(RULES_LOCAL):
223 # Default deps
224 rule_deps = $(1)-recursive $(1)-default $(1)-local
225 all:      $(call rule_deps,all)
226 install:  $(call rule_deps,install)
227 clean:    $(call rule_deps,clean)
228 cleanall: $(call rule_deps,cleanall)
229 init:     $(call rule_deps,init)
230 check:    $(call rule_deps,check)
231 test:     $(call rule_deps,test)
233 #############################################################################
234 # Misc
236 # Tell versions [3.59,3.63) of GNU make to not export all variables.
237 # Otherwise a system limit (for SysV at least) may be exceeded.
238 .NOEXPORT:
240 # Shell quote;
241 # Result of this needs to be placed inside ''
242 # XXX: Placed here because Vim cannot highlight things right afterwards
243 shq = $(subst ','\'',$(1))
244 # This has surrounding ''
245 shellquote = '$(call shq,$(1))'
247 # vim:syntax=make