-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
73 lines (57 loc) · 2.86 KB
/
Copy pathMakefile
File metadata and controls
73 lines (57 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#I have not added header tracking, \
so just clean and remake when a header file changes
EXE = graphics
BINDINGS = image_lib.so
SRC_DIR = src
BINDINGS_DIR = bindings
TST_DIR = tst
SWIG_GEN_OUTPUT_DIR = bin/swig_output
OBJ_DIR = bin/obj
OUTPUT_DIR = bin
IMAGES_DIR = images
LUA_DIR = lua
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
OBJ_BINDINGS = $(SRC:$(SOURCE_BINDINGS)/%.c=$(OBJ_DIR)/%.o)
HEADERS = $(wildcard $(SRC_DIR)/*.h)
CPPFLAGS += -Iinclude -fPIC
CFLAGS += -Wall -Wextra -std=c11 -g # note that the g flag means that it compiles with debug symbols
LDFLAGS += -Llib -fPIC
LDLIBS += -lm -ljpeg -lz -lpng
.PHONY: all clean format fresh images run everything bindings lint
all: $(EXE)
$(EXE): $(OBJ)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $(OUTPUT_DIR)/$@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
bindings: all
# eventually fix this, move it to a dependency above'
# I'm using swig 4.0.2
swig -lua -o bin/swig_output/lua_bindings.c bindings/swig.i
$(CC) -I /usr/include/lua5.2 $(CPPFLAGS) $(CFLAGS) -c bin/swig_output/lua_bindings.c -llua5.2 -o $(OBJ_DIR)/lua_bindings.o
$(CC) $(LDFLAGS) $(OBJ) bin/obj/lua_bindings.o $(LDLIBS) -shared -o $(OUTPUT_DIR)/$(BINDINGS)
clean:
$(RM) $(OBJ)
$(RM) $(OBJ_DIR)/*
$(RM) $(SWIG_GEN_OUTPUT_DIR)/*.c
$(RM) $(OUTPUT_DIR)/$(EXE)
$(RM) $(IMAGES_DIR)/*.pam
$(RM) $(IMAGES_DIR)/*.png
$(RM) $(OUTPUT_DIR)/$(BINDINGS)
format:
clang-format -i $(SRC_DIR)/*.c $(SRC_DIR)/*.h
clang-format -i $(TST_DIR)/*.c
lint:
clang-tidy src/* -checks=-*,clang-analyzer-* --
fresh: clean test all
everything: clean all test bindings
target: clean format lint test all bindings
# TODO: clean up this target eventually. It should probably just build+link everything.
test:
gcc -w -g -std=c11 tst/test_math.c src/custom_math.c -o bin/tst/custom_math -lm && ./bin/tst/custom_math
gcc -w -g -std=c11 tst/test_linear_algebra.c src/custom_math.c src/linear_algebra.c -o bin/tst/linear_algebra -lm && ./bin/tst/linear_algebra
gcc -w -g -std=c11 tst/test_image.c src/custom_math.c src/image.c src/linear_algebra.c src/pixel.c -o bin/tst/image -lm && ./bin/tst/image
gcc -w -g -std=c11 tst/test_pixel.c src/custom_math.c src/image.c src/linear_algebra.c src/pixel.c -o bin/tst/pixel -lm && ./bin/tst/pixel
gcc -w -g -std=c11 tst/test_shape.c src/file_pam.c src/custom_math.c src/image.c src/linear_algebra.c src/pixel.c src/shape.c -o bin/tst/shape -lm && ./bin/tst/shape
gcc -w -g -std=c11 -g tst/test_jpeg.c src/file_jpeg.c src/custom_math.c src/image.c src/linear_algebra.c src/pixel.c src/shape.c -o bin/tst/jpg -lm -ljpeg && valgrind --error-exitcode=1 ./bin/tst/jpg
gcc -w -g -std=c11 -g tst/test_png.c src/file_png.c src/custom_math.c src/image.c src/linear_algebra.c src/pixel.c src/shape.c -o bin/tst/png -lm -lpng && valgrind --error-exitcode=1 ./bin/tst/png