Permalink
Browse files

Tweak build system to allow out-of-tree projects.

It's very annoying to have to build libmaple projects in-tree. Users
are just copying the repository everywhere. That's stupid. So I made this:

https://github.com/mbolivar/example-libmaple-project

It needs these patches to work.

Add a header and footer for rules.mk files, so we can change them
around and things will continue to work for the users, who just
include them.

In Makefile, add USER_MODULES to LIBMAPLE_MODULES if it's
nonempty. This is the hook you use to get your code compiled and
linked correctly.

Hack build-targets.mk for stupid reasons I hope to fix later. For now,
you'll need an empty main.cpp in BOTH the libmaple directory and your
directory if you want things to work the way you'd expect.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
  • Loading branch information...
1 parent fece8e8 commit be75a466b7048b8a4024714f78e65a9b3f1a8836 Marti Bolivar committed Jun 15, 2012
Showing with 29 additions and 7 deletions.
  1. +6 −6 Makefile
  2. +1 −1 build-targets.mk
  3. +18 −0 support/make/footer.mk
  4. +4 −0 support/make/header.mk
View
@@ -67,12 +67,7 @@ include $(SUPPORT_PATH)/make/build-templates.mk
## Set all submodules here
##
-# Try to keep LIBMAPLE_MODULES a simply-expanded variable
-ifeq ($(LIBMAPLE_MODULES),)
- LIBMAPLE_MODULES := $(SRCROOT)/libmaple
-else
- LIBMAPLE_MODULES += $(SRCROOT)/libmaple
-endif
+LIBMAPLE_MODULES += $(SRCROOT)/libmaple
LIBMAPLE_MODULES += $(LIBMAPLE_MODULE_FAMILY) # family submodule in libmaple
LIBMAPLE_MODULES += $(SRCROOT)/wirish
# Official libraries:
@@ -83,6 +78,11 @@ LIBMAPLE_MODULES += $(SRCROOT)/libraries/Wire
# Experimental libraries:
LIBMAPLE_MODULES += $(SRCROOT)/libraries/FreeRTOS
+# User modules:
+ifneq ($(USER_MODULES),)
+LIBMAPLE_MODULES += $(USER_MODULES)
+endif
+
# Call each module's rules.mk:
$(foreach m,$(LIBMAPLE_MODULES),$(eval $(call LIBMAPLE_MODULE_template,$(m))))
View
@@ -1,5 +1,5 @@
# main project target
-$(BUILD_PATH)/main.o: main.cpp
+$(BUILD_PATH)/main.o: $(SRCROOT)/main.cpp
$(SILENT_CXX) $(CXX) $(CFLAGS) $(CXXFLAGS) $(LIBMAPLE_INCLUDES) $(WIRISH_INCLUDES) -o $@ -c $<
$(BUILD_PATH)/libmaple.a: $(BUILDDIRS) $(TGT_BIN)
View
@@ -0,0 +1,18 @@
+sFILES_$(d) := $(sSRCS_$(d):%=$(d)/%)
+cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%)
+cppFILES_$(d) := $(cppSRCS_$(d):%=$(d)/%)
+
+OBJS_$(d) := $(sFILES_$(d):%.S=$(BUILD_PATH)/%.o) \
+ $(cFILES_$(d):%.c=$(BUILD_PATH)/%.o) \
+ $(cppFILES_$(d):%.cpp=$(BUILD_PATH)/%.o)
+DEPS_$(d) := $(OBJS_$(d):%.o=%.d)
+
+$(OBJS_$(d)): TGT_CFLAGS := $(CFLAGS_$(d))
+$(OBJS_$(d)): TGT_CXXFLAGS := $(CXXFLAGS_$(d))
+$(OBJS_$(d)): TGT_ASFLAGS := $(ASFLAGS_$(d))
+
+TGT_BIN += $(OBJS_$(d))
+
+-include $(DEPS_$(d))
+d := $(dirstack_$(sp))
+sp := $(basename $(sp))
View
@@ -0,0 +1,4 @@
+sp := $(sp).x
+dirstack_$(sp) := $(d)
+d := $(dir)
+BUILDDIRS += $(BUILD_PATH)/$(d)

0 comments on commit be75a46

Please sign in to comment.