From 6739fcbf017d29701d7dd7ad4b9cd901a13899e9 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Tue, 22 Nov 2022 23:31:21 +0100 Subject: [PATCH] Added separate Makefiles for the library and the "main" program. --- Makefile | 33 ++++----------------------------- hashset/Makefile | 36 ++++++++++++++++++++++++++++++++++++ libhashset/Makefile | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 hashset/Makefile create mode 100644 libhashset/Makefile diff --git a/Makefile b/Makefile index 5022c73..11f461d 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,9 @@ -DUMPMACHINE := $(shell $(CC) -dumpmachine) - -ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),) - XCFLAGS = -march=x86-64 -mtune=nocona -else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),) - XCFLAGS = -march=pentiumpro -mtune=intel -endif - -CFLAGS = -O3 -DNDEBUG -Ilibhashset/include $(XCFLAGS) - -BASE_DIR := libhashset - -SRC_PATH := $(BASE_DIR)/src -OBJ_PATH := $(BASE_DIR)/obj -LIB_PATH := $(BASE_DIR)/lib - -LIB_FILE := $(LIB_PATH)/libhashset-1.a -OBJ_FILE := $(OBJ_PATH)/hash_set.o +SUBDIRS := libhashset hashset .PHONY: all clean -all: $(LIB_FILE) - -$(LIB_FILE): $(OBJ_FILE) $(LIB_PATH) - $(AR) rcs $@ $< - -$(OBJ_FILE): $(SRC_PATH) $(OBJ_PATH) - $(CC) $(CFLAGS) -c $(SRC_PATH)/$(patsubst %.o,%.c,$(notdir $@)) -o $@ - -$(SRC_PATH) $(OBJ_PATH) $(LIB_PATH): - mkdir -p $@ +all: + for subdir in $(SUBDIRS); do $(MAKE) -C $$subdir; done clean: - rm -f $(LIB_FILE) $(OBJ_PATH)/*.o + for subdir in $(SUBDIRS); do $(MAKE) -C $$subdir clean; done diff --git a/hashset/Makefile b/hashset/Makefile new file mode 100644 index 0000000..206236d --- /dev/null +++ b/hashset/Makefile @@ -0,0 +1,36 @@ +DUMPMACHINE := $(shell $(CC) -dumpmachine) + +ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),) + XCFLAGS = -march=x86-64 -mtune=nocona -s +else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),) + XCFLAGS = -march=pentiumpro -mtune=intel -s +endif + +ifeq ($(OS),Windows_NT) +ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),) + XCFLAGS += -Wl,--large-address-aware +endif + EXE_SUFFIX := .exe +endif + +CFLAGS = -O3 -DNDEBUG -I../libhashset/include $(XCFLAGS) + +SRC_PATH := src +BIN_PATH := bin + +BIN_FILE := $(BIN_PATH)/hashset$(EXE_SUFFIX) +SRC_FILE := $(SRC_PATH)/main.c +LIB_FILE := ../libhashset/lib/libhashset-1.a + +.PHONY: all clean + +all: $(BIN_FILE) + +$(BIN_FILE): $(SRC_FILE) $(LIB_FILE) $(BIN_PATH) + $(CC) $(CFLAGS) $< -o $@ $(LIB_FILE) + +$(SRC_PATH) $(BIN_PATH): + mkdir -p $@ + +clean: + rm -f $(BIN_FILE) diff --git a/libhashset/Makefile b/libhashset/Makefile new file mode 100644 index 0000000..55f36d2 --- /dev/null +++ b/libhashset/Makefile @@ -0,0 +1,32 @@ +DUMPMACHINE := $(shell $(CC) -dumpmachine) + +ifneq ($(firstword $(filter x86_64-%,$(DUMPMACHINE))),) + XCFLAGS = -march=x86-64 -mtune=nocona +else ifneq ($(firstword $(filter i686-%,$(DUMPMACHINE))),) + XCFLAGS = -march=pentiumpro -mtune=intel +endif + +CFLAGS = -O3 -DNDEBUG -Iinclude $(XCFLAGS) + +SRC_PATH := src +OBJ_PATH := obj +LIB_PATH := lib + +LIB_FILE := $(LIB_PATH)/libhashset-1.a +OBJ_FILE := $(OBJ_PATH)/hash_set.o + +.PHONY: all clean + +all: $(LIB_FILE) + +$(LIB_FILE): $(OBJ_FILE) $(LIB_PATH) + $(AR) rcs $@ $< + +$(OBJ_FILE): $(SRC_PATH) $(OBJ_PATH) + $(CC) $(CFLAGS) -c $(SRC_PATH)/$(patsubst %.o,%.c,$(notdir $@)) -o $@ + +$(SRC_PATH) $(OBJ_PATH) $(LIB_PATH): + mkdir -p $@ + +clean: + rm -f $(LIB_FILE) $(OBJ_PATH)/*.o