Added separate Makefiles for the library and the "main" program.

This commit is contained in:
LoRd_MuldeR 2022-11-22 23:31:21 +01:00
parent caef45b177
commit 6739fcbf01
3 changed files with 72 additions and 29 deletions

View File

@ -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

36
hashset/Makefile Normal file
View File

@ -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)

32
libhashset/Makefile Normal file
View File

@ -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