diff options
Diffstat (limited to 'Makefile')
-rwxr-xr-x | Makefile | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..8bd5560 --- /dev/null +++ b/Makefile | |||
@@ -0,0 +1,51 @@ | |||
1 | .POSIX: | ||
2 | .SUFFIXES: | ||
3 | |||
4 | # Source code location and files to watch for changes. | ||
5 | SRC_DIR := src/bootstrap | ||
6 | BUILD_DIR := build | ||
7 | SRC_MAIN := $(SRC_DIR)/main.c | ||
8 | WATCH_SRC := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h") | ||
9 | INC_DIRS := $(shell find $(SRC_DIR) -type d) | ||
10 | INC_FLAGS := $(addprefix -I,$(INC_DIRS)) | ||
11 | |||
12 | # Output executable. | ||
13 | TARGET := bdl | ||
14 | BIN := $(BUILD_DIR)/$(TARGET) | ||
15 | |||
16 | # Compiler and linker configuration. | ||
17 | CC := cc | ||
18 | CFLAGS := -Wall -Wextra -pedantic | ||
19 | CFLAGS += $(INC_FLAGS) | ||
20 | LDFLAGS := | ||
21 | LDLIBS := | ||
22 | RELEASE_CFLAGS := -DNDEBUG -O2 | ||
23 | DEBUG_CFLAGS := -DDEBUG -O2 -g | ||
24 | |||
25 | .PHONY: tools clean run | ||
26 | |||
27 | # Setup debug/release builds. | ||
28 | # make clean && make <target> DEBUG=0 | ||
29 | # make clean && make <target> DEBUG=1 | ||
30 | DEBUG ?= 0 | ||
31 | ifeq ($(DEBUG), 1) | ||
32 | CFLAGS += $(DEBUG_CFLAGS) | ||
33 | else | ||
34 | CFLAGS += $(RELEASE_CFLAGS) | ||
35 | endif | ||
36 | |||
37 | main: tools $(BUILD_DIR) $(ROM) $(BIN) | ||
38 | |||
39 | $(BIN): $(SRC_MAIN) $(WATCH_SRC) | ||
40 | $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(SRC_MAIN) $(LDLIBS) | ||
41 | |||
42 | # Create build directory if needed. | ||
43 | $(BUILD_DIR): tools | ||
44 | mkdir -p $(BUILD_DIR) | ||
45 | |||
46 | run: $(BIN) | ||
47 | ./$(BIN) | ||
48 | |||
49 | # Remove build directory. | ||
50 | clean: | ||
51 | rm -rf $(BUILD_DIR) | ||