Initial Framework
[henge/webcc.git] / src / Makefile
1 #Mihrtec Standard Makefile
2 #Author: ksg
3
4 #Project Info
5 APPNAME := the_march
6 MODULES := core
7 CFLAGS := -Wall
8 APP_RULES :=
9 CLEAN_RULES :=
10 SCRUB_RULES :=
11
12
13 ifdef EMSCRIPTEN_TOOLS
14 #Emscripten build environment
15 APP_RULES += move
16 HTML := index.html js/the_march.config.js
17 CC := emcc
18 EXPORTS := '_em_main'
19 EMOPTS := --separate-asm -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 --pre-js html/js/pre.js
20 LIBS += -s USE_SDL=2 -s USE_SDL_TTF=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]'
21 EXEPATH := ../dist/bin/jasm/js
22 EXE := $(APPNAME).js
23 OBJFILE :=bc
24 EMFLAGS := $(EMOPTS) $(LIBS) -s EXPORTED_FUNCTIONS="[$(EXPORTS)]"
25 EMFLAGS += -I/usr/include/google
26 BYPRODUCT := $(APPNAME).asm.js $(APPNAME).js.mem
27 else
28 #Native Build Environment
29 CC := gcc
30 LIBS := -lprotobuf-c
31 LIBS += -lSDL2_ttf -lSDL2_image -lSDL2main -lSDL2 -lopengl32
32 EXEPATH := ../dist/bin/$(shell uname -m)
33 #windows mingw build rules
34 ifeq ($(OS), Windows_NT)
35 LIBS := -lmingw32 -mwindows $(LIBS)
36 EXE := $(APPNAME).exe
37 else
38 EXE := $(APPNAME)
39 endif
40 OBJFILE :=o
41 endif
42
43 #-I each of the module directories, include directory, and define APPNAME.
44 CFLAGS += $(patsubst %,-I%, $(MODULES))
45 CFLAGS += -Iinclude -I.
46 CFLAGS += -DAPPNAME=$(APPNAME)
47
48 #auto include all .c files
49 SRC += $(patsubst %,%/*.c,$(MODULES))
50 SRC := $(wildcard $(SRC))
51
52 #Targets that don't generate a file
53 .PHONY: $(APPNAME) run push dox doc clean scrub all default move
54 #Define default rules to point to APPNAME
55 all default: clean $(APPNAME)
56
57 #include rules from any .mk file found in a module directory
58 include $(wildcard $(patsubst %,%/*.mk,$(MODULES)))
59
60 #populate C objects and dependency files to generate from SRC
61 COBJ += $(patsubst %.c,%.$(OBJFILE), $(filter %.c,$(SRC)))
62 CDEP += $(COBJ:.$(OBJFILE)=.d)
63
64 include $(CDEP)
65
66 #Build the executable
67 $(APPNAME): $(APP_RULES) $(CDEP) $(COBJ)
68 @mkdir -p $(EXEPATH)
69 $(CC) -o $(EXEPATH)/$(EXE) $(EMFLAGS) $(CXXFLAGS) $(CFLAGS) core/main.$(OBJFILE) $(LIBS)
70
71 #run the game after making it
72 run: $(APPNAME)
73 $(EXEPATH)/$(EXE)
74
75 #push to github after successful compile
76 push: $(APPNAME)
77 @printf '\nEnter a commit message:\n'; \
78 read CMT; \
79 git commit -am "$$CMT"
80 git push origin master
81
82 dox doc:
83 doxygen dox.conf
84
85 #clean up intermediate dependency files and binaries
86 clean: $(CLEAN_RULES)
87 @echo "Cleaning - Recompiling .d (deps) and .$(OBJFILE) (obj)"
88 @rm -f $(EXEPATH)/$(EXE) $(patsubst %,$(EXEPATH)/%, $(BYPRODUCT))
89 @rm -f $(patsubst %,%/*.$(OBJFILE), $(MODULES))
90 @rm -f $(patsubst %,%/*.d, $(MODULES))
91
92 #Scrub down to minimal distribution
93 scrub: clean $(SCRUB_RULES)
94
95 #construct list of move rules for each HTML item
96 .PHONY: $(HTML)
97 $(HTML):
98 @cp -f html/$@ ../dist/bin/jasm/$@
99 #move js/html files
100 move: $(HTML)
101
102 ################## DEFAULTS #####################
103 #cancel default %.o behavior for %.d dependency
104 %.o : %.c
105
106 #new default .o for .c files
107 %.bc %.o: %.c %.d
108 $(CC) -c $(EMFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@
109
110 #default for .d dependency files (output from gcc -M)
111 %.d: %.c
112 @./deps.sh 'dirname $*.c' $(CFLAGS) $*.c > $@
113 @sed -i 's/$(*F)[\.]o/$(@D)\/$(*F)\.o/g' $@
114 @cat $@ | sed 's/[\.][o]/.bc/g' >> $@
115