diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 51 |
1 files changed, 33 insertions, 18 deletions
| @@ -1,27 +1,42 @@ | |||
| 1 | BIN = build/tb_ml | 1 | # Build configuration |
| 2 | SRC = source/tb_ml/tb_ml.c | 2 | BIN := build/tb_ml |
| 3 | SRC := source/tb_ml/tb_ml.c | ||
| 4 | OBJ := build/tb_ml.o | ||
| 5 | DEP := build/tb_ml.d | ||
| 3 | 6 | ||
| 4 | # CC = gcc | 7 | # Compiler flags |
| 5 | CC = clang | 8 | CC ?= clang |
| 9 | CFLAGS := -Wall -Wextra -Wpedantic -Wno-unused-function -g --std=c99 -fno-omit-frame-pointer | ||
| 10 | LDFLAGS := -lm | ||
| 6 | 11 | ||
| 7 | COMPILER := $(shell $(CC) --version | grep -o "gcc\|clang" | head -1) | 12 | # Optimization level |
| 13 | OPT ?= 0 | ||
| 14 | CFLAGS += -O$(OPT) | ||
| 8 | 15 | ||
| 9 | # check for compile optimizations per compiler | 16 | # Build directory |
| 10 | ifeq ($(COMPILER),gcc) | 17 | $(shell mkdir -p build) |
| 11 | CFLAGS = -Wall -Wextra -Wpedantic -Wno-unused-function -g -Werror -O0 | ||
| 12 | else ifeq ($(COMPILER),clang) | ||
| 13 | CFLAGS = -Wall -Wextra -Wpedantic -Wno-unused-function -g -O0 | ||
| 14 | else | ||
| 15 | CFLAGS = -Wall -Wextra -Wpedantic -Wno-unused-function -g -O0 | ||
| 16 | endif | ||
| 17 | 18 | ||
| 18 | $(BIN): $(SRC) | 19 | # Targets |
| 19 | mkdir -p build | 20 | .PHONY: all run clean help |
| 20 | $(CC) $(CFLAGS) $< -o $@ | 21 | |
| 22 | all: $(BIN) | ||
| 23 | |||
| 24 | $(BIN): $(OBJ) | ||
| 25 | $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ | ||
| 26 | |||
| 27 | $(OBJ): $(SRC) | ||
| 28 | $(CC) $(CFLAGS) -MT $@ -MMD -MP -MF $(DEP) -c $< -o $@ | ||
| 29 | |||
| 30 | -include $(DEP) | ||
| 21 | 31 | ||
| 22 | run: $(BIN) | 32 | run: $(BIN) |
| 23 | $(BIN) | 33 | ./$(BIN) |
| 24 | 34 | ||
| 25 | .PHONY: clean | ||
| 26 | clean: | 35 | clean: |
| 27 | rm -rf build | 36 | rm -rf build |
| 37 | |||
| 38 | help: | ||
| 39 | @echo "make [OPT=0|1|2|3]" | ||
| 40 | @echo " all - Build (default)" | ||
| 41 | @echo " run - Build and run" | ||
| 42 | @echo " clean - Remove artifacts" | ||
