commit 78477aee9aab58fd257c5ccbe5b381d3dfd59a03
parent 3f35f0572096f172faf46f765d1b328b86db1d82
Author: Brian Swetland <swetland@frotz.net>
Date: Sun, 16 Jun 2013 16:26:44 -0700
modernize build system (handle autodeps, asset copies, etc)
Diffstat:
7 files changed, 190 insertions(+), 42 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,61 @@
+## Copyright 2013 Brian Swetland <swetland@frotz.net>
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+
+what_to_build:: all
+
+-include local.mk
+
+SDLCFG := /work/sdl2/bin/sdl2-config
+
+SDLFLAGS := $(shell $(SDLCFG) --cflags)
+SDLLIBS := $(shell $(SDLCFG) --static-libs)
+
+HOST_CFLAGS := $(SDLFLAGS) -Wall -g -O2
+HOST_CFLAGS += -std=c++0x
+HOST_CFLAGS += -Icommon
+#HOST_CFLAGS += -ffunction-sections -fdata-sections
+
+HOST_LFLAGS := -static-libstdc++
+#HOST_LFLAGS += -Wl,-gc-sections
+
+GLLIB := /usr/lib/nvidia-experimental-310/libGL.so.310.14
+#GLLIB := -lGL
+HOST_LIBS := $(SDLLIBS) $(GLLIB) -lm -lpng
+
+include $(wildcard arch/*/config.mk)
+
+OUT := out
+OUT_OBJ := $(OUT)/_obj
+OUT_LIB := $(OUT)/_lib
+
+ALL :=
+DEPS :=
+
+MKDIR = if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
+
+QUIET ?= @
+
+# additional modules
+include $(wildcard */module.mk)
+
+clean::
+ @echo clean
+ @rm -rf $(OUT)
+
+# we generate .d as a side-effect of compiling. override generic rule:
+%.d:
+-include $(DEPS)
+
+all:: $(ALL)
+
diff --git a/build/app.mk b/build/app.mk
@@ -0,0 +1,59 @@
+## Copyright 2013 Brian Swetland <swetland@frotz.net>
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+
+M_NAME := $(strip $(M_NAME))
+
+# sanity check
+ifeq "$(M_NAME)" ""
+$(error No module name specified)
+endif
+
+M_OBJS := $(addprefix $(OUT_OBJ)/$(M_NAME)/,$(M_OBJS))
+DEPS += $(M_OBJS:%o=%d)
+
+ASSETS := $(wildcard $(M_NAME)/assets/*)
+ASSETS += $(patsubst common/%,$(M_NAME)/%,$(wildcard common/assets/*))
+ASSETS := $(addprefix $(OUT)/,$(ASSETS))
+
+$(OUT)/$(M_NAME)/assets/%: $(M_NAME)/assets/%
+ @$(MKDIR)
+ cp $< $@
+
+$(OUT)/$(M_NAME)/assets/%: common/assets/%
+ @$(MKDIR)
+ cp $< $@
+
+M_LIBS := $(addprefix $(OUT_LIB)/,$(M_LIBS))
+M_LIBS := $(addsuffix .a,$(M_LIBS))
+
+ALL += $(OUT)/$(M_NAME)/$(M_NAME)
+
+$(OUT_OBJ)/$(M_NAME)/%.o: $(M_NAME)/%.cc
+ @$(MKDIR)
+ @echo compile $<
+ $(QUIET)g++ $(HOST_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)
+ @$(MKDIR)
+ @echo link $@
+ $(QUIET)g++ $(HOST_CFLAGS) -o $@ $(_OBJS) $(_LIBS) $(HOST_LIBS)
+
+$(info module $(M_NAME))
+
+M_LIBS :=
+M_OBJS :=
+M_NAME :=
+
diff --git a/build/lib.mk b/build/lib.mk
@@ -0,0 +1,44 @@
+## Copyright 2013 Brian Swetland <swetland@frotz.net>
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+
+M_NAME := $(strip $(M_NAME))
+
+# sanity check
+ifeq "$(M_NAME)" ""
+$(error No module name specified)
+endif
+
+M_OBJS := $(addprefix $(OUT_OBJ)/$(M_NAME)/,$(M_OBJS))
+DEPS += $(M_OBJS:%o=%d)
+
+ALL += $(OUT_LIB)/$(M_NAME).a
+
+$(OUT_OBJ)/$(M_NAME)/%.o: $(M_NAME)/%.cc
+ @$(MKDIR)
+ @echo compile $<
+ $(QUIET)g++ $(HOST_CFLAGS) -c $< -o $@ -MD -MT $@ -MF $(@:%o=%d)
+
+$(OUT_LIB)/$(M_NAME).a: _OBJS := $(M_OBJS)
+$(OUT_LIB)/$(M_NAME).a: $(M_OBJS)
+ @$(MKDIR)
+ @echo archive $@
+ @rm -f $@
+ $(QUIET)ar cr $@ $(_OBJS)
+
+$(info module $(M_NAME))
+
+M_LIBS :=
+M_OBJS :=
+M_NAME :=
+
diff --git a/common/module.mk b/common/module.mk
@@ -0,0 +1,14 @@
+
+M_NAME := common
+M_OBJS := glapp.o
+M_OBJS += io.o
+M_OBJS += loadfile.o
+M_OBJS += loadpng.o
+M_OBJS += loadobj.o
+M_OBJS += matrix.o
+M_OBJS += savepng.o
+M_OBJS += simplexnoise.o
+M_OBJS += textgrid.o
+M_LIBS := common
+
+include build/lib.mk
diff --git a/hello/Makefile b/hello/Makefile
@@ -1,42 +0,0 @@
-
-SDLCFG := /work/sdl2/bin/sdl2-config
-
-SDLFLAGS := $(shell $(SDLCFG) --cflags)
-SDLLIBS := $(shell $(SDLCFG) --static-libs)
-
-CFLAGS := $(SDLFLAGS) -Wall -g -O2
-CFLAGS += -ffunction-sections -fdata-sections
-CFLAGS += -std=c++0x
-CFLAGS += -I../common
-
-LFLAGS := -static-libstdc++
-LFLAGS += -Wl,-gc-sections
-
-CXXFLAGS := $(CFLAGS)
-
-GLLIB := /usr/lib/nvidia-experimental-310/libGL.so.310.14
-#GLLIB := -lGL
-LIBS := $(SDLLIBS) $(GLLIB) -lm -lpng
-
-LIBOBJS := ../common/loadfile.o
-LIBOBJS += ../common/loadobj.o
-LIBOBJS += ../common/loadpng.o
-LIBOBJS += ../common/savepng.o
-LIBOBJS += ../common/simplexnoise.o
-LIBOBJS += ../common/matrix.o
-LIBOBJS += ../common/textgrid.o
-LIBOBJS += ../common/glapp.o
-LIBOBJS += ../common/io.o
-
-OBJS := hello.o
-
-all: hello
-
-hello: $(OBJS) $(LIBOBJS)
- $(CXX) $(LFLAGS) -o hello $(OBJS) $(LIBOBJS) $(LIBS)
-
-test: test.o $(LIBOBJS)
- $(CXX) $(LFLAGS) -o test test.o $(LIBOBJS) $(LIBS)
-
-clean:
- rm -f *.o ../common/*.o hello test
diff --git a/hello/module.mk b/hello/module.mk
@@ -0,0 +1,6 @@
+
+M_NAME := hello
+M_OBJS := hello.o
+M_LIBS := common
+
+include build/app.mk
diff --git a/test/module.mk b/test/module.mk
@@ -0,0 +1,6 @@
+
+M_NAME := test
+M_OBJS := test.o
+M_LIBS := common
+
+include build/app.mk