mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
daaf61331a
Makes it more obvious which files are actually installed. MKINSTALLDIRS still spurs out a lot of 'mkdir ...', which probably should also be silenced when V=0.
139 lines
3.5 KiB
Makefile
139 lines
3.5 KiB
Makefile
### The build commands and verbosity
|
|
|
|
# If we are verbose, we will show commands prefixed by $(Q) (which acts as
|
|
# @ in the non-verbose mode), and we will show the "real" cmds instead of
|
|
# their quiet versions (which are used in the non-verbose mode).
|
|
# Inspired by the Linux kernel build system.
|
|
ifdef V
|
|
Q =
|
|
quiet =
|
|
mquiet = masq_
|
|
else
|
|
Q = @
|
|
quiet = quiet_
|
|
mquiet = quiet_
|
|
endif
|
|
|
|
CURPATH = $(shell pwd)
|
|
TOPPATH = $(shell cd $(path_to_top) && pwd)
|
|
RELPATH = $(shell echo '$(CURPATH)' | sed 's,$(TOPPATH),,;s,^/,,;s,\([a-z0-9]\)$$,\1/,')
|
|
|
|
# Show the command (quiet or non-quiet version based on the assignment
|
|
# just above) and then execute it.
|
|
ncmd = $(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
|
|
cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
|
|
mcmd = @$(if $($(mquiet)cmd_$(1)),echo $($(mquiet)cmd_$(1)) &&) $(cmd_$(1))
|
|
|
|
quiet_cmd_compile = ' [CC] $(RELPATH)$<'
|
|
masq_cmd_compile = $(COMPILE) -c $<
|
|
cmd_compile = $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
|
|
|
|
# Rule to compile a set of .o files into one .o file
|
|
quiet_cmd_ld_objs = " [LD] $(RELPATH)$@"
|
|
cmd_ld_objs = $(LD) -r -o $@ $(filter $(OBJS), $^)
|
|
|
|
quiet_cmd_link = ' [LINK] $(RELPATH)$@'
|
|
cmd_link = $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
|
|
|
|
# Recursive make
|
|
quiet_cmd_recmake = "[MAKE $$target] $(RELPATH)$$subdir"
|
|
cmd_recmake = $(MAKE) -C $$subdir $$target
|
|
|
|
quiet_cmd_installdata = " [INSTALL] $(RELPATH)$(2) -> $(3)"
|
|
cmd_installdata = $(INSTALL_DATA) $(2) $(3)
|
|
|
|
quiet_cmd_installprog = " [INSTALL] $(RELPATH)$(2) -> $(3)"
|
|
cmd_installprog = $(INSTALL_PROGRAM) $(2) $(3)
|
|
|
|
|
|
|
|
### Internal build rules
|
|
|
|
DEP_FILES_1 = $(foreach src,$(OBJS),.deps/$(src))
|
|
DEP_FILES = $(DEP_FILES_1:%.o=%.P)
|
|
|
|
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
|
|
|
|
ifdef OBJS
|
|
-include $(DEP_FILES)
|
|
endif
|
|
|
|
%.o: %.c
|
|
$(call mcmd,compile)
|
|
@-cp .deps/$(*F).pp .deps/$(*F).P; \
|
|
tr ' ' '\012' < .deps/$(*F).pp \
|
|
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
|
|
>> .deps/$(*F).P; \
|
|
rm .deps/$(*F).pp
|
|
|
|
ifdef SUBDIRS-yes
|
|
SUBDIRS += $(SUBDIRS-yes)
|
|
endif
|
|
|
|
ifdef OBJS-yes
|
|
OBJS += $(OBJS-yes)
|
|
endif
|
|
|
|
ifdef SUBDIRS
|
|
# Apparently wildcard won't expand *.o files so check if there are any *.c
|
|
# files and use that to magically add the lib.o file of the subdirectory.
|
|
subobjs := $(strip $(foreach subdir,$(sort $(filter-out src,$(SUBDIRS))), \
|
|
$(if $(wildcard $(subdir)/*.c),$(subdir)/lib.o)))
|
|
endif
|
|
ifneq ($(subobjs),)
|
|
OBJS += $(subobjs)
|
|
endif
|
|
|
|
ifdef OBJS
|
|
CLEAN += $(OBJS)
|
|
|
|
clean-local:
|
|
$(RM) lib.o $(CLEAN)
|
|
|
|
lib.o: $(sort $(OBJS))
|
|
$(call cmd,ld_objs)
|
|
|
|
all-local: lib.o
|
|
endif
|
|
|
|
install-local:
|
|
ifdef PROGS
|
|
$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
|
|
@for file in $(PROGS); do \
|
|
$(call ncmd,installprog,$$file,$(DESTDIR)$(bindir)); \
|
|
done
|
|
endif
|
|
ifdef MAN1
|
|
$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
|
|
@for file in $(MAN1); do \
|
|
$(call ncmd,installdata,$$file,$(DESTDIR)$(mandir)/man1); \
|
|
done
|
|
endif
|
|
ifdef MAN5
|
|
$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man5
|
|
@for file in $(MAN5); do \
|
|
$(call ncmd,installdata,$$file,$(DESTDIR)$(mandir)/man5); \
|
|
done
|
|
endif
|
|
|
|
# Recursion:
|
|
|
|
.PHONY: all-recursive install-recursive clean-recursive
|
|
all-recursive install-recursive clean-recursive:
|
|
ifdef SUBDIRS
|
|
@target=`echo $@ | sed s/-recursive//`; \
|
|
for subdir in $(sort $(SUBDIRS)); do \
|
|
$(call ncmd,recmake) || exit 1; \
|
|
done
|
|
endif
|
|
|
|
all: all-recursive all-local
|
|
install: install-recursive install-local
|
|
clean: clean-recursive clean-local
|
|
|
|
all-local:
|
|
install-local:
|
|
clean-local:
|
|
|
|
# vim:syntax=make
|