2021-12-21 10:45:00 +01:00
|
|
|
include premake.make
|
2020-03-16 12:17:56 +01:00
|
|
|
|
2021-12-21 10:45:00 +01:00
|
|
|
LIBNAME := $(shell basename $$(pwd))
|
2020-03-16 12:17:56 +01:00
|
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
CONFIGDIR ?= $(PREFIX)/etc
|
|
|
|
INCLUDEDIR ?= $(PREFIX)/include
|
|
|
|
LIBDIR ?= $(PREFIX)/lib
|
|
|
|
DATADIR ?= $(PREFIX)/share
|
|
|
|
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
|
|
|
|
MANDIR ?= $(PREFIX)/man
|
|
|
|
|
2020-03-16 12:17:56 +01:00
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
LINKERNAME := $(LIBNAME).dylib
|
|
|
|
SONAME := $(LIBNAME).$(MAJOR).dylib
|
|
|
|
REALNAME := $(LINKERNAME)
|
2021-12-21 10:45:00 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),OpenBSD)
|
|
|
|
REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR)
|
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
2020-03-16 12:17:56 +01:00
|
|
|
LINKERNAME := $(LIBNAME).so
|
|
|
|
SONAME := $(LINKERNAME).$(MAJOR)
|
2021-12-21 10:45:00 +01:00
|
|
|
REALNAME := $(SONAME).$(MINOR).$(PATCH)
|
2020-03-16 12:17:56 +01:00
|
|
|
endif
|
2021-12-21 10:45:00 +01:00
|
|
|
STATICLIB := $(LIBNAME).a
|
2020-03-16 12:17:56 +01:00
|
|
|
|
|
|
|
CXX ?= g++
|
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
|
|
|
|
CXXFLAGS += -g3 -std=c++20 -fPIC
|
2020-03-16 12:17:56 +01:00
|
|
|
ifeq ($(DEBUG),1)
|
|
|
|
CXXFLAGS += -D DEBUG -O0
|
2021-12-21 10:45:00 +01:00
|
|
|
CONFIG := debug
|
2020-03-16 12:17:56 +01:00
|
|
|
else
|
|
|
|
CXXFLAGS += -D NDEBUG -O3
|
2021-12-21 10:45:00 +01:00
|
|
|
CONFIG := release
|
2020-03-16 12:17:56 +01:00
|
|
|
endif
|
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
OUTDIR := build/$(CONFIG)
|
|
|
|
BUILDDIR := build/obj
|
|
|
|
|
|
|
|
SRCS := $(notdir $(wildcard src/*.cpp))
|
|
|
|
OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o))
|
|
|
|
DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep))
|
|
|
|
HDRS ?= $(wildcard src/*.hpp)
|
|
|
|
MANS := $(addprefix $(PREFIX)/, $(wildcard man/man*/*))
|
|
|
|
|
|
|
|
$(BUILDDIR)/%.o: src/%.cpp
|
|
|
|
$(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $<
|
|
|
|
|
|
|
|
%.dep: ;
|
|
|
|
|
|
|
|
$(MANDIR)/man1/%: man/man1/%
|
|
|
|
install -m 0644 $< $@
|
|
|
|
|
|
|
|
$(MANDIR)/man3/%: man/man3/%
|
|
|
|
install -m 0644 $< $@
|
|
|
|
|
|
|
|
$(MANDIR)/man5/%: man/man5/%
|
|
|
|
install -m 0644 $< $@
|
2020-03-16 12:17:56 +01:00
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
.PHONY: all test clean install
|
2021-12-21 10:45:00 +01:00
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
all: $(BUILDDIR) $(OUTDIR) $(OUTDIR)/$(REALNAME) $(OUTDIR)/$(STATICLIB)
|
2021-12-21 10:45:00 +01:00
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
$(BUILDDIR):
|
|
|
|
mkdir -p $@
|
2020-03-16 12:17:56 +01:00
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
$(OUTDIR):
|
|
|
|
mkdir -p $@
|
2021-12-21 10:45:00 +01:00
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
$(OUTDIR)/$(REALNAME): $(OBJS)
|
2020-03-16 12:17:56 +01:00
|
|
|
ifeq ($(UNAME_S),Darwin)
|
2024-09-12 15:02:55 +02:00
|
|
|
$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
2021-12-21 10:45:00 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),OpenBSD)
|
2024-09-12 15:02:55 +02:00
|
|
|
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
2021-12-21 10:45:00 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
2024-09-12 15:02:55 +02:00
|
|
|
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
2020-03-16 12:17:56 +01:00
|
|
|
endif
|
|
|
|
|
2024-09-12 16:37:12 +02:00
|
|
|
-include $(DEPS)
|
2020-03-16 12:17:56 +01:00
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
$(OUTDIR)/$(STATICLIB): $(OBJS)
|
|
|
|
ar r $(OUTDIR)/$(STATICLIB) $(OBJS)
|
2021-12-21 10:45:00 +01:00
|
|
|
|
2021-12-22 17:28:06 +01:00
|
|
|
ifeq ($(GENERATELIBHEADER),1)
|
2024-09-12 15:02:55 +02:00
|
|
|
$(OUTDIR)/$(LIBNAME).hpp: $(HDRS)
|
|
|
|
@echo updating $(OUTDIR)/$(LIBNAME).hpp
|
|
|
|
@cp /dev/null $(OUTDIR)/$(LIBNAME).hpp
|
2020-03-16 12:17:56 +01:00
|
|
|
@for h in $(HDRS); \
|
|
|
|
do \
|
2024-09-12 15:02:55 +02:00
|
|
|
sed '/@exclude/d' $$h >> $(OUTDIR)/$(LIBNAME).hpp; \
|
2021-12-21 10:45:00 +01:00
|
|
|
done
|
2021-12-22 17:28:06 +01:00
|
|
|
endif
|
2020-04-29 17:00:03 +02:00
|
|
|
|
|
|
|
test:
|
2021-12-21 10:45:00 +01:00
|
|
|
$(MAKE) -C tests && tests/tests
|
2020-03-16 12:17:56 +01:00
|
|
|
|
|
|
|
clean:
|
2024-09-12 15:02:55 +02:00
|
|
|
rm -rf build
|
2021-12-21 10:45:00 +01:00
|
|
|
$(MAKE) -C tests clean
|
|
|
|
|
2024-09-12 15:02:55 +02:00
|
|
|
$(MANDIR)/man1:
|
|
|
|
install -m 0755 -d $@
|
|
|
|
|
|
|
|
$(MANDIR)/man3:
|
|
|
|
install -m 0755 -d $@
|
|
|
|
|
|
|
|
$(MANDIR)/man5:
|
|
|
|
install -m 0755 -d $@
|
|
|
|
|
|
|
|
$(LIBDIR):
|
|
|
|
install -m 0755 -d $@
|
|
|
|
|
|
|
|
$(INCLUDEDIR):
|
|
|
|
install -m 0755 -d $@
|
|
|
|
|
2021-12-22 17:28:06 +01:00
|
|
|
ifeq ($(GENERATELIBHEADER),1)
|
2024-09-12 15:02:55 +02:00
|
|
|
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(OUTDIR)/$(LIBNAME).hpp
|
|
|
|
install -m 0644 $(OUTDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
|
2021-12-22 17:28:06 +01:00
|
|
|
else
|
2024-09-12 15:02:55 +02:00
|
|
|
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS)
|
|
|
|
install -m 0644 $(HDRS) $(INCLUDEDIR)/$(LIBNAME)
|
2021-12-22 17:28:06 +01:00
|
|
|
endif
|
2024-09-12 15:02:55 +02:00
|
|
|
install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR)
|
|
|
|
install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR)
|
2020-03-16 12:17:56 +01:00
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
2021-12-21 10:45:00 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
2024-09-26 12:56:03 +02:00
|
|
|
ifeq ($(UID), 0)
|
2020-03-16 12:17:56 +01:00
|
|
|
ldconfig
|
2024-09-26 12:56:03 +02:00
|
|
|
else
|
|
|
|
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
|
|
|
endif
|
2020-03-16 12:17:56 +01:00
|
|
|
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
|
|
|
|
endif
|
2023-04-15 23:30:16 +02:00
|
|
|
ifeq ($(UNAME_S),OpenBSD)
|
|
|
|
ldconfig -R
|
|
|
|
endif
|
2024-09-12 15:02:55 +02:00
|
|
|
|
|
|
|
-include postmake.make
|