Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 66 additions & 46 deletions Makefile.lib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Makefile.lib
#
# version : 3.2.0
# copyright : 2002 - 2019 by Alper Akcan
# version : 3.2.3
# copyright : 2002 - 2020 by Alper Akcan
# email : alper.akcan@gmail.com
#
# This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -50,6 +50,8 @@
# 20190701 - do not override depends-y
# 20190702 - fix depends-y for subdirs
# 20190806 - fix parallel compilation of ${target}_depends-y
# 20200130 - adding install rule
# 20200203 - add 'distclean' target and add uniq to all foreach

#
# Example
Expand Down Expand Up @@ -82,6 +84,8 @@
#
# dist.dir = dist
#
# dist.base = base
#
# dist.bin = target1
#
# include Makefile.lib
Expand Down Expand Up @@ -177,10 +181,13 @@
# ---------------------
#
# dist.dir : distribution folder
# dist.base : base folder to be used in $(dist.dir)/{obj,share,include,src}/
#
# dist.src-[y,n ] : files to be copied under $(dist.dir)/src directory
# dist.obj-[y,n ] : files to be copied under $(dist.dir)/obj directory
# dist.lib-[y,n ] : files to be copied under $(dist.dir)/lib directory
# dist.bin-[y,n ] : files to be copied under $(dist.dir)/bin directory
# dist.include-[y,n ] : files to be copied under $(dist.dir)/include directory
#

TOPDIR ?= $(CURDIR)
Expand Down Expand Up @@ -266,46 +273,48 @@ else
MAKE += --no-print-directory
endif

pur_objects = $(CURDIR)/$$@
pur_objects = $$(subst __UPDIR__/,../,$(CURDIR)/$$@)
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))

pur_objects := $$(subst __UPDIR__/,../,$$@)
pur_objects := $$(if $$(patsubst /%,,$(pur_objects)),$(CURDIR)/$(pur_objects),$(pur_objects))
#pur_objects = $$(subst $(TOPDIR)/,,$$(subst /.$1,/$1,$(CURDIR)/$$@))
#pur_objects = $$(subst .$1/,,$$@)

#
# PUR
#
pur_disp_depend.c = echo " CPP $(pur_objects)"
pur_disp_depend.c = echo " DEP $(pur_objects)"
pur_disp_compile.c = echo " CC $(pur_objects)"
pur_disp_link.c = echo " LINK $(pur_objects)"
pur_disp_link_so.c = echo " LINKSO $(pur_objects)"

pur_disp_depend.cxx = echo " CPP $(pur_objects)"
pur_disp_depend.cxx = echo " DEP $(pur_objects)"
pur_disp_compile.cxx = echo " CXX $(pur_objects)"
pur_disp_link.cxx = echo " LINK $(pur_objects)"
pur_disp_link_so.cxx = echo " LINKSO $(pur_objects)"

pur_disp_moc.qt = echo " MOC $(pur_objects)"
pur_disp_uic.qt = echo " UIC $(pur_objects)"

pur_disp_depend.m = echo " CPP $(pur_objects)"
pur_disp_depend.m = echo " DEP $(pur_objects)"
pur_disp_compile.m = echo " CC $(pur_objects)"
pur_disp_link.m = echo " LINK $(pur_objects)"
pur_disp_link_so.m = echo " LINKSO $(pur_objects)"

pur_disp_depend.c.host = echo " HOSTCPP $(pur_objects)"
pur_disp_depend.c.host = echo " HOSTDEP $(pur_objects)"
pur_disp_compile.c.host = echo " HOSTCC $(pur_objects)"
pur_disp_link.c.host = echo " HOSTLINK $(pur_objects)"
pur_disp_link_so.c.host = echo " HOSTLINKSO $(pur_objects)"

pur_disp_depend.cxx.host = echo " HOSTCPP $(pur_objects)"
pur_disp_depend.cxx.host = echo " HOSTDEP $(pur_objects)"
pur_disp_compile.cxx.host = echo " HOSTCXX $(pur_objects)"
pur_disp_link.cxx.host = echo " HOSTLINK $(pur_objects)"
pur_disp_link_so.cxx.host = echo " HOSTLINKSO $(pur_objects)"

pur_disp_moc.qt.host = echo " HOSTMOC $(pur_objects)"
pur_disp_uic.qt.host = echo " HOSTUIC $(pur_objects)"

pur_disp_depend.m.host = echo " HOSTCPP $(pur_objects)"
pur_disp_depend.m.host = echo " HOSTDEP $(pur_objects)"
pur_disp_compile.m.host = echo " HOSTCC $(pur_objects)"
pur_disp_link.m.host = echo " HOSTLINK $(pur_objects)"
pur_disp_link_so.m.host = echo " HOSTLINKSO $(pur_objects)"
Expand Down Expand Up @@ -734,9 +743,9 @@ define target-defaults_base
$(do_cp)
$(do_print_deps)

.NOTPARALLEL: $($1_depends_y) $($1_objects_e) $($1_objects)
.NOTPARALLEL: $($1_depends_y) $($1_objects) $($1_objects_e)

.$1/$1: $($1_depends_y) $($1_objects_e) $($1_objects)
.$1/$1: $($1_depends_y) $($1_objects) $($1_objects_e)

$1_clean: __FORCE
$(do_clean) $1 .$1 $$@.cmd $1.dSYM $($1_headers_uic)
Expand Down Expand Up @@ -888,6 +897,10 @@ define subdir-defaults
${Q}+ $(MAKE) $($1_makeflags-y) -C '$$(subst _all,,$$@)' all
$(do_print_deps)

$(addsuffix _install, $1): __FORCE
${Q}+ $(MAKE) $($1_makeflags-y) -C '$$(subst _install,,$$@)' install
$(do_print_deps)

$(addsuffix _clean, $1): __FORCE
${Q}+ $(MAKE) $($1_makeflags-y) -C '$$(subst _clean,,$$@)' clean
endef
Expand Down Expand Up @@ -940,53 +953,53 @@ endef

# generate target variables

$(eval $(foreach T,$(target-y), $(eval $(call target-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(target-n), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(target-), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target-y)), $(eval $(call target-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target-)), $(eval $(call target_empty-defaults,$T))))

$(eval $(foreach T,$(target.o-y), $(eval $(call target.o-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(target.o-n), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(target.o-), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.o-y)), $(eval $(call target.o-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.o-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.o-)), $(eval $(call target_empty-defaults,$T))))

$(eval $(foreach T,$(target.a-y), $(eval $(call target.a-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(target.a-n), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(target.a-), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.a-y)), $(eval $(call target.a-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.a-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.a-)), $(eval $(call target_empty-defaults,$T))))

$(eval $(foreach T,$(target.so-y), $(eval $(call target.so-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(target.so-n), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(target.so-), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.so-y)), $(eval $(call target.so-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.so-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.so-)), $(eval $(call target_empty-defaults,$T))))

$(eval $(foreach T,$(target.host-y), $(eval $(call target.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(target.host-n), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(target.host-), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.host-y)), $(eval $(call target.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.host-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.host-)), $(eval $(call target_empty-defaults,$T))))

$(eval $(foreach T,$(target.o.host-y), $(eval $(call target.o.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(target.o.host-n), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(target.o.host-), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.o.host-y)), $(eval $(call target.o.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.o.host-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.o.host-)), $(eval $(call target_empty-defaults,$T))))

$(eval $(foreach T,$(target.so.host-y), $(eval $(call target.so.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(target.so.host-n), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(target.so.host-), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.so.host-y)), $(eval $(call target.so.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.so.host-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.so.host-)), $(eval $(call target_empty-defaults,$T))))

$(eval $(foreach T,$(target.a.host-y), $(eval $(call target.a.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(target.a.host-n), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(target.a.host-), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.a.host-y)), $(eval $(call target.a.host-variables,$T,$($T_files-y)))))
$(eval $(foreach T,$(call uniq,$(target.a.host-n)), $(eval $(call target_empty-defaults,$T))))
$(eval $(foreach T,$(call uniq,$(target.a.host-)), $(eval $(call target_empty-defaults,$T))))

# generate subdir targets

$(eval $(foreach S,$(subdir-y),$(eval $(call subdir-defaults,$S))))
$(eval $(foreach S,$(subdir-n),$(eval $(call subdir_empty-defaults,$S,clean))))
$(eval $(foreach S,$(subdir-),$(eval $(call subdir_empty-defaults,$S,clean))))
$(eval $(foreach S,$(call uniq,$(subdir-y)),$(eval $(call subdir-defaults,$S))))
$(eval $(foreach S,$(call uniq,$(subdir-n)),$(eval $(call subdir_empty-defaults,$S,clean))))
$(eval $(foreach S,$(call uniq,$(subdir-)),$(eval $(call subdir_empty-defaults,$S,clean))))

# distributin tags

ifneq ($(dist.dir),)
$(eval $(foreach D,$(dist.bin-y), $(eval $(call dist.bin-variables,$D))))
$(eval $(foreach D,$(dist.lib-y), $(eval $(call dist.lib-variables,$D))))
$(eval $(foreach D,$(dist.obj-y), $(eval $(call dist.obj-variables,$D))))
$(eval $(foreach D,$(dist.src-y), $(eval $(call dist.src-variables,$D))))
$(eval $(foreach D,$(dist.include-y), $(eval $(call dist.include-variables,$D))))
$(eval $(foreach D,$(dist.share-y), $(eval $(call dist.share-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.bin-y)), $(eval $(call dist.bin-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.lib-y)), $(eval $(call dist.lib-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.obj-y)), $(eval $(call dist.obj-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.src-y)), $(eval $(call dist.src-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.include-y)), $(eval $(call dist.include-variables,$D))))
$(eval $(foreach D,$(call uniq,$(dist.share-y)), $(eval $(call dist.share-variables,$D))))
endif

# generic tags
Expand All @@ -998,14 +1011,21 @@ all: $(target.extra-y)
all: __FORCE
@true

install: $(addsuffix _install, $(subdirs))
install: $(target-dists)
install: __FORCE

clean: $(addsuffix _clean, $(subdir-y) $(subdir-n) $(subdir-))
clean: $(target-cleans)
clean: $(addsuffix _clean, $(targets-empty))
clean: __FORCE

distclean: clean
distclean: __FORCE

__FORCE:
@true

ifneq "$(MAKECMDGOALS)" "clean"
ifeq ($(filter $(MAKECMDGOALS),clean distclean),)
-include $(target-depends)
endif