make for static linkage

This commit is contained in:
mrbesen 2021-03-04 10:18:18 +01:00
parent 432b3de3eb
commit e6dcb27ecb
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 12 additions and 6 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ build/
*.so
*.d
*.a
deps/

View File

@ -6,10 +6,11 @@
# statdessen: `make clean; make all -j` verwenden
# windows name
NAME = lib$(NAMESHORT).dll
#NAME = lib$(NAMESHORT).dll
NAMESHORT = mrbesen
NAME ?= lib$(NAMESHORT).so
NAMESTATIC = lib$(NAMESHORT).a
NAMETEST = test
CFLAGS = -fpic -std=c++17 -O2 -g -pipe -Wall -Wextra -Wno-unused-parameter -Wpedantic
CXX = g++
@ -32,7 +33,11 @@ BUILDDIRS = $(patsubst $(SRCF)%, $(BUILDDIR)%, $(SOURCEDIRS))
INCLUDES += $(addprefix -I, $(SOURCEDIRS))
all: $(OUTF)$(NAME) runtest
all: $(OUTF)$(NAME) $(OUTF)$(NAMESTATIC) runtest
$(OUTF)$(NAMESTATIC): $(BUILDDIRS) $(DEPF) $(OBJFILES)
@echo "Archiving $@"
@$(AR) rs $@ $(filter %.o, $^)
$(OUTF)$(NAME): $(BUILDDIRS) $(DEPF) $(OBJFILES)
@echo "Linking $@"
@ -50,15 +55,15 @@ clean-depends:
$(RM) -r $(DEPF)
clean:
$(RM) -r $(OUTF)$(NAME) $(BUILDDIR) $(NAMETEST)
$(RM) -r $(OUTF)$(NAME) $(BUILDDIR) $(NAMETEST) $(NAMESTATIC)
$(NAMETEST): $(NAME) $(TESTF)*.cpp
$(NAMETEST): $(TESTF)*.cpp $(NAMESTATIC)
@echo "Compiling tests"
@$(CXX) -o $@ $(filter-out %.so, $^) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(OUTF) -l$(NAMESHORT)
@$(CXX) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS)
runtest: $(NAMETEST)
@echo "Running tests"
LD_LIBRARY_PATH=$(OUTF):$(LD_LIBRARY_PATH) ./$<
./$<
install: $(NAME)
cp -f ./$(NAME) /usr/lib/