UTF-8: Fix scrolling of input fields.
[elinks.git] / Makefile.lib
blob09fa3c9efe1d7f8b8d12f46fdcce8fcb0bfee66f
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         Q =
29 else
30         quiet = quiet_
31         mquiet = quiet_
32         Q = @
33 endif
35 # Show the command (quiet or non-quiet version based on the assignment
36 # just above) and then execute it.
37 ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
38 cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
39 mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
40 ecmd = @$(if $($(mquiet)cmd_$(1)),printf "%-38s " $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
42 quiet_cmd_compile = '      [$(CC_COLOR)CC$(END_COLOR)]   $(RELPATH)$@'
43  masq_cmd_compile = $(COMPILE) -o $(@) -c $< $(2)
44       cmd_compile = $(COMPILE) -o $(@) -Wp,-MD,.deps/$(*F).pp -c $< $(2)
46 # Rule to compile a set of .o files into one .o file
47 quiet_cmd_ld_objs = "      [$(LD_COLOR)LD$(END_COLOR)]   $(RELPATH)$@"
48       cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^) \
49                     $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
50                             `test -e $(subdir)/$(LIB_O_NAME) && echo $(subdir)/$(LIB_O_NAME)`)
52    quiet_cmd_link = '    [$(LINK_COLOR)LINK$(END_COLOR)]   $(RELPATH)$@'
53          cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
55  quiet_cmd_sparse = '    [SPARSE]   $(RELPATH)$(2)'
56        cmd_sparse = $(SPARSE) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(SPARSE_FLAGS) $(2)
58 # Recursive make
59 quiet_cmd_recmake = "[$(INFO_COLOR)MAKE $(3)$(END_COLOR)]   $(RELPATH)$(2)"
60       cmd_recmake = $(MAKE) -C $(2) $(3)
62 quiet_cmd_installdata = "     [$(INSTALL_COLOR)INSTALL$(END_COLOR)]   $(RELPATH)$(2) -> $(3)"
63       cmd_installdata = $(INSTALL_DATA) $(2) $(3)
65 quiet_cmd_installprog = "     [$(INSTALL_COLOR)INSTALL$(END_COLOR)]   $(RELPATH)$(2) -> $(3)"
66       cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
69 #############################################################################
70 # Special handling of conditional variables
72 SUBDIRS += $(SUBDIRS-yes)
73 OBJS    += $(OBJS-yes)
75 ALTDIRS  = $(SUBDIRS-no) $(SUBDIRS-)
76 ALTOBJS  = $(OBJS-no) $(OBJS-)
78 ifneq ($(findstring cleanall,$(MAKECMDGOALS)),)
79 INCLUDE_ALL=1
80 endif
82 ifneq ($(findstring init,$(MAKECMDGOALS)),)
83 INCLUDE_ALL=1
84 ifndef SRC
85 SRC = $(shell cd $(top_srcdir) && pwd)
86 endif
87 endif
89 ifdef INCLUDE_ALL
90 SUBDIRS += $(ALTDIRS)
91 OBJS    += $(ALTOBJS)
92 endif
95 #############################################################################
96 # Internal build rules
98 # All files in $(OBJS) and any $(subdir)/lib.o are linked into lib.o.
99 # Sort them to filter out duplicated and get uniform order.
100 LIB_O_DEPS = \
101  $(sort $(filter-out $(LIB_O_NAME),$(OBJS))) \
102  $(foreach subdir,$(sort $(SUBDIRS)),$(wildcard $(subdir)/$(LIB_O_NAME)))
104 $(LIB_O_NAME): $(LIB_O_DEPS)
105         $(call cmd,ld_objs)
107 DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
108 DEP_FILES = $(DEP_FILES_1:%.o=%.P)
109 DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
111 ifneq ($(strip $(OBJS)),)
112 -include $(DEP_FILES)
113 ALL_OBJS = $(LIB_O_DEPS) $(LIB_O_NAME)
114 endif
116 %.o: $(srcdir)%.c
117         $(call mcmd,compile)
118         @-if test -e .deps/$(*F).pp; then \
119                 cp .deps/$(*F).pp .deps/$(*F).P; \
120                 tr ' ' '\012' < .deps/$(*F).pp \
121                         | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
122                         >> .deps/$(*F).P; \
123                 rm .deps/$(*F).pp; \
124         fi
126 CLEAN += $(PROGS) $(OBJS) $(LIB_O_NAME)
129 #############################################################################
130 # The main default rules
132 all-default: $(ALL_OBJS) $(PROGS) $(MAN1) $(MAN5)
134 # Ensure that Makefiles in subdirs are created before we recursive into them
135 init-recursive: init-default
137 init-default:
138         @$(foreach subdir,$(sort $(SUBDIRS)), \
139                 $(MKINSTALLDIRS) $(subdir) >/dev/null; \
140                 test -e "$(subdir)/Makefile" \
141                 || echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;)
143 clean-default cleanall-default:
144         $(Q)-test -z "$(CLEAN)" || $(RM) $(CLEAN)
146 check-default:
147 ifneq ($(SPARSE),)
148         @$(foreach file, $(wildcard *.c), \
149                 $(call ncmd,sparse,$(file));)
150 endif
152 install-default: all-default
153 ifdef PROGS
154         @$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
155         @$(foreach file,$(PROGS), \
156                 $(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
157 endif
158 ifdef MAN1
159         @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
160         @$(foreach file,$(MAN1), \
161                 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
162 endif
163 ifdef MAN5
164         @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
165         @$(foreach file,$(MAN5), \
166                 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);)
167 endif
169 ##############################################################################
170 # Auto-testing infrastructure
172 test-default:
174 ifdef TEST_PROGS
175 TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o
176 TESTDEPS += $(TESTDEPS-yes)
178 TEST_LIB=$(top_srcdir)/test/libtest.sh
179 export TEST_LIB
181 # This is a very general rule but as long as we don't put test programs in src/
182 # it should work.
183 %: %.o $(TESTDEPS)
184         $(call cmd,link)
186 TESTS = $(wildcard $(srcdir)test-*)
188 $(TESTS): $(addsuffix .o,$(TEST_PROGS)) $(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 descend all subdirs.
216 # If make -k was used and a sub-Make fails, then keep building the
217 # remaining subdirectories, but return an error at the end.
218 $(RULES_REC):
219 ifneq (,$(findstring k,$(MAKEFLAGS)))
220         @suberr=0; \
221         $(foreach subdir,$(sort $(SUBDIRS)), \
222                 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || suberr=1;) \
223         exit $$suberr
224 else
225         @$(foreach subdir,$(sort $(SUBDIRS)), \
226                 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
227 endif
229 # Dummy -local rules
230 $(RULES_LOCAL):
232 # Default deps
233 rule_deps = $(1)-recursive $(1)-default $(1)-local
234 all:      $(call rule_deps,all)
235 install:  $(call rule_deps,install)
236 clean:    $(call rule_deps,clean)
237 cleanall: $(call rule_deps,cleanall)
238 init:     $(call rule_deps,init)
239 check:    $(call rule_deps,check)
240 test:     $(call rule_deps,test)
242 #############################################################################
243 # Misc
245 # Tell versions [3.59,3.63) of GNU make to not export all variables.
246 # Otherwise a system limit (for SysV at least) may be exceeded.
247 .NOEXPORT:
249 # Shell quote;
250 # Result of this needs to be placed inside ''
251 # XXX: Placed here because Vim cannot highlight things right afterwards
252 shq = $(subst ','\'',$(1))
253 # This has surrounding ''
254 shellquote = '$(call shq,$(1))'
256 # vim:syntax=make