2020-09-28 23:49:14 +02:00
|
|
|
# Author Yannis Gerlach
|
|
|
|
# Hochschule Osnabrück
|
|
|
|
# 28.09.2020
|
|
|
|
|
|
|
|
# `make clean all` nicht mit -j verwenden! -> race condition im make file
|
|
|
|
# statdessen: `make clean; make all -j` verwenden
|
|
|
|
|
2020-12-14 13:40:42 +01:00
|
|
|
# windows name
|
2021-03-04 10:18:18 +01:00
|
|
|
#NAME = lib$(NAMESHORT).dll
|
2020-12-14 13:40:42 +01:00
|
|
|
|
2020-10-02 16:01:57 +02:00
|
|
|
NAMESHORT = mrbesen
|
2020-12-14 13:40:42 +01:00
|
|
|
NAME ?= lib$(NAMESHORT).so
|
2021-03-04 10:18:18 +01:00
|
|
|
NAMESTATIC = lib$(NAMESHORT).a
|
2020-09-28 23:49:14 +02:00
|
|
|
NAMETEST = test
|
|
|
|
CFLAGS = -fpic -std=c++17 -O2 -g -pipe -Wall -Wextra -Wno-unused-parameter -Wpedantic
|
|
|
|
CXX = g++
|
|
|
|
SRCF = src/
|
|
|
|
BUILDDIR = build/
|
|
|
|
INCF = inc/
|
|
|
|
TESTF = tests/
|
|
|
|
DEPF = $(BUILDDIR)deps/
|
2020-10-02 16:01:57 +02:00
|
|
|
OUTF = ./
|
2020-09-28 23:49:14 +02:00
|
|
|
|
|
|
|
INCLUDES = -I$(INCF)
|
|
|
|
LDFLAGS =
|
|
|
|
|
|
|
|
SRCFILES = $(shell find $(SRCF) -name "*.cpp")
|
|
|
|
OBJFILES = $(patsubst $(SRCF)%, $(BUILDDIR)%, $(patsubst %.cpp, %.o, $(SRCFILES)))
|
|
|
|
DEPFILES = $(wildcard $(DEPF)*.d)
|
|
|
|
|
|
|
|
SOURCEDIRS = $(shell find $(SRCF) -type d -printf "%p/\n")
|
|
|
|
BUILDDIRS = $(patsubst $(SRCF)%, $(BUILDDIR)%, $(SOURCEDIRS))
|
|
|
|
|
|
|
|
INCLUDES += $(addprefix -I, $(SOURCEDIRS))
|
|
|
|
|
2021-03-04 10:18:18 +01:00
|
|
|
all: $(OUTF)$(NAME) $(OUTF)$(NAMESTATIC) runtest
|
|
|
|
|
|
|
|
$(OUTF)$(NAMESTATIC): $(BUILDDIRS) $(DEPF) $(OBJFILES)
|
|
|
|
@echo "Archiving $@"
|
|
|
|
@$(AR) rs $@ $(filter %.o, $^)
|
2020-09-28 23:49:14 +02:00
|
|
|
|
2020-10-02 16:01:57 +02:00
|
|
|
$(OUTF)$(NAME): $(BUILDDIRS) $(DEPF) $(OBJFILES)
|
2020-09-28 23:49:14 +02:00
|
|
|
@echo "Linking $@"
|
2020-10-02 16:01:57 +02:00
|
|
|
@$(CXX) -shared -o $@ $(filter %.o, $^)
|
2020-09-28 23:49:14 +02:00
|
|
|
|
|
|
|
$(BUILDDIR)%.o: $(SRCF)%.cpp
|
|
|
|
@echo "Compiling: $@"
|
|
|
|
@$(CXX) $(CFLAGS) $(INCLUDES) $< -MM -MT $@ > $(DEPF)$(subst /,_,$*).d
|
|
|
|
@$(CXX) -c -o $@ $(CFLAGS) $(INCLUDES) $<
|
|
|
|
|
|
|
|
%/:
|
|
|
|
mkdir -p $@
|
|
|
|
|
|
|
|
clean-depends:
|
|
|
|
$(RM) -r $(DEPF)
|
|
|
|
|
|
|
|
clean:
|
2021-03-23 02:19:09 +01:00
|
|
|
$(RM) -r $(OUTF)$(NAME) $(BUILDDIR) $(NAMETEST) $(NAMESTATIC) $(NAMESHORT).deb
|
2020-09-28 23:49:14 +02:00
|
|
|
|
2021-03-04 10:18:18 +01:00
|
|
|
$(NAMETEST): $(TESTF)*.cpp $(NAMESTATIC)
|
2020-09-28 23:49:14 +02:00
|
|
|
@echo "Compiling tests"
|
2021-03-04 10:18:18 +01:00
|
|
|
@$(CXX) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS)
|
2020-09-28 23:49:14 +02:00
|
|
|
|
|
|
|
runtest: $(NAMETEST)
|
|
|
|
@echo "Running tests"
|
2021-03-04 10:18:18 +01:00
|
|
|
./$<
|
2020-09-28 23:49:14 +02:00
|
|
|
|
2021-03-23 02:19:09 +01:00
|
|
|
builddeb: $(NAME)
|
|
|
|
mkdir -p $(BUILDDIR)deb/$(NAMESHORT)/DEBIAN/
|
|
|
|
mkdir -p $(BUILDDIR)deb/$(NAMESHORT)/usr/lib/
|
|
|
|
mkdir -p $(BUILDDIR)deb/$(NAMESHORT)/usr/include/$(NAMESHORT)/
|
|
|
|
cp -f ./debconfig $(BUILDDIR)deb/$(NAMESHORT)/DEBIAN/control
|
|
|
|
cp -f ./$(NAME) $(BUILDDIR)deb/$(NAMESHORT)/usr/lib/
|
|
|
|
cp -rf $(INCF)* $(BUILDDIR)deb/$(NAMESHORT)/usr/include/$(NAMESHORT)/
|
|
|
|
dpkg-deb --build $(BUILDDIR)deb/$(NAMESHORT)
|
|
|
|
cp -f $(BUILDDIR)deb/$(NAMESHORT).deb .
|
|
|
|
|
2020-09-28 23:49:14 +02:00
|
|
|
install: $(NAME)
|
|
|
|
cp -f ./$(NAME) /usr/lib/
|
2020-10-02 16:10:03 +02:00
|
|
|
mkdir -p /usr/include/$(NAMESHORT)/
|
2020-10-02 16:01:57 +02:00
|
|
|
cp -rf $(INCF)* /usr/include/$(NAMESHORT)/
|
2020-09-28 23:49:14 +02:00
|
|
|
|
|
|
|
uninstall:
|
2020-10-02 16:01:57 +02:00
|
|
|
$(RM) -r /usr/lib/$(NAME) /usr/include/$(NAMESHORT)/
|
2020-09-28 23:49:14 +02:00
|
|
|
|
2020-10-02 16:01:57 +02:00
|
|
|
.PHONY: clean all clean-depends runtest install uninstall
|
2020-09-28 23:49:14 +02:00
|
|
|
|
|
|
|
include $(DEPFILES)
|