From 34557c92c3dc1a3628f3650a5b942edc9db9403f Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Wed, 16 Mar 2022 18:23:11 +0000 Subject: [PATCH] Setup the Makefile to allow me to produce a release build and to create some directories if they're not there already. --- Makefile | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 0064e4a..16fc303 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,32 @@ CC = gcc -CFLAGS=-Wall +CFLAGS=-Wall -DDEBUG SRC=src OBJ=obj SRCS=$(wildcard $(SRC)/*.c) +# Substitute all .c with .o from SRCS OBJS=$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS)) BINDIR=bin BIN=$(BINDIR)/clox -all:$(BIN) +all: $(BIN) -$(BIN): $(OBJS) +release: CFLAGS=-Wall -O2 +release: clean +release: $(BIN) + +$(BIN): $(OBJS) $(BINDIR) $(CC) $(CFLAGS) $(OBJS) -o $@ -$(OBJ)/%.o: $(SRC)/%.c +$(OBJ)/%.o: $(SRC)/%.c $(OBJ) $(CC) $(CFLAGS) -c $< -o $@ +$(BINDIR): + mkdir $@ + +$(OBJ): + mkdir $@ + .PHONY: clean .PHONY: test