SlunkCrypt/Makefile

90 lines
2.3 KiB
Makefile

# ---------------------------------------------------------------------------
# Options
# ---------------------------------------------------------------------------
DEBUG ?= 0
MARCH ?= native
MTUNE ?= native
# ---------------------------------------------------------------------------
# Directories
# ---------------------------------------------------------------------------
SUBDIR_APP := frontend
SUBDIR_LIB := libslunkcrypt
# ---------------------------------------------------------------------------
# Flags
# ---------------------------------------------------------------------------
CFLAGS = -I$(SUBDIR_LIB)/include -Wall -Wno-trigraphs -march=$(MARCH) -mtune=$(MTUNE)
ifeq ($(DEBUG),1)
CFLAGS += -Og -g
undefine LDFLGS
else
CFLAGS += -O3 -DNDEBUG
LDFLGS += -static -s
endif
ifeq ($(OS),Windows_NT)
LDFLGS += -municode -mconsole
endif
undefine SUFFIX
ifeq ($(OS),Windows_NT)
SUFFIX := .exe
else
undefine SUFFIX
endif
ifeq ($(DEBUG),1)
CONFIG := _g
else
undefine CONFIG
endif
# ---------------------------------------------------------------------------
# File names
# ---------------------------------------------------------------------------
OUTNAME_APP := slunkcrypt$(CONFIG)$(SUFFIX)
OUTNAME_LIB := libslunkcrypt$(CONFIG)-1.a
OUTPATH_APP := $(SUBDIR_APP)/bin/$(OUTNAME_APP)
OUTPATH_LIB := $(SUBDIR_LIB)/lib/$(OUTNAME_LIB)
SOURCES_APP := $(wildcard $(SUBDIR_APP)/src/*.c)
OBJECTS_APP := $(patsubst $(SUBDIR_APP)/src/%.c,$(SUBDIR_APP)/obj/%$(CONFIG).o,$(SOURCES_APP))
SOURCES_LIB := $(wildcard $(SUBDIR_LIB)/src/*.c)
OBJECTS_LIB := $(patsubst $(SUBDIR_LIB)/src/%.c,$(SUBDIR_LIB)/obj/%$(CONFIG).o,$(SOURCES_LIB))
# ---------------------------------------------------------------------------
# Targets
# ---------------------------------------------------------------------------
.PHONY: all clean
all: $(OUTPATH_APP)
$(OUTPATH_APP): $(OBJECTS_APP) $(OUTPATH_LIB)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLGS)
$(OUTPATH_LIB): $(OBJECTS_LIB)
@mkdir -p $(@D)
$(AR) rcs $@ $^
$(SUBDIR_APP)/obj/%$(CONFIG).o: $(SUBDIR_APP)/src/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
$(SUBDIR_LIB)/obj/%$(CONFIG).o: $(SUBDIR_LIB)/src/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
clean:
$(RM) $(addsuffix *crypt*,$(dir $(TARGET_APP)) $(dir $(TARGET_LIB)))
$(RM) $(addsuffix *.o,$(dir $(OBJECTS_APP)) $(dir $(OBJECTS_LIB)))