From 53dcefacbb6ebc69a936dcf1457a1e0ab695b69b Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Wed, 14 Oct 2020 19:59:12 +0200 Subject: [PATCH] Makefile improvements. --- .gitignore | 2 ++ Makefile | 78 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index b89ed54..8631494 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ +*.o *.user /.vs /bin +/lib /obj diff --git a/Makefile b/Makefile index c48b33b..244b58a 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,75 @@ -CFLAGS = -O3 -static -DNDEBUG -IlibMCrypt/include +# --------------------------------------------------------------------------- +# Options +# --------------------------------------------------------------------------- + +DEBUG ?= 0 +MARCH ?= native +MTUNE ?= native + +# --------------------------------------------------------------------------- +# FLags +# --------------------------------------------------------------------------- + +CFLAGS = -IlibMCrypt/include -march=$(MARCH) -mtune=$(MTUNE) + +ifeq ($(DEBUG),1) + CFLAGS += -Og -g + undefine LDFLGS +else + CFLAGS += -O3 -static -DNDEBUG + LDFLGS += -static -s +endif ifeq ($(OS),Windows_NT) - SUFFIX := exe - CFLAGS += -municode -else - SUFFIX := out + CFLAGS += -municode -mconsole endif +# --------------------------------------------------------------------------- +# File names +# --------------------------------------------------------------------------- + +undefine SUFFIX +ifeq ($(OS),Windows_NT) + SUFFIX := .exe +else + undefine SUFFIX +endif + +ifeq ($(DEBUG),1) + NAMEX := _g +else + undefine NAMEX +endif + +TARGET_APP := bin/mcrypt$(NAMEX)$(SUFFIX) +TARGET_LIB := lib/libmcrypt$(NAMEX)-1.a + +SOURCES_APP := $(wildcard frontend/src/*.c) +OBJECTS_APP := $(patsubst %.c,%$(NAMEX).o,$(SOURCES_APP)) + +SOURCES_LIB := $(wildcard libMCrypt/src/*.c) +OBJECTS_LIB := $(patsubst %.c,%$(NAMEX).o,$(SOURCES_LIB)) + +# --------------------------------------------------------------------------- +# Targets +# --------------------------------------------------------------------------- + .PHONY: all clean -all: - @mkdir -p bin - $(CC) $(CFLAGS) -o bin/mcrypt.$(SUFFIX) $(wildcard frontend/src/*.c) $(wildcard libMCrypt/src/*.c) - strip bin/mcrypt.$(SUFFIX) +all: $(TARGET_APP) +$(TARGET_APP): $(OBJECTS_APP) $(TARGET_LIB) + @mkdir -p $(@D) + $(CC) $(CFLAGS) $^ -o $@ $(LDFLGS) + +$(TARGET_LIB): $(OBJECTS_LIB) + @mkdir -p $(@D) + $(AR) rcs $@ $^ + +%$(NAMEX).o: %.c + @mkdir -p $(@D) + $(CC) $(CFLAGS) -c $< -o $@ + clean: - @mkdir -p bin - rm -f bin/*.$(SUFFIX) + $(RM) $(addsuffix *crypt*,$(dir $(TARGET_APP)) $(dir $(TARGET_LIB))) + $(RM) $(addsuffix *.o,$(dir $(OBJECTS_APP)) $(dir $(OBJECTS_LIB)))