shrink makefile bloat

This commit is contained in:
Felix Suchert 2022-12-28 17:55:36 +01:00
parent e24fecea52
commit 540eb43239
Signed by: feliix42
GPG key ID: 24363525EA0E8A99
7 changed files with 62 additions and 318 deletions

54
Makefile.common.mk Normal file
View file

@ -0,0 +1,54 @@
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}

View file

@ -1,54 +1,3 @@
CC := clang
YACC := bison
LEX := flex
CFLAGS := -std=c17 -Wpedantic -Wall -Wextra
BUILD := ./build
INCLUDE := -I./
OBJ_DIR := $(BUILD)/objects
APP_DIR := $(BUILD)/bin
TARGET := day_1 TARGET := day_1
SRC := $(wildcard ./*.cpp) lexer.c parser.c include ../Makefile.common.mk
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) --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: 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}

View file

@ -1,54 +1,3 @@
CC := clang TARGET := day_2_1
YACC := bison
LEX := flex
CFLAGS := -std=c17 -Wpedantic -Wall -Wextra
BUILD := ./build
INCLUDE := -I./
OBJ_DIR := $(BUILD)/objects
APP_DIR := $(BUILD)/bin
TARGET := day_2
SRC := $(wildcard ./*.cpp) lexer.c parser.c include ../Makefile.common.mk
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) --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: 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}

View file

@ -1,54 +1,3 @@
CC := clang TARGET := day_2_2
YACC := bison
LEX := flex
CFLAGS := -std=c17 -Wpedantic -Wall -Wextra
BUILD := ./build
INCLUDE := -I./
OBJ_DIR := $(BUILD)/objects
APP_DIR := $(BUILD)/bin
TARGET := day_2
SRC := $(wildcard ./*.cpp) lexer.c parser.c include ../Makefile.common.mk
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) --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: 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}

View file

@ -1,54 +1,3 @@
CC := clang
YACC := bison
LEX := flex
CFLAGS := -std=c17 -Wpedantic -Wall -Wextra
BUILD := ./build
INCLUDE := -I./
OBJ_DIR := $(BUILD)/objects
APP_DIR := $(BUILD)/bin
TARGET := day_4 TARGET := day_4
SRC := $(wildcard ./*.cpp) lexer.c parser.c include ../Makefile.common.mk
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) --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: 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}

View file

@ -1,56 +1,3 @@
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
TARGET := day_5 TARGET := day_5
SRC := $(wildcard ./*.cpp) lexer.c parser.c include ../Makefile.common.mk
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}

View file

@ -1,56 +1,3 @@
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
TARGET := day_6 TARGET := day_6
SRC := $(wildcard ./*.cpp) lexer.c parser.c include ../Makefile.common.mk
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}