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