-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
114 lines (89 loc) · 2.46 KB
/
Copy pathMakefile
File metadata and controls
114 lines (89 loc) · 2.46 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Directories
SRC_DIR ?=./src
TESTS_DIR ?=./tests
EXAMPLES_DIR ?=./examples
TESTS_SRC_FILES ?=$(wildcard $(TESTS_DIR)/*.c)
# Compiler
CC ?=clang
CFLAGS ?=-ansi -pedantic -std=c99 -Wall -O3
LDFLAGS ?=-lm
GUI_LDFLAGS ?=$(LDFLAGS) -lraylib
GUI_FLAGS ?=$(shell pkg-config --cflags --libs raylib) $(LDFLAGS)
# Flags
INCLUDES ?=-I$(SRC_DIR)
GUI_INCLUDES ?=$(INCLUDES)
TESTS_INCLUDES ?=-I./tests $(INCLUDES)
# Binaries
XOR_BIN ?=nn_xor
TEST_BIN ?=nn_tests
ADDER_BIN ?=nn_adder
ADDER_GUI_BIN ?=nn_adder_gui
IMG_UPSCALE_GUI_BIN ?=nn_img_upscale_gui
RSA_DECRYPT_GUI_BIN ?=nn_rsa_decrypt_gui
# Verbosity
VERBOSE ?=false
ifneq ($(VERBOSE), true)
HIDE =
else
HIDE = @
endif
# Text colors
_SET_RED := @echo "\033[31m" # Red text for "printf"
_SET_WHITE := @echo "\033[0m" # White text for "printf"
_SET_GREEN := @echo "\033[32m" # Green text for "printf"
# Makefile rules
.PHONY:\
all\
clean\
tests\
examples\
xor\
adder\
adder_gui\
rsa_decrypt_gui\
img_upscale_gui
all:\
examples
tests:\
nn_tests\
nn_matrix_tests
examples:\
xor\
adder\
adder_gui\
img_upscale_gui\
rsa_decrypt_gui# Doesn't work, but was interesting to try out
xor: $(XOR_BIN)
adder: $(ADDER_BIN)
adder_gui: $(ADDER_GUI_BIN)
rsa_decrypt_gui: $(RSA_DECRYPT_GUI_BIN)
img_upscale_gui: $(IMG_UPSCALE_GUI_BIN)
nn_tests: $(TESTS_DIR)/nn_tests.c
$(HIDE)$(CC) $(CFLAGS) $(TESTS_INCLUDES) $^ -o $@ $(LDFLAGS)
nn_matrix_tests: $(TESTS_DIR)/nn_matrix_tests.c
$(HIDE)$(CC) $(CFLAGS) $(TESTS_INCLUDES) $^ -o $@ $(LDFLAGS)
$(XOR_BIN): $(EXAMPLES_DIR)/nn_xor.c
$(HIDE)$(CC) $(CFLAGS) $(INCLUDES) $^ -o $@ $(LDFLAGS)
$(ADDER_BIN): $(EXAMPLES_DIR)/nn_adder.c
$(HIDE)$(CC) $(CFLAGS) $(INCLUDES) $^ -o $@ $(LDFLAGS)
$(ADDER_GUI_BIN): $(EXAMPLES_DIR)/nn_adder_gui.c
$(HIDE)$(CC) $(CFLAGS) $(INCLUDES) $(GUI_FLAGS) $^ -o $@
$(RSA_DECRYPT_GUI_BIN): $(EXAMPLES_DIR)/nn_rsa_decrypt_gui.c
$(HIDE)$(CC) $(CFLAGS) $(INCLUDES) $(GUI_FLAGS) $^ -o $@
$(IMG_UPSCALE_GUI_BIN): $(EXAMPLES_DIR)/nn_upscale_png.c
$(HIDE)$(CC) $(CFLAGS) $(INCLUDES) $(GUI_FLAGS) $^ -o $@
clean: \
$(eval BINARIES:=$(strip $(shell find -maxdepth 1 -type f -executable -print)))\
$(eval BINARIES:=$(filter-out $(wildcard ./*.sh), $(BINARIES)))\
$(eval RMBIN:=rm $(BINARIES))
ifneq ($(BINARIES),)
@echo "\nmake clean wants to execute the following command:"
$(_SET_RED)
@echo "$(RMBIN)"
$(_SET_WHITE)
@echo -n "Do you accept? [y/n] " && read ans && [ $${ans:-N} = y ]
$(RMBIN)
endif
$(_SET_GREEN)
@echo "Cleaning Done."
$(_SET_WHITE)