.POSIX: .SUFFIXES: # Source code location and files to watch for changes. SRC_DIR := src BUILD_DIR := build TESTS_DIR := tests TEST_FILES := $(wildcard $(TESTS_DIR)/*.bad) SRC_MAIN := $(SRC_DIR)/main.c SRC_RUN := tests/loops.bad WATCH_SRC := $(shell find $(SRC_DIR) -name "*.c" -or -name "*.s" -or -name "*.h") INC_DIRS := $(shell find $(SRC_DIR) -type d) INC_FLAGS := $(addprefix -I,$(INC_DIRS)) # Graphviz viz command. DOT := dot -Gmargin=0.7 -Gcolor=white -Gfontcolor=white \ -Ncolor=white -Nfontcolor=white \ -Ecolor=white -Efontcolor=white -Efontsize=15 \ -Efontname="Iosevka Nerd Font" \ -Nfontname="Iosevka Nerd Font" -Nfontsize=20 \ -T png | kitty +kitten icat # Output executable. TARGET := badc BIN := $(BUILD_DIR)/$(TARGET) # Compiler and linker configuration. CC := cc CFLAGS := -Wall -Wextra -pedantic -std=c11 -DBIN_NAME=\"$(TARGET)\" CFLAGS += $(INC_FLAGS) LDFLAGS := LDLIBS := RELEASE_CFLAGS := -DNDEBUG -O2 DEBUG_CFLAGS := -DDEBUG -g -fsanitize=address,undefined .PHONY: build tests clean # Setup debug/release builds. # make clean && make DEBUG=0 # make clean && make DEBUG=1 DEBUG ?= 0 ifeq ($(DEBUG), 1) CFLAGS += $(DEBUG_CFLAGS) else CFLAGS += $(RELEASE_CFLAGS) endif main: $(BIN) $(BIN): $(SRC_MAIN) $(WATCH_SRC) | $(BUILD_DIR) $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(SRC_MAIN) $(LDLIBS) # Create build directory if needed. $(BUILD_DIR): mkdir -p $(BUILD_DIR) run: $(BIN) $(BIN) $(SRC_RUN) graph-tokens: $(BIN) $(BIN) -pl $(SRC_RUN) graph-parse: $(BIN) @echo "parsing tree for: '$(SRC_RUN)'" @$(BIN) -pp $(SRC_RUN) | $(DOT) graph-semantic: $(BIN) @echo "semantic tree for: '$(SRC_RUN)'" @$(BIN) -ps $(SRC_RUN) | $(DOT) graph-symbols: $(BIN) @echo "symbol table for: '$(SRC_RUN)'" @$(BIN) -pt $(SRC_RUN) | $(DOT) tests: $(BIN) @for name in $(TEST_FILES); do\ line=" OK";\ printf "$${name}\r" ;\ $(BIN) $${name} \ && printf "$$line\r" \ && printf "$${name}\n";\ done # Remove build directory. clean: rm -rf $(BUILD_DIR)