polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

Makefile (1608B)


      1 NAME ?= polyadvent
      2 BIN ?= $(NAME)
      3 PREFIX ?= /usr/local
      4 DEFS= -DGLFW_INCLUDE_NONE
      5 # release build lol
      6 # DEFS= -DGLFW_INCLUDE_NONE -DNDEBUG
      7 
      8 # CFLAGS = $(DEFS) -ggdb -O0 -I src -Wall -Wextra -std=c99 \
      9 
     10 CFLAGS = $(DEFS) -O1 -g -I src -Wall -Werror -Wextra -std=c99  \
     11 						-Wno-unused-function \
     12 						-Wno-unused-parameter \
     13 						-Wno-unused-variable \
     14 						-Wmissing-field-initializers \
     15 						-Wno-cast-align \
     16 						-Wno-padded
     17 LDFLAGS = -lSDL2 -lGL -lm
     18 SRC=src
     19 
     20 SRCS=$(wildcard $(SRC)/*.c)
     21 PLYS=$(wildcard data/models/*.ply)
     22 
     23 MODELS=$(PLYS:.ply=.mdl)
     24 OBJS=$(SRCS:.c=.o)
     25 
     26 TESTS =  test/test_dae
     27 TESTS += test/test_resource
     28 TESTS += test/test_scene
     29 
     30 TOOLS = tools/compile-model
     31 
     32 all: $(BIN) $(MODELS)
     33 
     34 clean:
     35 	rm -f main.o polyadvent.o src/main.o test/*.o tools/*.o $(OBJS) $(TESTS) $(TOOLS) $(MODELS) $(SHLIB) $(BIN) $(SRC)/*.d*
     36 
     37 %.d: %.c
     38 	@rm -f $@; \
     39 	$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
     40 	sed 's,\(.*\)\.o[ :]*,src/\1.o $@ : ,g' < $@.$$$$ > $@; \
     41 	rm -f $@.$$$$
     42 
     43 %.o: %.c %.h
     44 	@echo "cc $<"
     45 	@$(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
     46 
     47 test/%: test/%.o $(OBJS)
     48 	@echo "link $@"
     49 	@$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
     50 
     51 tools/%: tools/%.o $(OBJS)
     52 	@echo "link $@"
     53 	@$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
     54 
     55 tools: $(TOOLS)
     56 
     57 data/models/%.mdl: data/models/%.ply tools/compile-model
     58 	@echo "compile-model $@"
     59 	@./tools/compile-model $< $@
     60 
     61 check: $(TESTS) $(MODELS)
     62 	./test/test_dae
     63 	./test/test_resource
     64 	./test/test_scene
     65 
     66 $(BIN): main.o $(OBJS)
     67 	@echo "link $@"
     68 	@$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
     69 
     70 install: $(BIN)
     71 	install -d $(PREFIX)/bin
     72 	install $(BIN) $(PREFIX)/bin
     73 
     74 TAGS:
     75 	etags $(SRCS)
     76 
     77 .PHONY: TAGS