Makefile improvements.

This commit is contained in:
LoRd_MuldeR 2020-10-14 19:59:12 +02:00
parent 985dcfd6ee
commit 53dcefacbb
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
2 changed files with 69 additions and 11 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
*.o
*.user *.user
/.vs /.vs
/bin /bin
/lib
/obj /obj

View File

@ -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) ifeq ($(OS),Windows_NT)
SUFFIX := exe CFLAGS += -municode -mconsole
CFLAGS += -municode
else
SUFFIX := out
endif 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 .PHONY: all clean
all: all: $(TARGET_APP)
@mkdir -p bin
$(CC) $(CFLAGS) -o bin/mcrypt.$(SUFFIX) $(wildcard frontend/src/*.c) $(wildcard libMCrypt/src/*.c)
strip bin/mcrypt.$(SUFFIX)
$(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: clean:
@mkdir -p bin $(RM) $(addsuffix *crypt*,$(dir $(TARGET_APP)) $(dir $(TARGET_LIB)))
rm -f bin/*.$(SUFFIX) $(RM) $(addsuffix *.o,$(dir $(OBJECTS_APP)) $(dir $(OBJECTS_LIB)))