From 2b87172744ea7a57a939d7c42be73a841fc237b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9cate?= Date: Mon, 11 May 2020 14:15:20 +0200 Subject: [PATCH] Makefile rework This commit simplifies and fixes several quirks of the Makefile: * LDLIBS is now used instead of LDFLAGS * Only one step is now necessary to compile the binary * clean is now marked as a PHONY rule --- Makefile | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 77e47dc..0d55236 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,11 @@ # Apprentice binary CC = gcc -CFLAGS = -std=c99 -g -Wall -Wextra -Werror -LDFLAGS = -lm -lmagic -HEADER_FILES = src -C_SOURCE_FILES = src/apprentice.c -OBJECT_FILES = $(C_SOURCE_FILES:.c=.o) -EXECUTABLE_DIRECTORY = priv -EXECUTABLE = $(EXECUTABLE_DIRECTORY)/apprentice +CFLAGS = -std=c99 -g -Wall -Werror +LDLIBS = -lm -lmagic +BEAM_FILES = _build/ +PRIV = priv/ +RM = rm -Rf # Unit test custom magic file @@ -16,20 +14,9 @@ TEST_DIRECTORY = test TARGET_MAGIC = $(TEST_DIRECTORY)/elixir.mgc SOURCE_MAGIC = $(TEST_DIRECTORY)/elixir -# Target - -all: $(EXECUTABLE) $(TARGET_MAGIC) - -# Compile - -$(EXECUTABLE): $(OBJECT_FILES) $(EXECUTABLE_DIRECTORY) - $(CC) $(OBJECT_FILES) -o $@ $(LDFLAGS) - -$(EXECUTABLE_DIRECTORY): - mkdir -p $(EXECUTABLE_DIRECTORY) - -.o: - $(CC) $(CFLAGS) $< -o $@ +priv/apprentice: src/apprentice.c + mkdir -p priv + $(CC) $(CFLAGS) $(LDLIBS) $^ -o $@ # Test case @@ -37,4 +24,6 @@ $(TARGET_MAGIC): $(SOURCE_MAGIC) cd $(TEST_DIRECTORY); $(MAGIC) -C -m elixir clean: - rm -f $(EXECUTABLE) $(OBJECT_FILES) $(BEAM_FILES) + $(RM) $(PRIV) $(BEAM_FILES) + +.PHONY: clean