Refactored the Makefiles.

This commit is contained in:
LoRd_MuldeR 2022-11-30 16:15:12 +01:00
parent 3f197143f6
commit b49e1497bf
5 changed files with 48 additions and 113 deletions

31
config.mk Normal file
View File

@ -0,0 +1,31 @@
DUMPMACHINE := $(shell $(CC) -dumpmachine)
ifeq ($(DUMPMACHINE),)
$(error The C compiler could not be detected!)
endif
ifneq ($(DEBUG),)
XCFLAGS = -Og -g
else
ifneq ($(ASAN),)
XCFLAGS = -O1 -g -fsanitize=address -fno-omit-frame-pointer
XLDFLAGS += -static-libasan
else
XCFLAGS = -Ofast -DNDEBUG
ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),)
XCFLAGS += -march=x86-64 -mtune=nocona
else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XCFLAGS += -march=pentiumpro -mtune=intel
endif
ifneq ($(FLTO),)
XCFLAGS += -flto
endif
XLDFLAGS += -s -static
endif
endif
ifneq ($(firstword $(filter %-mingw32 %-cygwin,$(DUMPMACHINE))),)
EXE_SUFFIX := .exe
ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XLDFLAGS += -Wl,--large-address-aware
endif
endif

View File

@ -1,32 +1,7 @@
DUMPMACHINE := $(shell $(CC) -dumpmachine) include ../../config.mk
ifneq ($(DEBUG),)
XCFLAGS = -Og -g
else
ifneq ($(ASAN),)
XCFLAGS = -O1 -g -fsanitize=address -fno-omit-frame-pointer -static-libasan
else
XCFLAGS = -Ofast -DNDEBUG
ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),)
XCFLAGS += -march=x86-64 -mtune=nocona
else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XCFLAGS += -march=pentiumpro -mtune=intel
endif
ifneq ($(FLTO),)
XCFLAGS += -flto
endif
XCFLAGS += -s -static
endif
endif
ifneq ($(firstword $(filter %-mingw32 %-cygwin,$(DUMPMACHINE))),)
EXE_SUFFIX := .exe
ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XCFLAGS += -Wl,--large-address-aware
endif
endif
CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include $(XCFLAGS) CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include $(XCFLAGS)
LDFLAGS = -L../../libhashset/lib -lhashset-1 $(XLDFLAGS)
SRC_PATH := src SRC_PATH := src
BIN_PATH := bin BIN_PATH := bin
@ -34,7 +9,6 @@ ALL_PATH := $(SRC_PATH) $(BIN_PATH)
BIN_FILE := $(BIN_PATH)/example-hash-map$(EXE_SUFFIX) BIN_FILE := $(BIN_PATH)/example-hash-map$(EXE_SUFFIX)
SRC_FILE := $(wildcard $(SRC_PATH)/*.c) SRC_FILE := $(wildcard $(SRC_PATH)/*.c)
LIB_FILE := ../../libhashset/lib/libhashset-1.a
.PHONY: all build clean .PHONY: all build clean
@ -42,11 +16,11 @@ all: clean build
build: $(ALL_PATH) $(BIN_FILE) build: $(ALL_PATH) $(BIN_FILE)
$(BIN_FILE): $(SRC_FILE) $(LIB_FILE) $(BIN_FILE): $(SRC_FILE)
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(ALL_PATH): $(ALL_PATH):
mkdir -p $@ mkdir -p $@
clean: clean:
rm -f $(BIN_FILE) rm -vf $(BIN_FILE)

View File

@ -1,32 +1,7 @@
DUMPMACHINE := $(shell $(CC) -dumpmachine) include ../../config.mk
ifneq ($(DEBUG),)
XCFLAGS = -Og -g
else
ifneq ($(ASAN),)
XCFLAGS = -O1 -g -fsanitize=address -fno-omit-frame-pointer -static-libasan
else
XCFLAGS = -Ofast -DNDEBUG
ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),)
XCFLAGS += -march=x86-64 -mtune=nocona
else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XCFLAGS += -march=pentiumpro -mtune=intel
endif
ifneq ($(FLTO),)
XCFLAGS += -flto
endif
XCFLAGS += -s -static
endif
endif
ifneq ($(firstword $(filter %-mingw32 %-cygwin,$(DUMPMACHINE))),)
EXE_SUFFIX := .exe
ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XCFLAGS += -Wl,--large-address-aware
endif
endif
CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include $(XCFLAGS) CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include $(XCFLAGS)
LDFLAGS = -L../../libhashset/lib -lhashset-1 $(XLDFLAGS)
SRC_PATH := src SRC_PATH := src
BIN_PATH := bin BIN_PATH := bin
@ -34,7 +9,6 @@ ALL_PATH := $(SRC_PATH) $(BIN_PATH)
BIN_FILE := $(BIN_PATH)/example-hash-set$(EXE_SUFFIX) BIN_FILE := $(BIN_PATH)/example-hash-set$(EXE_SUFFIX)
SRC_FILE := $(wildcard $(SRC_PATH)/*.c) SRC_FILE := $(wildcard $(SRC_PATH)/*.c)
LIB_FILE := ../../libhashset/lib/libhashset-1.a
.PHONY: all build clean .PHONY: all build clean
@ -42,11 +16,11 @@ all: clean build
build: $(ALL_PATH) $(BIN_FILE) build: $(ALL_PATH) $(BIN_FILE)
$(BIN_FILE): $(SRC_FILE) $(LIB_FILE) $(BIN_FILE): $(SRC_FILE)
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(ALL_PATH): $(ALL_PATH):
mkdir -p $@ mkdir -p $@
clean: clean:
rm -f $(BIN_FILE) rm -vf $(BIN_FILE)

View File

@ -1,22 +1,4 @@
DUMPMACHINE := $(shell $(CC) -dumpmachine) include ../config.mk
ifneq ($(DEBUG),)
XCFLAGS = -Og -g
else
ifneq ($(ASAN),)
XCFLAGS = -O1 -g -fsanitize=address -fno-omit-frame-pointer -static-libasan
else
XCFLAGS = -Ofast -DNDEBUG
ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),)
XCFLAGS += -march=x86-64 -mtune=nocona
else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XCFLAGS += -march=pentiumpro -mtune=intel
endif
ifneq ($(FLTO),)
XCFLAGS += -flto
endif
endif
endif
CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -Iinclude $(XCFLAGS) CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -Iinclude $(XCFLAGS)

View File

@ -1,40 +1,14 @@
DUMPMACHINE := $(shell $(CC) -dumpmachine) include ../../config.mk
ifneq ($(DEBUG),)
XCFLAGS = -Og -g
else
ifneq ($(ASAN),)
XCFLAGS = -O1 -g -fsanitize=address -fno-omit-frame-pointer -static-libasan
else
XCFLAGS = -Ofast -DNDEBUG
ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),)
XCFLAGS += -march=x86-64 -mtune=nocona
else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XCFLAGS += -march=pentiumpro -mtune=intel
endif
ifneq ($(FLTO),)
XCFLAGS += -flto
endif
XCFLAGS += -s -static
endif
endif
ifneq ($(firstword $(filter %-mingw32 %-cygwin,$(DUMPMACHINE))),)
EXE_SUFFIX := .exe
ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),)
XCFLAGS += -Wl,--large-address-aware
endif
endif
CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include $(XCFLAGS) CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -I../../libhashset/include $(XCFLAGS)
LDFLAGS = -L../../libhashset/lib -lhashset-1 $(XLDFLAGS)
SRC_PATH := src SRC_PATH := src
BIN_PATH := bin BIN_PATH := bin
ALL_PATH := $(SRC_PATH) $(BIN_PATH) ALL_PATH := $(SRC_PATH) $(BIN_PATH)
BIN_FILE := $(BIN_PATH)/hashset-test$(EXE_SUFFIX) BIN_FILE := $(BIN_PATH)/test-hash-set$(EXE_SUFFIX)
SRC_FILE := $(wildcard $(SRC_PATH)/*.c) SRC_FILE := $(wildcard $(SRC_PATH)/*.c)
LIB_FILE := ../../libhashset/lib/libhashset-1.a
.PHONY: all build clean .PHONY: all build clean
@ -42,11 +16,11 @@ all: clean build
build: $(ALL_PATH) $(BIN_FILE) build: $(ALL_PATH) $(BIN_FILE)
$(BIN_FILE): $(SRC_FILE) $(LIB_FILE) $(BIN_FILE): $(SRC_FILE)
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(ALL_PATH): $(ALL_PATH):
mkdir -p $@ mkdir -p $@
clean: clean:
rm -f $(BIN_FILE) rm -vf $(BIN_FILE)