From 540eb4323904a52ad3bd26e970a3674568a79fbb Mon Sep 17 00:00:00 2001 From: Felix Suchert Date: Wed, 28 Dec 2022 17:55:36 +0100 Subject: [PATCH] shrink makefile bloat --- Makefile.common.mk | 54 +++++++++++++++++++++++++++++++++++++++++++++ day_1/Makefile | 53 +------------------------------------------- day_2-1/Makefile | 55 ++-------------------------------------------- day_2-2/Makefile | 55 ++-------------------------------------------- day_4/Makefile | 53 +------------------------------------------- day_5/Makefile | 55 +--------------------------------------------- day_6/Makefile | 55 +--------------------------------------------- 7 files changed, 62 insertions(+), 318 deletions(-) create mode 100644 Makefile.common.mk diff --git a/Makefile.common.mk b/Makefile.common.mk new file mode 100644 index 0000000..dc0b5f5 --- /dev/null +++ b/Makefile.common.mk @@ -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} diff --git a/day_1/Makefile b/day_1/Makefile index 545eddb..81b97d3 100644 --- a/day_1/Makefile +++ b/day_1/Makefile @@ -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 -SRC := $(wildcard ./*.cpp) 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) --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} +include ../Makefile.common.mk diff --git a/day_2-1/Makefile b/day_2-1/Makefile index 922249d..8c8bccd 100644 --- a/day_2-1/Makefile +++ b/day_2-1/Makefile @@ -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_2 +TARGET := day_2_1 -SRC := $(wildcard ./*.cpp) 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) --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} +include ../Makefile.common.mk diff --git a/day_2-2/Makefile b/day_2-2/Makefile index 922249d..60fd973 100644 --- a/day_2-2/Makefile +++ b/day_2-2/Makefile @@ -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_2 +TARGET := day_2_2 -SRC := $(wildcard ./*.cpp) 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) --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} +include ../Makefile.common.mk diff --git a/day_4/Makefile b/day_4/Makefile index 234a1ab..f7434ab 100644 --- a/day_4/Makefile +++ b/day_4/Makefile @@ -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 -SRC := $(wildcard ./*.cpp) 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) --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} +include ../Makefile.common.mk diff --git a/day_5/Makefile b/day_5/Makefile index aef3d04..f074f1d 100644 --- a/day_5/Makefile +++ b/day_5/Makefile @@ -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 -SRC := $(wildcard ./*.cpp) 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} +include ../Makefile.common.mk diff --git a/day_6/Makefile b/day_6/Makefile index 81b7c3f..10542e6 100644 --- a/day_6/Makefile +++ b/day_6/Makefile @@ -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 -SRC := $(wildcard ./*.cpp) 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} +include ../Makefile.common.mk