55 lines
1 KiB
Makefile
55 lines
1 KiB
Makefile
|
CC := clang
|
||
|
YACC := bison
|
||
|
LEX := flex
|
||
|
CFLAGS := -std=c17 -Wpedantic -Wall -Wextra
|
||
|
BISONFLAGS :=
|
||
|
BUILD := ./build
|
||
|
INCLUDE := -I./
|
||
|
OBJ_DIR := $(BUILD)/objects
|
||
|
APP_DIR := $(BUILD)/bin
|
||
|
|
||
|
SRC := $(wildcard ./*.c) lexer.c parser.c
|
||
|
OBJECTS := $(SRC:%.c=$(OBJ_DIR)/%.o)
|
||
|
|
||
|
# targets
|
||
|
all: build $(APP_DIR)/$(TARGET)
|
||
|
|
||
|
run: all
|
||
|
$(APP_DIR)/$(TARGET)
|
||
|
|
||
|
flex:
|
||
|
$(LEX) --outfile=lexer.c --header-file=lexer.h lexer.l
|
||
|
|
||
|
bison:
|
||
|
$(YACC) $(BISONFLAGS) --output=parser.c parser.y
|
||
|
|
||
|
generate: flex bison
|
||
|
|
||
|
$(OBJ_DIR)/%.o: %.c
|
||
|
@mkdir -p $(@D)
|
||
|
$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
|
||
|
|
||
|
$(APP_DIR)/$(TARGET): flex bison $(OBJECTS)
|
||
|
@mkdir -p $(@D)
|
||
|
$(CC) $(CFLAGS) $(INCLUDE) $(LDFLAGS) -o $(APP_DIR)/$(TARGET) $(OBJECTS)
|
||
|
|
||
|
.PHONY: all build clean debug release
|
||
|
|
||
|
build:
|
||
|
@mkdir -p $(APP_DIR)
|
||
|
@mkdir -p $(OBJ_DIR)
|
||
|
|
||
|
debug: CFLAGS += -DDEBUG -g
|
||
|
debug: BISONFLAGS += -Wcounterexamples
|
||
|
debug: all
|
||
|
|
||
|
sanitize: CFLAGS += -DDEBUG -g -fsanitize=address
|
||
|
sanitize: all
|
||
|
|
||
|
release: CFLAGS += -O2
|
||
|
release: all
|
||
|
|
||
|
clean:
|
||
|
-@rm -rvf $(BUILD)
|
||
|
-@rm -rvf {lexer.c,parser.c} {lexer.h,parser.h}
|