commit c23ed10c9bdf84217448a65790d031056e817347
parent 45b83c1e3a91b1d33b942388657c46df7abf31d2
Author: Brian Swetland <swetland@frotz.net>
Date: Fri, 21 Jun 2013 00:29:59 -0700
build: allow module name and path to differ, support C code in libraries
Diffstat:
6 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/Makefile b/Makefile
@@ -46,6 +46,8 @@ MKDIR = if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
QUIET ?= @
+modulepath = $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
+
# additional modules
include $(wildcard */module.mk)
diff --git a/build/app.mk b/build/app.mk
@@ -13,40 +13,46 @@
## limitations under the License.
M_NAME := $(strip $(M_NAME))
+M_PATH := $(strip $(M_PATH))
# sanity check
ifeq "$(M_NAME)" ""
$(error No module name specified)
endif
+ifeq "$(M_PATH)" ""
+$(error No module path specified)
+endif
-M_OBJS := $(addprefix $(OUT_OBJ)/$(M_NAME)/,$(M_OBJS))
+M_OBJS := $(addprefix $(OUT_OBJ)/$(M_PATH)/,$(M_OBJS))
DEPS += $(M_OBJS:%o=%d)
-ASSETS := $(wildcard $(M_NAME)/assets/*)
-ASSETS += $(patsubst common/%,$(M_NAME)/%,$(wildcard common/assets/*))
+ASSETS := $(wildcard $(M_PATH)/assets/*)
+ASSETS += $(patsubst common/%,$(M_PATH)/%,$(wildcard common/assets/*))
ASSETS := $(addprefix $(OUT)/,$(ASSETS))
-$(OUT)/$(M_NAME)/assets/%: $(M_NAME)/assets/%
+$(OUT)/$(M_PATH)/assets/%: $(M_PATH)/assets/%
@$(MKDIR)
cp $< $@
-$(OUT)/$(M_NAME)/assets/%: common/assets/%
+$(OUT)/$(M_PATH)/assets/%: common/assets/%
@$(MKDIR)
cp $< $@
M_LIBS := $(addprefix $(OUT_LIB)/,$(M_LIBS))
M_LIBS := $(addsuffix .a,$(M_LIBS))
-ALL += $(OUT)/$(M_NAME)/$(M_NAME)
+ALL += $(OUT)/$(M_PATH)/$(M_NAME)
+
+$(OUT_OBJ)/$(M_PATH)/%.o: _CFLAGS := $(M_CFLAGS)
-$(OUT_OBJ)/$(M_NAME)/%.o: $(M_NAME)/%.cc
+$(OUT_OBJ)/$(M_PATH)/%.o: $(M_PATH)/%.cc
@$(MKDIR)
@echo compile $<
- $(QUIET)g++ $(HOST_CFLAGS) -c $< -o $@ -MD -MT $@ -MF $(@:%o=%d)
+ $(QUIET)g++ $(HOST_CFLAGS) $(_CFLAGS) -c $< -o $@ -MD -MT $@ -MF $(@:%o=%d)
-$(OUT)/$(M_NAME)/$(M_NAME): _OBJS := $(M_OBJS)
-$(OUT)/$(M_NAME)/$(M_NAME): _LIBS := $(M_LIBS)
-$(OUT)/$(M_NAME)/$(M_NAME): $(M_OBJS) $(M_LIBS) $(ASSETS)
+$(OUT)/$(M_PATH)/$(M_NAME): _OBJS := $(M_OBJS)
+$(OUT)/$(M_PATH)/$(M_NAME): _LIBS := $(M_LIBS)
+$(OUT)/$(M_PATH)/$(M_NAME): $(M_OBJS) $(M_LIBS) $(ASSETS)
@$(MKDIR)
@echo link $@
$(QUIET)g++ $(HOST_CFLAGS) -o $@ $(_OBJS) $(_LIBS) $(HOST_LIBS)
@@ -56,4 +62,4 @@ $(info module $(M_NAME))
M_LIBS :=
M_OBJS :=
M_NAME :=
-
+M_CFLAGS :=
diff --git a/build/lib.mk b/build/lib.mk
@@ -13,21 +13,32 @@
## limitations under the License.
M_NAME := $(strip $(M_NAME))
+M_PATH := $(strip $(M_PATH))
# sanity check
ifeq "$(M_NAME)" ""
$(error No module name specified)
endif
+ifeq "$(M_PATH)" ""
+$(error No module path specified)
+endif
-M_OBJS := $(addprefix $(OUT_OBJ)/$(M_NAME)/,$(M_OBJS))
+M_OBJS := $(addprefix $(OUT_OBJ)/$(M_PATH)/,$(M_OBJS))
DEPS += $(M_OBJS:%o=%d)
ALL += $(OUT_LIB)/$(M_NAME).a
-$(OUT_OBJ)/$(M_NAME)/%.o: $(M_NAME)/%.cc
+$(OUT_OBJ)/$(M_PATH)/%.o: _CFLAGS := $(M_CFLAGS)
+
+$(OUT_OBJ)/$(M_PATH)/%.o: $(M_PATH)/%.cc
+ @$(MKDIR)
+ @echo compile $<
+ $(QUIET)g++ $(HOST_CFLAGS) $(_CFLAGS) -c $< -o $@ -MD -MT $@ -MF $(@:%o=%d)
+
+$(OUT_OBJ)/$(M_PATH)/%.o: $(M_PATH)/%.c
@$(MKDIR)
@echo compile $<
- $(QUIET)g++ $(HOST_CFLAGS) -c $< -o $@ -MD -MT $@ -MF $(@:%o=%d)
+ $(QUIET)g++ $(HOST_CFLAGS) $(_CFLAGS) -c $< -o $@ -MD -MT $@ -MF $(@:%o=%d)
$(OUT_LIB)/$(M_NAME).a: _OBJS := $(M_OBJS)
$(OUT_LIB)/$(M_NAME).a: $(M_OBJS)
@@ -41,4 +52,4 @@ $(info module $(M_NAME))
M_LIBS :=
M_OBJS :=
M_NAME :=
-
+M_CLFAGS :=
diff --git a/common/module.mk b/common/module.mk
@@ -1,3 +1,4 @@
+M_PATH := $(modulepath)
M_NAME := common
M_OBJS := glapp.o
diff --git a/hello/module.mk b/hello/module.mk
@@ -1,3 +1,4 @@
+M_PATH := $(modulepath)
M_NAME := hello
M_OBJS := hello.o
diff --git a/test/module.mk b/test/module.mk
@@ -1,3 +1,4 @@
+M_PATH := $(modulepath)
M_NAME := test
M_OBJS := test.o