libscnumerics/Makefile

143 lines
3.3 KiB
Makefile
Raw Normal View History

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