2021-12-21 11:59:59 +01:00
|
|
|
include premake.make
|
2020-03-16 12:05:52 +01:00
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
LIBNAME := $(shell basename $$(pwd))
|
2020-03-16 12:05:52 +01:00
|
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
|
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
LINKERNAME := $(LIBNAME).dylib
|
|
|
|
SONAME := $(LIBNAME).$(MAJOR).dylib
|
|
|
|
REALNAME := $(LINKERNAME)
|
2021-12-20 18:05:25 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),OpenBSD)
|
|
|
|
REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR)
|
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
2020-03-16 12:05:52 +01:00
|
|
|
LINKERNAME := $(LIBNAME).so
|
|
|
|
SONAME := $(LINKERNAME).$(MAJOR)
|
2021-12-20 18:05:25 +01:00
|
|
|
REALNAME := $(SONAME).$(MINOR).$(PATCH)
|
2020-03-16 12:05:52 +01:00
|
|
|
endif
|
2021-12-21 11:59:59 +01:00
|
|
|
STATICLIB := $(LIBNAME).a
|
2020-03-16 12:05:52 +01:00
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
BUILDDIR := build/intermediates/
|
2020-03-16 12:05:52 +01:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
BINDIR ?= $(PREFIX)/bin
|
2021-12-21 11:59:59 +01:00
|
|
|
CONFIGDIR ?= $(PREFIX)/etc
|
2020-03-16 12:05:52 +01:00
|
|
|
INCLUDEDIR ?= $(PREFIX)/include
|
2021-12-21 11:59:59 +01:00
|
|
|
LIBDIR ?= $(PREFIX)/lib
|
2020-03-16 12:05:52 +01:00
|
|
|
DATADIR ?= $(PREFIX)/share
|
|
|
|
MANDIR ?= $(DATADIR)/man
|
2021-12-21 11:59:59 +01:00
|
|
|
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
|
2020-03-16 12:05:52 +01:00
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
SRCS := $(notdir $(wildcard src/*.cpp))
|
|
|
|
OBJS := $(SRCS:.cpp=.o)
|
|
|
|
DEPS := $(SRCS:.cpp=.d)
|
|
|
|
HDRS := $(wildcard src/*.hpp)
|
2020-03-16 12:05:52 +01:00
|
|
|
|
|
|
|
CXX ?= g++
|
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC
|
2020-03-16 12:05:52 +01:00
|
|
|
ifeq ($(DEBUG),1)
|
|
|
|
CXXFLAGS += -D DEBUG -O0
|
2021-12-21 11:59:59 +01:00
|
|
|
CONFIG := debug
|
2020-03-16 12:05:52 +01:00
|
|
|
else
|
|
|
|
CXXFLAGS += -D NDEBUG -O3
|
2021-12-21 11:59:59 +01:00
|
|
|
CONFIG := release
|
2020-03-16 12:05:52 +01:00
|
|
|
endif
|
2021-12-21 11:59:59 +01:00
|
|
|
OUTDIR := build/$(CONFIG)/
|
2020-03-16 12:05:52 +01:00
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
RM := /bin/rm -rf
|
2020-03-16 12:05:52 +01:00
|
|
|
INSTALL := /usr/bin/install -c
|
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
vpath %.cpp src
|
|
|
|
vpath %.d $(BUILDDIR)
|
|
|
|
vpath %.o $(BUILDDIR)
|
2020-03-16 12:05:52 +01:00
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
.PHONY: all clean install prebuild test
|
|
|
|
|
|
|
|
all: prebuild $(OUTDIR)$(REALNAME) $(OUTDIR)$(STATICLIB)
|
|
|
|
|
|
|
|
prebuild:
|
|
|
|
@mkdir -p $(BUILDDIR) $(OUTDIR)
|
|
|
|
|
|
|
|
$(OUTDIR)$(REALNAME): $(OBJS) $(DEPS)
|
2020-03-16 12:05:52 +01:00
|
|
|
ifeq ($(UNAME_S),Darwin)
|
2021-12-21 11:59:59 +01:00
|
|
|
$(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
2021-12-20 18:05:25 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),OpenBSD)
|
2021-12-21 11:59:59 +01:00
|
|
|
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
2021-12-20 18:05:25 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
2021-12-21 11:59:59 +01:00
|
|
|
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
2020-03-16 12:05:52 +01:00
|
|
|
endif
|
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
%.o: %.cpp %.d
|
2020-03-16 12:05:52 +01:00
|
|
|
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
|
2021-12-21 11:59:59 +01:00
|
|
|
@mv $@ $*.d $(BUILDDIR)
|
2020-03-16 12:05:52 +01:00
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
-include $(BUILDDIR)*.d
|
2020-03-16 12:05:52 +01:00
|
|
|
|
|
|
|
%.d: ;
|
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
$(OUTDIR)$(STATICLIB): $(OBJS)
|
|
|
|
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
|
|
|
|
|
2020-03-16 12:05:52 +01:00
|
|
|
$(LIBNAME).hpp: $(HDRS)
|
2021-12-21 11:59:59 +01:00
|
|
|
@echo updating build/$(LIBNAME).hpp
|
|
|
|
@cp /dev/null build/$(LIBNAME).hpp
|
2020-03-16 12:05:52 +01:00
|
|
|
@for h in $(HDRS); \
|
|
|
|
do \
|
2021-12-21 11:59:59 +01:00
|
|
|
cat $$h >> build/$(LIBNAME).hpp; \
|
|
|
|
done
|
2020-03-16 12:05:52 +01:00
|
|
|
|
2021-12-21 11:59:59 +01:00
|
|
|
test:
|
|
|
|
$(MAKE) -C tests && tests/tests
|
2020-03-16 12:05:52 +01:00
|
|
|
|
|
|
|
clean:
|
2021-12-21 11:59:59 +01:00
|
|
|
$(RM) build
|
|
|
|
$(MAKE) -C tests clean
|
|
|
|
|
|
|
|
install: $(OUTDIR)$(REALNAME) $(LIBNAME).hpp
|
|
|
|
$(INSTALL) -d $(LIBDIR)
|
|
|
|
$(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
|
|
|
|
$(INSTALL) -d $(INCLUDEDIR)
|
|
|
|
$(INSTALL) -m 644 build/$(LIBNAME).hpp $(INCLUDEDIR)
|
2020-03-16 12:05:52 +01:00
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
2021-12-20 18:05:25 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
2020-03-16 12:05:52 +01:00
|
|
|
ldconfig
|
|
|
|
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
|
|
|
|
endif
|