From cf23a620089155caf2a1c7227c6c52f9f8a74a3c Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 22 Oct 2023 18:06:41 +0100 Subject: Made a debug and release configuration via flags Also split out the check for whether $(DIST) exists by making it its own recipe. Removes the repeated checks in each object compilation. --- Makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a0106b3..6ac5145 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ CC=gcc -CFLAGS=-Wall -Wextra -Werror -Wswitch-enum -ggdb -fsanitize=address -std=c11 +GENERAL-FLAGS=-Wall -Wextra -Werror -Wswitch-enum -std=c11 +DEBUG-FLAGS=-ggdb -fsanitize=address +RELEASE-FLAGS=-O3 +CFLAGS=$(GENERAL-FLAGS) $(DEBUG-FLAGS) LIBS= ARGS= OUT=ovm.out @@ -12,18 +15,19 @@ OBJECTS=$(CODE:$(SRC)/%.c=$(DIST)/%.o) DEPS=$(OBJECTS:%.o=%.d) .PHONY: all -all: $(OUT) +all: $(OUT) $(DIST) + +$(DIST): + mkdir -p $(DIST) $(OUT): $(DIST)/$(OUT) -$(DIST)/$(OUT): $(OBJECTS) - mkdir -p $(DIST) - $(CC) $(CFLAGS) $^ -o $@ $(LIBS) +$(DIST)/$(OUT): $(DIST) $(OBJECTS) + $(CC) $(CFLAGS) $(OBJECTS) -o $@ $(LIBS) -include $(DEPS) $(DIST)/%.o: $(SRC)/%.c - mkdir -p $(DIST) $(CC) $(CFLAGS) -MMD -c $< -o $@ $(LIBS) .PHONY: run -- cgit v1.2.3-13-gbd6f