Skip to content

Commit

Permalink
Get rid of .fake_file dependency
Browse files Browse the repository at this point in the history
From now on OBJDIR is order-only dependency
  • Loading branch information
aostruszka committed Apr 16, 2013
1 parent 7435463 commit f3f07d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
15 changes: 7 additions & 8 deletions mk/def_rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ LINK.cc = $(call echo_cmd,LINK $@) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(T
%.CPPFLAGS : %
@echo $(CPPFLAGS)

# In this build system all objects are in a separate directory and
# I make sure this directory exists by the dependency on this fake file
%/$(OBJDIR)/.fake_file:
@[ -d $(dir $@) ] || mkdir -p $(dir $@); touch $@
# Create the output directory for build targets.
%/$(OBJDIR):
@mkdir -p $@

# Generic rules. Again, since the output is in different directory than
# source files I cannot count on the built in make rules. So I keep
Expand All @@ -81,19 +80,19 @@ LINK.cc = $(call echo_cmd,LINK $@) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(T
# COMPILE.cmo.ml = $(call echo_cmd,CAML $<) $(CAML) -c
# COMPILE.cmx.ml = $(call echo_cmd,CAMLOPT $<) $(CAMLOPT) -c
# together with corresponding two entries in 'skeleton' below:
# $(OBJPATH)/%.cmo $(OBJPATH)/%.cmx: $(1)/%.ml $(OBJPATH)/.fake_file
# $(OBJPATH)/%.cmo $(OBJPATH)/%.cmx: $(1)/%.ml | $(OBJPATH)
# $(value COMPILECMD_TD)

COMPILECMD = $(COMPILE$(suffix $<)) -o $@ $<
COMPILECMD_TD = $(COMPILE$(suffix $@)$(suffix $<)) -o $@ $<

define skeleton
$(OBJPATH)/%.o: $(1)/%.cpp $(OBJPATH)/.fake_file
$(OBJPATH)/%.o: $(1)/%.cpp | $(OBJPATH)
$(value COMPILECMD)

$(OBJPATH)/%.o: $(1)/%.cc $(OBJPATH)/.fake_file
$(OBJPATH)/%.o: $(1)/%.cc | $(OBJPATH)
$(value COMPILECMD)

$(OBJPATH)/%.o: $(1)/%.c $(OBJPATH)/.fake_file
$(OBJPATH)/%.o: $(1)/%.c | $(OBJPATH)
$(value COMPILECMD)
endef
2 changes: 1 addition & 1 deletion mk/footer.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $(foreach v,$(INHERIT_DIR_VARS_$(d)),$(if $($(v)_$(d)),,$(eval $(v)_$(d) := $($(
$(foreach sd,$(SUBDIRS),$(eval $(call include_subdir_rules,$(sd))))

.PHONY: dir_$(d) clean_$(d) clean_extra_$(d) clean_tree_$(d) dist_clean_$(d)
.SECONDARY: $(OBJPATH)/.fake_file
.SECONDARY: $(OBJPATH)

# Whole tree targets
all :: $(TARGETS_$(d))
Expand Down
18 changes: 9 additions & 9 deletions mk/skel.mk
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ SOEXT := $(or $(SOEXT),so)
########################################################################

# I define these for convenience - you can use them in your command for
# updating the target. Since I'm using fake file dependency to make
# sure the OBJDIR exists I filter it out here. Mnemonic for these
# ? ^ versions is Real (that is not fake :))
# updating the target.
DEP_OBJS = $(filter %.o, $^)
DEP_ARCH = $(filter %.a, $^)
DEP_LIBS = $(addprefix -L,$(dir $(filter %.$(SOEXT), $^))) $(patsubst lib%.$(SOEXT),-l%,$(notdir $(filter %.$(SOEXT), $^)))
?R = $(filter-out %/.fake_file,$?)
^R = $(filter-out %/.fake_file,$^)

# Kept for backward capability - you should stop using these since I'm
# now not dependend on $(OBJDIR)/.fake_file any more
?R = $?
^R = $^

# Targets that match this pattern (make pattern) will use rules defined
# in:
Expand Down Expand Up @@ -172,9 +173,8 @@ SRCS_VPATH := src
# target's suffix and corresponding MAKECMD variable. For example %.a
# are # updated by MAKECMD.a (exemplary setting below). If the target
# is not filtered out by AUTO_TGTS and there's neither _CMD nor suffix
# specific command to build the target DEFAULT_MAKECMD is used. See
# above for the explanation of the R versions of ? and ^ variables.
MAKECMD.a = $(call echo_cmd,AR $@) $(AR) $(ARFLAGS) $@ $(?R) && $(RANLIB) $@
# specific command to build the target DEFAULT_MAKECMD is used.
MAKECMD.a = $(call echo_cmd,AR $@) $(AR) $(ARFLAGS) $@ $? && $(RANLIB) $@
MAKECMD.$(SOEXT) = $(LINK.cc) $(DEP_OBJS) $(DEP_ARCH) $(DEP_LIBS) $(LIBS_$(@)) $(LDLIBS) -shared -o $@
DEFAULT_MAKECMD = $(LINK.cc) $(DEP_OBJS) $(DEP_ARCH) $(DEP_LIBS) $(LIBS_$(@)) $(LDLIBS) -o $@

Expand Down Expand Up @@ -214,7 +214,7 @@ abs_deps := $$(filter /%,$$(DEPS_$(1)))
rel_deps := $$(filter-out /%,$$(DEPS_$(1)))
abs_deps += $$(addprefix $(OBJPATH)/,$$(rel_deps))
-include $$(addsuffix .d,$$(basename $$(abs_deps)))
$(1): $$(abs_deps) $(if $(findstring $(OBJDIR),$(1)),$(OBJPATH)/.fake_file,)
$(1): $$(abs_deps) $(if $(findstring $(OBJDIR),$(1)),| $(OBJPATH),)
$$(or $$(CMD_$(1)),$$(MAKECMD$$(suffix $$@)),$$(DEFAULT_MAKECMD))
endef

Expand Down

0 comments on commit f3f07d8

Please sign in to comment.