Skip to content

Commit

Permalink
Improve out of project tree builds
Browse files Browse the repository at this point in the history
For the out of the project tree builds there is no need to replicate
under TOP_BUILD_DIR whole directory stack leading to the actual project
directory.  This is now removed and the project is built now right under
TOP_BUILD_DIR.  In addition:
- OBJ_PATH has been optimized (no need for constant TOP_BUILD_DIR testing)
- clean targets has been corrected
- echo_cmd also has been corrected
  • Loading branch information
aostruszka committed Nov 8, 2013
1 parent 2645064 commit 5b7b478
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 5 additions & 1 deletion mk/def_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ COLOR_TTY := $(shell [ `tput colors` -gt 2 ] && echo true)
endif

ifneq ($(VERBOSE),true)
strip_top = $(subst $(TOP)/,,$(subst $(TOP_BUILD_DIR),,$(1)))
ifneq ($(strip $(TOP_BUILD_DIR)),)
strip_top = $(subst $(TOP_BUILD_DIR)/,,$(1))
else
strip_top = $(subst $(TOP)/,,$(1))
endif
ifeq ($(COLOR_TTY),true)
echo_prog := $(shell if echo -e | grep -q -- -e; then echo echo; else echo echo -e; fi)
echo_cmd = @$(echo_prog) "$(COLOR)$(call strip_top,$(1))$(NOCOLOR)";
Expand Down
4 changes: 2 additions & 2 deletions mk/footer.mk
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dist_clean_$(d) :
else
dist_clean_$(d) : clean_extra_$(d)
endif
rm -rf $(TOP_BUILD_DIR)$(subst dist_clean_,,$@)/$(firstword $(subst /, ,$(OBJDIR)))
rm -rf $(DIST_CLEAN_DIR)
endif

########################################################################
Expand All @@ -78,7 +78,7 @@ clean_$(d) :
else
clean_$(d) : clean_extra_$(d)
endif
rm -f $(TOP_BUILD_DIR)$(subst clean_,,$@)/$(OBJDIR)/*
rm -f $(CLEAN_DIR)/*

# clean_extra is meant for the extra output that is generated in source
# directory (e.g. generated source from lex/yacc) so I'm not using
Expand Down
14 changes: 11 additions & 3 deletions mk/skel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,16 @@ OBJDIR := $(if $(BUILD_MODE),obj/$(BUILD_MODE),obj)
# By default OBJDIR is relative to the directory of the corresponding Rules.mk
# however you can use TOP_BUILD_DIR to build all objects outside of your
# project tree.
#TOP_BUILD_DIR := /tmp/make-builddir
OBJPATH = $(if $(TOP_BUILD_DIR),$(TOP_BUILD_DIR)$(d),$(d))/$(OBJDIR)
#TOP_BUILD_DIR := /tmp/make-builddir/project_name
ifneq ($(strip $(TOP_BUILD_DIR)),)
OBJPATH = $(TOP_BUILD_DIR)$(subst $(TOP),,$(d))/$(OBJDIR)
CLEAN_DIR = $(TOP_BUILD_DIR)$(subst $(TOP),,$(subst clean_,,$@))/$(OBJDIR)
DIST_CLEAN_DIR = $(TOP_BUILD_DIR)$(subst $(TOP),,$(subst dist_clean_,,$@))/$(firstword $(subst /, ,$(OBJDIR)))
else
OBJPATH = $(d)/$(OBJDIR)
CLEAN_DIR = $(subst clean_,,$@)/$(OBJDIR)
DIST_CLEAN_DIR = $(subst dist_clean_,,$@)/$(firstword $(subst /, ,$(OBJDIR)))
endif

# This variable contains a list of subdirectories where to look for
# sources. That is if you have some/dir/Rules.mk where you name object
Expand Down Expand Up @@ -231,7 +239,7 @@ endef
# have dist_clean on per directory level and the one below is enough
ifneq ($(strip $(TOP_BUILD_DIR)),)
dist_clean :
rm -rf $(TOP_BUILD_DIR)$(TOP)
rm -rf $(TOP_BUILD_DIR)
endif

# Suck in the default rules
Expand Down

0 comments on commit 5b7b478

Please sign in to comment.