summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile36
1 files changed, 24 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 2d77ef1..b0f3b83 100644
--- a/Makefile
+++ b/Makefile
@@ -29,6 +29,11 @@ base_src := $(wildcard *_base.cpp)
base_src += library.cpp sprite.cpp font.cpp main.cpp
base_obj := $(patsubst %.cpp,build/%.o,$(base_src))
+categories := object sprite font
+category_headers := $(foreach c,$(categories),build/$(c)s.h)
+
+all_objects := $(base_obj) $(foreach c,$(categories),$($(c)_obj))
+
.PHONY: all clean remake run
#keep all intermediate files!
@@ -40,6 +45,7 @@ base_obj := $(patsubst %.cpp,build/%.o,$(base_src))
all: $(BIN)
clean:
+ echo Cleaning
rm -rf build $(BIN)
remake: clean all
@@ -48,17 +54,28 @@ run: all
printf "\x1B[1mRUNNING...\x1B[0m\n"
./$(BIN)
+kaas:
+ echo $(all_objects)
-$(BIN): $(base_obj) $(object_obj) $(sprite_obj) $(font_obj)
+
+$(BIN): $(all_objects)
echo Linking
- $(CXX) $(CXXFLAGS) $(LIBS) -o $(BIN) $^
+ $(CXX) $(CXXFLAGS) -o $(BIN) $^ $(LIBS)
+
-build/main.o: main.cpp build/objects.h build/sprites.h build/fonts.h
+build/main.o: main.cpp $(category_headers)
echo Building main
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c -o "$@" "$<" "-DOBJECT_CLASSES_XLIST=$(object_xlist)" "-DGAME_NAME=\"$(BIN)\""
-build/objects/%.o: build/objects/%.cpp build/objects.h build/sprites.h build/fonts.h
+
+build/%.o: %.cpp
+ echo Compiling $*
+ mkdir -p $(dir $@)
+ $(CXX) $(CXXFLAGS) -c -o "$@" $^
+
+
+build/objects/%.o: build/objects/%.cpp $(category_headers)
echo Building $*
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c -o "$@" "$<"
@@ -77,11 +94,6 @@ build/objects.h: $(object_head)
echo Collecting header files
echo $(object_head) | xargs -n 1 basename | sed 's,.*,#include "objects/&",' >"$@"
-build/%.o: %.cpp
- echo Compiling $*
- mkdir -p $(dir $@)
- $(CXX) $(CXXFLAGS) -c -o "$@" $^
-
build/sprites/%.o: build/sprites/%.cpp
echo Building sprite $*
@@ -94,7 +106,7 @@ build/sprites/%.cpp: src/sprites/%.png
printf "#include \"sprite.h\"\n\nstatic const unsigned char data[]={\n%s\n};\n\nstatic Sprite struct_data=Sprite(data,%d);\nSprite *$*=&struct_data;\n" "$$($(BIN2C) <"$<")" $$(stat -f '%z' "$<") >"$@"
build/sprites.h: $(sprite_fnames)
- echo Collecting generated sprite files
+ echo Writing collected sprites header
mkdir -p $(dir $@)
printf "#include \"sprite.h\"\n\n$(sprite_externs)\n" >"$@"
test -z "$(sprite_skipped)" || printf "\x1B[1mWARNING: skipped files in src/sprites: $(notdir $(sprite_skipped))\x1B[0m\n"
@@ -105,13 +117,13 @@ build/fonts/%.o: build/fonts/%.cpp
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c -o "$@" "$<"
-build/fonts/%.cpp: src/fonts/%.*
+build/fonts/%.cpp: src/fonts/%.ttf
echo Generating for font $*
mkdir -p $(dir $@)
printf "#include \"font.h\"\n\nstatic const unsigned char data[]={\n%s\n};\n\nstatic Font struct_data=Font(data,%d);\nFont *$*=&struct_data;\n" "$$($(BIN2C) <"$<")" $$(stat -f '%z' "$<") >"$@"
build/fonts.h: $(font_fnames)
- echo Collecting generated font files
+ echo Writing collected fonts header
mkdir -p $(dir $@)
printf "#include \"font.h\"\n\n$(font_externs)\n" >"$@"
test -z "$(font_skipped)" || printf "\x1B[1mWARNING: skipped files in src/fonts: $(notdir $(font_skipped))\x1B[0m\n"