mirror of
https://github.com/Cameron-Reed1/Cpp-Argument-Parser.git
synced 2025-01-11 00:06:47 +00:00
Added option to toggle between shared and static library
This commit is contained in:
parent
53e81db0ea
commit
1382930021
46
Makefile
46
Makefile
@ -1,3 +1,7 @@
|
|||||||
|
TYPE = STATIC
|
||||||
|
SHARED_TYPE = SHARED
|
||||||
|
STATIC_TYPE = STATIC
|
||||||
|
|
||||||
BUILD_DIR = bin
|
BUILD_DIR = bin
|
||||||
SOURCE_DIR = Src
|
SOURCE_DIR = Src
|
||||||
HEADER_DIR = Inc
|
HEADER_DIR = Inc
|
||||||
@ -5,7 +9,11 @@ HEADER_INSTALL_DIR = /usr/local/include
|
|||||||
INSTALL_DIR = /usr/local/lib
|
INSTALL_DIR = /usr/local/lib
|
||||||
|
|
||||||
LIB_NAME = argParser
|
LIB_NAME = argParser
|
||||||
|
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||||
|
LIB_FILE_NAME = lib$(LIB_NAME).so
|
||||||
|
else
|
||||||
LIB_FILE_NAME = lib$(LIB_NAME).a
|
LIB_FILE_NAME = lib$(LIB_NAME).a
|
||||||
|
endif
|
||||||
|
|
||||||
OPT = -O2
|
OPT = -O2
|
||||||
|
|
||||||
@ -24,16 +32,44 @@ OBJECTS += $(addprefix $(BUILD_DIR)/, $(notdir $(CXX_SOURCES:.cpp=.o)))
|
|||||||
CFLAGS = $(OPT) $(INCS) -Wall
|
CFLAGS = $(OPT) $(INCS) -Wall
|
||||||
CXXFLAGS = -std=c++17 $(OPT) $(INCS) -Wall
|
CXXFLAGS = -std=c++17 $(OPT) $(INCS) -Wall
|
||||||
|
|
||||||
|
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||||
|
CFLAGS += -fpic
|
||||||
|
CXXFLAGS += -fpic
|
||||||
|
|
||||||
|
TESTFLAGS = -Wl,-rpath=$(PWD)/$(BUILD_DIR)
|
||||||
|
endif
|
||||||
|
|
||||||
HEADERS = $(wildcard $(HEADER_DIR)/*.h)
|
HEADERS = $(wildcard $(HEADER_DIR)/*.h)
|
||||||
|
|
||||||
CP = cp
|
CP = cp
|
||||||
MKDIR = mkdir -p
|
MKDIR = mkdir -p
|
||||||
ARFLAGS = rvc
|
ARFLAGS = rvc
|
||||||
|
SED = sed -i -e
|
||||||
|
CHMOD = chmod
|
||||||
|
LDCONFIG = ldconfig
|
||||||
|
|
||||||
all: $(BUILD_DIR)/$(LIB_FILE_NAME)
|
all: $(BUILD_DIR)/$(LIB_FILE_NAME)
|
||||||
|
|
||||||
|
ifneq ($(TYPE), $(SHARED_TYPE))
|
||||||
|
shared: clean
|
||||||
|
@$(SED) "s/^TYPE = .*$$/TYPE = $(SHARED_TYPE)/" Makefile
|
||||||
|
|
||||||
|
.PHONY: shared
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(TYPE), $(STATIC_TYPE))
|
||||||
|
static: clean
|
||||||
|
@$(SED) "s/^TYPE = .*$$/TYPE = $(STATIC_TYPE)/" Makefile
|
||||||
|
|
||||||
|
.PHONY: static
|
||||||
|
endif
|
||||||
|
|
||||||
$(BUILD_DIR)/$(LIB_FILE_NAME): $(OBJECTS)
|
$(BUILD_DIR)/$(LIB_FILE_NAME): $(OBJECTS)
|
||||||
|
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||||
|
$(CXX) $^ $(CXXFLAGS) -shared -o $@
|
||||||
|
else
|
||||||
$(AR) $(ARFLAGS) $@ $^
|
$(AR) $(ARFLAGS) $@ $^
|
||||||
|
endif
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | $(BUILD_DIR)
|
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | $(BUILD_DIR)
|
||||||
$(CC) -c $< $(CFLAGS) -o $@
|
$(CC) -c $< $(CFLAGS) -o $@
|
||||||
@ -45,7 +81,7 @@ $(BUILD_DIR):
|
|||||||
$(MKDIR) $@
|
$(MKDIR) $@
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
$(CXX) test.cpp $(CXXFLAGS) -l$(LIB_NAME) -L$(BUILD_DIR) -o $(BUILD_DIR)/test
|
$(CXX) test.cpp $(CXXFLAGS) -l$(LIB_NAME) -L$(BUILD_DIR) $(TESTFLAGS) -o $(BUILD_DIR)/test
|
||||||
-$(BUILD_DIR)/test
|
-$(BUILD_DIR)/test
|
||||||
|
|
||||||
test_installed:
|
test_installed:
|
||||||
@ -55,12 +91,20 @@ test_installed:
|
|||||||
install: all
|
install: all
|
||||||
$(CP) $(BUILD_DIR)/$(LIB_FILE_NAME) $(INSTALL_DIR)
|
$(CP) $(BUILD_DIR)/$(LIB_FILE_NAME) $(INSTALL_DIR)
|
||||||
$(CP) $(HEADERS) $(HEADER_INSTALL_DIR)
|
$(CP) $(HEADERS) $(HEADER_INSTALL_DIR)
|
||||||
|
@$(CHMOD) 0755 $(INSTALL_DIR)/$(LIB_FILE_NAME)
|
||||||
|
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||||
|
@$(LDCONFIG)
|
||||||
|
endif
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
$(RM) $(INSTALL_DIR)/$(LIB_FILE_NAME)
|
$(RM) $(INSTALL_DIR)/$(LIB_FILE_NAME)
|
||||||
$(RM) $(addprefix $(HEADER_INSTALL_DIR)/, $(notdir $(HEADERS)))
|
$(RM) $(addprefix $(HEADER_INSTALL_DIR)/, $(notdir $(HEADERS)))
|
||||||
|
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||||
|
@$(LDCONFIG)
|
||||||
|
endif
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) -r $(BUILD_DIR)
|
$(RM) -r $(BUILD_DIR)
|
||||||
|
|
||||||
.PHONY: all test install uninstall clean
|
.PHONY: all test install uninstall clean
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user