diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-12-29 10:57:15 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-12-29 10:57:30 +0100 |
commit | 6286f890c132b9cd6a36d585735e5d7310dc0abf (patch) | |
tree | 32b2e697fa0030fdd410eba0d2626e8fd511c7ed /Makefile | |
parent | ac18b3132059b5e7d5f00ccf2b56e543cf0da84b (diff) |
Sprites, object destruction
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 54 |
1 files changed, 44 insertions, 10 deletions
@@ -1,5 +1,5 @@ CXX := g++ -CXXFLAGS := -Wall -Wextra -std=c++11 -O2 -isystem /usr/local/include -I. +CXXFLAGS := -Wall -Wextra -std=c++11 -O2 -I. LIBS := -lfltk -L/usr/local/lib BIN := game @@ -8,6 +8,12 @@ object_obj := $(patsubst src/objects/%.cpp,build/objects/%.o,$(object_src)) object_head := $(patsubst src/objects/%.cpp,build/objects/%.h,$(object_src)) object_xlist := $(shell echo $$(for f in $(object_src); do basename $$f | sed 's/\.[^.]*$$//' | sed 's/.*/X(&)/'; done)) +sprite_allfiles := $(wildcard src/sprites/*) +sprite_fnames := $(filter %.png,$(sprite_allfiles)) +sprite_skipped := $(filter-out %.png,$(sprite_allfiles)) +sprite_obj := $(patsubst src/sprites/%.png,build/sprites/%.o,$(sprite_fnames)) +sprite_externs := $(shell echo $$(for f in $(sprite_obj); do basename $$f | sed 's/\.[^.]*$$//' | sed 's/.*/extern const unsigned char &[];/'; done)) + base_src := $(wildcard *_base.cpp) base_src += library.cpp main.cpp base_obj := $(patsubst %.cpp,build/%.o,$(base_src)) @@ -17,6 +23,9 @@ base_obj := $(patsubst %.cpp,build/%.o,$(base_src)) #keep all intermediate files! .SECONDARY: +#we handle our own printing +.SILENT: + all: $(BIN) clean: @@ -25,31 +34,56 @@ clean: remake: clean all run: all + printf "\x1B[1mRUNNING...\x1B[0m\n" ./$(BIN) -$(BIN): $(base_obj) $(object_obj) +$(BIN): $(base_obj) $(object_obj) $(sprite_obj) + echo Linking $(CXX) $(CXXFLAGS) $(LIBS) -o $(BIN) $^ -build/main.o: main.cpp build/objects.h - @mkdir -p $(dir $@) +build/main.o: main.cpp build/objects.h build/sprites.h + echo Building main + mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -c -o "$@" "$<" "-DOBJECT_CLASSES_XLIST=$(object_xlist)" "-DGAME_NAME=\"$(BIN)\"" -build/objects/%.o: build/objects/%.cpp - @mkdir -p $(dir $@) - $(CXX) $(CXXFLAGS) -c -o "$@" $^ +build/objects/%.o: build/objects/%.cpp build/objects.h build/sprites.h + echo Building $* + mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -c -o "$@" "$<" build/objects/%.cpp: src/objects/%.cpp - @mkdir -p $(dir $@) + echo Generating source for $* + mkdir -p $(dir $@) $(CXX) -E object_wrapper.cpp "-D__OBJECT_FNAME__=\"$<\"" "-D__OBJECT_NAME__=$(basename $(notdir $<))" | sed 's/^# [0-9]\+ ".*//' >"$@" build/objects/%.h: src/objects/%.cpp - @mkdir -p $(dir $@) + echo Generating header for $* + mkdir -p $(dir $@) $(CXX) -E object_header_maker.cpp "-D__OBJECT_NAME__=$(basename $(notdir $<))" "-DEVENT_XLIST=$$($(CXX) -E object_header_extractor.cpp "-D__OBJECT_FNAME__=\"$<\"" | sed 's/__________EVENT_NEWLINE__________/\n/g' | grep -oe '__________EVENT_COUNTER_TAG_[^_]*__________' | sed 's/[^G]*G_\(.*\)__________.*/X(\1)/g' | xargs)" | sed 's/^# [0-9]\+ ".*//' >"$@" build/objects.h: $(object_head) + echo Collecting header files echo $(object_head) | xargs -n 1 basename | sed 's,.*,#include "objects/&",' >"$@" build/%.o: %.cpp - @mkdir -p $(dir $@) + echo Compiling $* + mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -c -o "$@" $^ + + +build/sprites/%.o: build/sprites/%.cpp + echo Building sprite $* + mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -Wno-unused-const-variable -c -o "$@" "$<" + +build/sprites/%.cpp: src/sprites/%.png + echo Generating for sprite $* + mkdir -p $(dir $@) + printf "const unsigned char $*[]={\n%s, 0\n};\nconst unsigned int _$*_len=%d;\n" "$$(xxd -i <"$<")" $$(stat -f '%z' "$<") >"$@" + +build/sprites.h: + echo Collecting generated sprite files + mkdir -p $(dir $@) + echo "$(sprite_externs)" >"$@" + test -z "$(sprite_skipped)" || printf "\x1B[1mWARNING: skipped files in src/sprites: $(notdir $(sprite_skipped))\x1B[0m\n" |