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