gol

Implementation of Conway's Game of Life writen in C
git clone git://git.dimitrijedobrota.com/gol.git
Log | Files | Refs | README

commit 55b90dc05da91c34fa20e558765be5afa9136ad3
parent 3db973191cc6ad64c2ddc07c303477c0c419c5f6
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri,  3 Jun 2022 03:35:39 +0200

Improved Makefile

- Properly implemented DEBUG and NO_UNICODE flags
- Help command
- Improved readability
- Improved portability

Diffstat:
MMakefile | 64+++++++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 45 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,24 +1,40 @@ -CC=gcc -CFLAGS = -I include +# GNU Makefile for Game of Life simulation +# +# Usage: make [-f path\Makefile] [DEBUG=Y] [NO_UNICODE=Y] target -ifeq ($(OS),Windows_NT) -LDFLAGS = -lpdcurses -else -LDFLAGS = -lncurses -endif +NAME = gol +CC = gcc + +CFLAGS = -I include SRC = src OBJ = obj BINDIR = bin -BIN = bin/gol +BIN = bin/$(NAME) SRCS=$(wildcard $(SRC)/*.c) OBJS=$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS)) +ifeq ($(OS),Windows_NT) + LDFLAGS = -lpdcurses + RM = del + NAME := $(NAME).exe + DEL_CLEAN = $(subst /,\,$(BIN)) $(subst /,\,$(OBJS)) +else + LDFLAGS = -lncurses + RM = rm -f + DEL_CLEAN = $(BIN) $(OBJS) +endif + +ifeq ($(DEBUG),Y) + CFLAGS += -ggdb -Wall +endif + +ifeq ($(NO_UNICODE),Y) + CFLAGS += -D NO_UNICODE +endif + all: $(BIN) -debug: CFLAGS +=-ggdb -Wall -NO_UNICODE: CFLAGS += -D NO_UNICODE -NO_UNICODE debug: ${BIN} $(BIN): $(OBJS) $(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@ @@ -26,12 +42,22 @@ $(BIN): $(OBJS) $(OBJ)/%.o: $(SRC)/%.c $(CC) -c $< -o $@ $(CFLAGS) $(LDFLAGS) -ifeq ($(OS),Windows_NT) clean: - del bin\gol.exe $(subst /,\,$(OBJS)) -else -clean: - rm -f $(BIN) $(OBJS) -endif - -.PHONY: all clean debug NO_UNICODE + -$(RM) $(DEL_CLEAN) + +help: + @echo "Game of Life Simulation" + @echo + @echo "Usage: make [-f path\Makefile] [DEBUG=Y] [NO_UNICODE=Y] target" + @echo + @echo "Target rules:" + @echo " all - Compiles binary file [Default]" + @echo " clean - Clean the project by removing binaries" + @echo " help - Prints a help message with target rules" + @echo + @echo "Optional parameters:" + @echo " DEBUG - Compile binary file with debug flags enabled" + @echo " NO_UNICODE - Compile binary file that does not use Unicode characters" + @echo + +.PHONY: all clean help