summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-11-24 09:50:09 (EST)
committer P. J. McDermott <pj@pehjota.net>2014-11-24 09:53:51 (EST)
commit0f37bc35e47819f20afde8329cd62c0b868d173a (patch)
tree624f6c38362e61b6ce30814f6d597bed40e7d56a
parent2f9780f77ee22264439ea5386a63ac3e60371ed2 (diff)
Makefile: Fix subdirectory build
Copy variable assignments from scripts/Makefile.host at commit 97e3226 in Linux. Drop "$(obj)/" from -o options in linking commands.
-rw-r--r--Makefile48
1 files changed, 38 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index e980151..fe82a2b 100644
--- a/Makefile
+++ b/Makefile
@@ -28,24 +28,52 @@ hostprogs-y := nconf
endif
__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
-host-csingle := $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m)))
-host-cmulti := $(foreach m,$(__hostprogs),\
- $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
-host-cxxmulti := $(foreach m,$(__hostprogs),\
- $(if $($(m)-cxxobjs),$(m),$(if $($(m)-objs),)))
-host-cobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(__hostprogs),$($(m)-objs))))
-host-cxxobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(__hostprogs),$($(m)-cxxobjs))))
+
+# C code
+# Executables compiled from a single .c file
+host-csingle := $(foreach m,$(__hostprogs), \
+ $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
+
+# C executables linked based on several .o files
+host-cmulti := $(foreach m,$(__hostprogs),\
+ $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
+
+# Object (.o) files compiled from .c files
+host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
+
+# C++ code
+# C++ executables compiled from at least one .cc file
+# and zero or more .c files
+host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
+
+# C++ Object (.o) files compiled from .cc files
+host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
+
+# output directory for programs/.o files
+# hostprogs-y := tools/build may have been specified.
+# Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
+host-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs))
+
+host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs))))
+
+__hostprogs := $(addprefix $(obj)/,$(__hostprogs))
+host-csingle := $(addprefix $(obj)/,$(host-csingle))
+host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
+host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
+host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
+host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
+host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
HOST_EXTRACFLAGS += -I$(obj) -DCONFIG_=\"\"
$(host-csingle): %: %.c
- $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$@) $< -o $(obj)/$@
+ $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$@) $< -o $@
$(host-cmulti): %: $(host-cobjs) $(host-cshlib)
- $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$@) $(addprefix $(obj)/,$($(@F)-objs)) $(HOSTLOADLIBES_$(@F)) -o $(obj)/$@
+ $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$@) $(addprefix $(obj)/,$($(@F)-objs)) $(HOSTLOADLIBES_$(@F)) -o $@
$(host-cxxmulti): %: $(host-cxxobjs) $(host-cobjs) $(host-cshlib)
- $(HOSTCXX) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCXXFLAGS_$@) $(addprefix $(obj)/,$($(@F)-objs) $($(@F)-cxxobjs)) $(HOSTLOADLIBES_$(@F)) -o $(obj)/$@
+ $(HOSTCXX) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCXXFLAGS_$@) $(addprefix $(obj)/,$($(@F)-objs) $($(@F)-cxxobjs)) $(HOSTLOADLIBES_$(@F)) -o $@
$(obj)/%.o: %.c
$(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) -c $< -o $@