Compile fix, reported by zas
[elinks.git] / Makefile.lib
blobe3cf4652bfd05588371baf4841458cdb11c689f8
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 # Show the command (quiet or non-quiet version based on the assignment
18 # just above) and then execute it.
19 ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
20 cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
21 mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
23 quiet_cmd_compile = '      [CC]   $(RELPATH)$@'
24  masq_cmd_compile = $(COMPILE) -c $<
25       cmd_compile = $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
27 # Rule to compile a set of .o files into one .o file
28 quiet_cmd_ld_objs = "      [LD]   $(RELPATH)$@"
29       cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^) \
30                     $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
31                             `test -e $(subdir)/lib.o && echo $(subdir)/lib.o`)
33    quiet_cmd_link = '    [LINK]   $(RELPATH)$@'
34          cmd_link = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
36  quiet_cmd_sparse = '    [SPARSE]   $(RELPATH)$(2)'
37        cmd_sparse = $(SPARSE) $(DEFS) $(INCLUDES) $(AM_CFLAGS) $(CFLAGS) $(SPARSE_FLAGS) $(2)
39 # Recursive make
40 quiet_cmd_recmake = "[MAKE $(3)]   $(RELPATH)$(2)"
41       cmd_recmake = $(MAKE) -C $(2) $(3)
43 quiet_cmd_installdata = "     [INSTALL]   $(RELPATH)$(2) -> $(3)"
44       cmd_installdata = $(INSTALL_DATA) $(2) $(3)
46 quiet_cmd_installprog = "     [INSTALL]   $(RELPATH)$(2) -> $(3)"
47       cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
50 ### Internal build rules
52 DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
53 DEP_FILES = $(DEP_FILES_1:%.o=%.P)
55 DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
57 ifdef OBJS
58 -include $(DEP_FILES)
59 endif
61 %.o: $(srcdir)%.c
62         $(call mcmd,compile)
63         @-cp .deps/$(*F).pp .deps/$(*F).P; \
64                 tr ' ' '\012' < .deps/$(*F).pp \
65                         | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
66                         >> .deps/$(*F).P; \
67                 rm .deps/$(*F).pp
69 ifdef SUBDIRS-yes
70 SUBDIRS += $(SUBDIRS-yes)
71 endif
73 ifdef OBJS-yes
74 OBJS += $(OBJS-yes)
75 endif
77 ifneq ($(findstring cleanall,$(MAKECMDGOALS)),)
78 INCLUDE_ALL=1
79 endif
81 ifneq ($(findstring init,$(MAKECMDGOALS)),)
82 # FIXME: Detect when $(subdir)/Makefile is $(srcdir)/$(subdir)/Makefile
83 # and error out so the user won't overwrite the 'master' Makefiles.
84 INCLUDE_ALL=1
85 endif
87 ifdef INCLUDE_ALL
88 ifdef SUBDIRS-no
89 SUBDIRS += $(SUBDIRS-no)
90 endif
91 ifdef OBJS-no
92 OBJS += $(OBJS-no)
93 endif
95 endif
98 ifdef OBJS
99 lib.o: $(sort $(OBJS)) $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), $(wildcard $(subdir)/lib.o))
100         $(call cmd,ld_objs)
102 LIB_O = lib.o
103 CLEAN += $(OBJS) $(LIB_O)
104 endif
106 CLEAN += $(PROG)
108 all-default: $(LIB_O) $(PROGS) $(MAN1) $(MAN5)
110 init-default:
111         @$(foreach subdir,$(sort $(SUBDIRS)), \
112                 $(MKINSTALLDIRS) $(subdir) >/dev/null; \
113                 echo 'include $(SRC)/$(RELPATH)/$(subdir)/Makefile' > $(subdir)/Makefile;)
115 clean-default:
116         -test -z "$(CLEAN)" || $(RM) $(CLEAN)
118 cleanall-default: clean-default
120 check-default:
121 ifneq ($(SPARSE),)
122         @$(foreach file, $(wildcard *.c), \
123                 $(call ncmd,sparse,$(file));)
124 endif
126 # sparse is architecture-neutral, which means that we need to tell it
127 # explicitly what architecture to check for. Fix this up for yours..
128 SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
129 install-default: all-default
130 ifdef PROGS
131         @$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
132         @$(foreach file,$(PROGS), \
133                 $(call ncmd,installprog,$(file),$(DESTDIR)$(bindir));)
134 endif
135 ifdef MAN1
136         @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
137         @$(foreach file,$(MAN1), \
138                 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man1);)
139 endif
140 ifdef MAN5
141         @$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
142         @$(foreach file,$(MAN5), \
143                 $(call ncmd,installdata,$(file),$(DESTDIR)$(mandir)/man5);)
144 endif
146 # Recursion:
148 .PHONY: all-recursive install-recursive clean-recursive cleanall-recursive init-recursive check-recursive
150 all-recursive install-recursive clean-recursive cleanall-recursive init-recursive check-recursive:
151 ifdef SUBDIRS
152         @$(foreach subdir,$(sort $(SUBDIRS)), \
153                 $(call ncmd,recmake,$(subdir),$(subst -recursive,,$@)) || exit 1;)
154 endif
156 all: all-recursive all-default all-local
157 install: install-recursive install-default install-local
158 check: check-recursive check-default check-local
159 clean: clean-recursive clean-default clean-local
161 cleanall: cleanall-recursive cleanall-default
162 init: init-default init-recursive
164 all-local:
165 install-local:
166 clean-local:
167 check-local:
169 # Tell versions [3.59,3.63) of GNU make to not export all variables.
170 # Otherwise a system limit (for SysV at least) may be exceeded.
171 .NOEXPORT:
173 # vim:syntax=make