#include dom/node.h instead of dom/stack.h
[elinks.git] / Makefile.lib
blob7fcd01f438553b86c7b3d54812a0ee1c25aa92e5
1 ### The build commands and verbosity
3 # If we are verbose, we will show commands prefixed by $(Q) (which acts as
4 # @ in the non-verbose mode), and we will show the "real" cmds instead of
5 # their quiet versions (which are used in the non-verbose mode).
6 # Inspired by the Linux kernel build system.
7 ifdef V
8         Q =
9         quiet =
10         mquiet = masq_
11 else
12         Q = @
13         quiet = quiet_
14         mquiet = quiet_
15 endif
17 # Colorize the build.
18 ifdef MAKE_COLOR
19         INFO_COLOR    = $(shell tput setaf 5)
20         CC_COLOR      = $(shell tput setaf 6)
21         LD_COLOR      = $(shell tput setaf 2)
22         PO_COLOR      = $(shell tput setaf 6)
23         LINK_COLOR    = $(shell tput bold;tput setaf 4)
24         INSTALL_COLOR = $(shell tput setaf 3)
25         END_COLOR     = $(shell tput sgr0)
26 endif
28 # Show the command (quiet or non-quiet version based on the assignment
29 # just above) and then execute it.
30 ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
31 cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
32 mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
33 ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
35 quiet_cmd_compile = '      [$(CC_COLOR)CC$(END_COLOR)]   $(RELPATH)$@'
36  masq_cmd_compile = $(COMPILE) -c $<
37       cmd_compile = $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
39 # Rule to compile a set of .o files into one .o file
40 quiet_cmd_ld_objs = "      [$(LD_COLOR)LD$(END_COLOR)]   $(RELPATH)$@"
41       cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^) \
42                     $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
43                             `test -e $(subdir)/$(LIB_O_NAME) && echo $(subdir)/$(LIB_O_NAME)`)
45    quiet_cmd_link = '    [$(LINK_COLOR)LINK$(END_COLOR)]   $(RELPATH)$@'
46          cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
48  quiet_cmd_sparse = '    [SPARSE]   $(RELPATH)$(2)'
49        cmd_sparse = $(SPARSE) $(DEFS) $(INCLUDES) $(AM_CFLAGS) $(CFLAGS) $(SPARSE_FLAGS) $(2)
51 # Recursive make
52 quiet_cmd_recmake = "[$(INFO_COLOR)MAKE $(3)$(END_COLOR)]   $(RELPATH)$(2)"
53       cmd_recmake = $(MAKE) -C $(2) $(3)
55 quiet_cmd_installdata = "     [$(INSTALL_COLOR)INSTALL$(END_COLOR)]   $(RELPATH)$(2) -> $(3)"
56       cmd_installdata = $(INSTALL_DATA) $(2) $(3)
58 quiet_cmd_installprog = "     [$(INSTALL_COLOR)INSTALL$(END_COLOR)]   $(RELPATH)$(2) -> $(3)"
59       cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
62 ### Internal build rules
64 DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
65 DEP_FILES = $(DEP_FILES_1:%.o=%.P)
67 DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
69 ifdef OBJS
70 -include $(DEP_FILES)
71 endif
73 %.o: $(srcdir)%.c
74         $(call mcmd,compile)
75         @-if test -e .deps/$(*F).pp; then \
76                 cp .deps/$(*F).pp .deps/$(*F).P; \
77                 tr ' ' '\012' < .deps/$(*F).pp \
78                         | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
79                         >> .deps/$(*F).P; \
80                 rm .deps/$(*F).pp; \
81         fi
83 ifdef SUBDIRS-yes
84 SUBDIRS += $(SUBDIRS-yes)
85 endif
87 ifdef OBJS-yes
88 OBJS += $(OBJS-yes)
89 endif
91 ifneq ($(findstring cleanall,$(MAKECMDGOALS)),)
92 INCLUDE_ALL=1
93 endif
95 ifneq ($(findstring init,$(MAKECMDGOALS)),)
96 INCLUDE_ALL=1
97 ifndef SRC
98 SRC = $(shell cd $(top_srcdir) && pwd)
99 endif
100 endif
102 ifdef INCLUDE_ALL
103 ifdef SUBDIRS-no
104 SUBDIRS += $(SUBDIRS-no)
105 endif
106 ifdef SUBDIRS-
107 SUBDIRS += $(SUBDIRS-)
108 endif
109 ifdef OBJS-no
110 OBJS += $(OBJS-no)
111 endif
112 ifdef OBJS-
113 OBJS += $(OBJS-)
114 endif
116 endif
119 ifdef OBJS
120 $(LIB_O_NAME): $(sort $(OBJS)) $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), $(wildcard $(subdir)/$(LIB_O_NAME)))
121         $(call cmd,ld_objs)
123 LIB_O = $(LIB_O_NAME)
124 CLEAN += $(OBJS) $(LIB_O)
125 endif
127 CLEAN += $(PROG)
129 all-default: $(LIB_O) $(PROGS) $(MAN1) $(MAN5)
131 init-default:
132         @$(foreach subdir,$(sort $(SUBDIRS)), \
133                 $(MKINSTALLDIRS) $(subdir) >/dev/null; \
134                 test -e "$(subdir)/Makefile" \
135                 || echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;)
137 clean-default cleanall-default:
138         @-test -z "$(CLEAN)" || $(RM) $(CLEAN)
140 check-default:
141 ifneq ($(SPARSE),)
142         @$(foreach file, $(wildcard *.c), \
143                 $(call ncmd,sparse,$(file));)
144 endif
146 ##############################################################################
148 # Auto-testing infrastructure
151 test-default:
153 ifdef TEST_PROGS
154 TESTDEPS += $(TESTDEPS-yes)
156 $(TEST_PROGS): $(TESTDEPS) $$@.o
157         $(call cmd,link)
159 TESTS = $(wildcard $(srcdir)test-*)
161 $(TESTS): $(TEST_PROGS)
162         @echo "*** $(notdir $@) ***"; \
163         $(call shellquote,$(SHELL)) $@ $(TEST_OPTS)
165 test-default: $(TESTS)
167 clean-test:
168         @rm -fr trash
170 CLEAN += $(TEST_PROGS) $(patsubst %,%.o,$(TEST_PROGS))
171 endif
173 .PHONY: $(TESTS)
174 .NOPARALLEL:
176 # sparse is architecture-neutral, which means that we need to tell it
177 # explicitly what architecture to check for. Fix this up for yours..
178 SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
179 install-default: all-default
180 ifdef PROGS
181         @$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
182         @$(foreach file,$(PROGS), \
183                 $(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
184 endif
185 ifdef MAN1
186         @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
187         @$(foreach file,$(MAN1), \
188                 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
189 endif
190 ifdef MAN5
191         @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
192         @$(foreach file,$(MAN5), \
193                 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);)
194 endif
196 # Recursion:
198 .PHONY: all-recursive install-recursive clean-recursive cleanall-recursive init-recursive check-recursive test-recursive
200 all-recursive install-recursive clean-recursive cleanall-recursive init-recursive check-recursive test-recursive:
201 ifdef SUBDIRS
202         @$(foreach subdir,$(sort $(SUBDIRS)), \
203                 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
204 endif
206 all: all-recursive all-default all-local
207 install: install-recursive install-default install-local
208 check: check-recursive check-default check-local
209 clean: clean-recursive clean-default clean-local
210 test: test-recursive test-default test-local
212 cleanall: cleanall-recursive cleanall-default
213 init: init-default init-recursive
215 all-local:
216 install-local:
217 clean-local:
218 check-local:
219 test-local:
221 # Tell versions [3.59,3.63) of GNU make to not export all variables.
222 # Otherwise a system limit (for SysV at least) may be exceeded.
223 .NOEXPORT:
225 # Shell quote;
226 # Result of this needs to be placed inside ''
227 # XXX: Placed here because Vim cannot highlight things right afterwards
228 shq = $(subst ','\'',$(1))
229 # This has surrounding ''
230 shellquote = '$(call shq,$(1))'
232 # vim:syntax=make