Replace Makefile with new version

But stay on C++17 for u8 compatibility.
This commit is contained in:
Bob Polis 2024-09-12 14:55:04 +02:00
parent 3b97dd7116
commit e3a5088dfe

123
Makefile
View File

@ -3,6 +3,14 @@ include premake.make
LIBNAME := $(shell basename $$(pwd))
UNAME_S := $(shell uname -s)
PREFIX ?= /usr/local
CONFIGDIR ?= $(PREFIX)/etc
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
DATADIR ?= $(PREFIX)/share
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
MANDIR ?= $(PREFIX)/man
ifeq ($(UNAME_S),Darwin)
LINKERNAME := $(LIBNAME).dylib
SONAME := $(LIBNAME).$(MAJOR).dylib
@ -18,24 +26,10 @@ ifeq ($(UNAME_S),Linux)
endif
STATICLIB := $(LIBNAME).a
BUILDDIR := build/intermediates/
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/man
CONFIGDIR ?= $(PREFIX)/etc
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
DATADIR ?= $(PREFIX)/share
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
SRCS := $(notdir $(wildcard src/*.cpp))
OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.d)
HDRS ?= $(wildcard src/*.hpp)
CXX ?= g++
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g3 -std=c++17 -fPIC
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
CXXFLAGS += -g3 -std=c++17 -fPIC
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
CONFIG := debug
@ -43,72 +37,97 @@ else
CXXFLAGS += -D NDEBUG -O3
CONFIG := release
endif
OUTDIR := build/$(CONFIG)/
RM := /bin/rm -rf
INSTALL := /usr/bin/install -c
OUTDIR := build/$(CONFIG)
BUILDDIR := build/obj
vpath %.cpp src
vpath %.d $(BUILDDIR)
vpath %.o $(BUILDDIR)
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*/*))
.PHONY: all clean install prebuild test
$(BUILDDIR)/%.o: src/%.cpp
$(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $<
all: prebuild $(OUTDIR)$(REALNAME) $(OUTDIR)$(STATICLIB)
%.dep: ;
prebuild:
@mkdir -p $(BUILDDIR) $(OUTDIR)
$(MANDIR)/man1/%: man/man1/%
install -m 0644 $< $@
$(OUTDIR)$(REALNAME): $(OBJS)
$(MANDIR)/man3/%: man/man3/%
install -m 0644 $< $@
$(MANDIR)/man5/%: man/man5/%
install -m 0644 $< $@
.PHONY: all test clean install
all: $(BUILDDIR) $(OUTDIR) $(OUTDIR)/$(REALNAME) $(OUTDIR)/$(STATICLIB)
$(BUILDDIR):
mkdir -p $@
$(OUTDIR):
mkdir -p $@
$(OUTDIR)/$(REALNAME): $(OBJS)
ifeq ($(UNAME_S),Darwin)
$(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(addprefix $(BUILDDIR),$(OBJS)) $(LDLIBS)
$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS)
endif
ifeq ($(UNAME_S),OpenBSD)
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(addprefix $(BUILDDIR),$(OBJS)) $(LDLIBS)
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
endif
ifeq ($(UNAME_S),Linux)
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(addprefix $(BUILDDIR),$(OBJS)) $(LDLIBS)
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
endif
%.o %.d: %.cpp
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
@mv $@ $*.d $(BUILDDIR)
-include $(addprefix $(BUILDDIR), $(DEPS))
$(OUTDIR)$(STATICLIB): $(OBJS)
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
$(OUTDIR)/$(STATICLIB): $(OBJS)
ar r $(OUTDIR)/$(STATICLIB) $(OBJS)
ifeq ($(GENERATELIBHEADER),1)
$(LIBNAME).hpp: $(HDRS)
@echo updating build/$(LIBNAME).hpp
@cp /dev/null build/$(LIBNAME).hpp
$(OUTDIR)/$(LIBNAME).hpp: $(HDRS)
@echo updating $(OUTDIR)/$(LIBNAME).hpp
@cp /dev/null $(OUTDIR)/$(LIBNAME).hpp
@for h in $(HDRS); \
do \
sed '/@exclude/d' $$h >> build/$(LIBNAME).hpp; \
sed '/@exclude/d' $$h >> $(OUTDIR)/$(LIBNAME).hpp; \
done
HEADERSRCDIR := build
else
HEADERSRCDIR := src
INCLUDEDIR := $(INCLUDEDIR)/$(LIBNAME)
endif
test:
$(MAKE) -C tests && tests/tests
clean:
$(RM) build
rm -rf build
$(MAKE) -C tests clean
$(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 $@
ifeq ($(GENERATELIBHEADER),1)
install: $(LIBNAME).hpp
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(OUTDIR)/$(LIBNAME).hpp
install -m 0644 $(OUTDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
else
install:
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS)
install -m 0644 $(HDRS) $(INCLUDEDIR)/$(LIBNAME)
endif
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
$(INSTALL) -d $(INCLUDEDIR)
$(INSTALL) -m 644 $(HEADERSRCDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR)
install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR)
ifeq ($(UNAME_S),Darwin)
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
endif
@ -119,3 +138,5 @@ endif
ifeq ($(UNAME_S),OpenBSD)
ldconfig -R
endif
-include postmake.make