mirror of
https://github.com/Cameron-Reed1/Cpp-Argument-Parser.git
synced 2025-01-10 15:56: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
|
||||
SOURCE_DIR = Src
|
||||
HEADER_DIR = Inc
|
||||
@ -5,7 +9,11 @@ HEADER_INSTALL_DIR = /usr/local/include
|
||||
INSTALL_DIR = /usr/local/lib
|
||||
|
||||
LIB_NAME = argParser
|
||||
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||
LIB_FILE_NAME = lib$(LIB_NAME).so
|
||||
else
|
||||
LIB_FILE_NAME = lib$(LIB_NAME).a
|
||||
endif
|
||||
|
||||
OPT = -O2
|
||||
|
||||
@ -24,16 +32,44 @@ OBJECTS += $(addprefix $(BUILD_DIR)/, $(notdir $(CXX_SOURCES:.cpp=.o)))
|
||||
CFLAGS = $(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)
|
||||
|
||||
CP = cp
|
||||
MKDIR = mkdir -p
|
||||
ARFLAGS = rvc
|
||||
SED = sed -i -e
|
||||
CHMOD = chmod
|
||||
LDCONFIG = ldconfig
|
||||
|
||||
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)
|
||||
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||
$(CXX) $^ $(CXXFLAGS) -shared -o $@
|
||||
else
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
endif
|
||||
|
||||
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | $(BUILD_DIR)
|
||||
$(CC) -c $< $(CFLAGS) -o $@
|
||||
@ -45,7 +81,7 @@ $(BUILD_DIR):
|
||||
$(MKDIR) $@
|
||||
|
||||
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
|
||||
|
||||
test_installed:
|
||||
@ -55,12 +91,20 @@ test_installed:
|
||||
install: all
|
||||
$(CP) $(BUILD_DIR)/$(LIB_FILE_NAME) $(INSTALL_DIR)
|
||||
$(CP) $(HEADERS) $(HEADER_INSTALL_DIR)
|
||||
@$(CHMOD) 0755 $(INSTALL_DIR)/$(LIB_FILE_NAME)
|
||||
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||
@$(LDCONFIG)
|
||||
endif
|
||||
|
||||
uninstall:
|
||||
$(RM) $(INSTALL_DIR)/$(LIB_FILE_NAME)
|
||||
$(RM) $(addprefix $(HEADER_INSTALL_DIR)/, $(notdir $(HEADERS)))
|
||||
ifeq ($(TYPE), $(SHARED_TYPE))
|
||||
@$(LDCONFIG)
|
||||
endif
|
||||
|
||||
clean:
|
||||
$(RM) -r $(BUILD_DIR)
|
||||
|
||||
.PHONY: all test install uninstall clean
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user