Replace Makefile with new version
But stay on C++17 for u8 compatibility.
This commit is contained in:
parent
3b97dd7116
commit
e3a5088dfe
123
Makefile
123
Makefile
@ -3,6 +3,14 @@ include premake.make
|
|||||||
LIBNAME := $(shell basename $$(pwd))
|
LIBNAME := $(shell basename $$(pwd))
|
||||||
UNAME_S := $(shell uname -s)
|
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)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
LINKERNAME := $(LIBNAME).dylib
|
LINKERNAME := $(LIBNAME).dylib
|
||||||
SONAME := $(LIBNAME).$(MAJOR).dylib
|
SONAME := $(LIBNAME).$(MAJOR).dylib
|
||||||
@ -18,24 +26,10 @@ ifeq ($(UNAME_S),Linux)
|
|||||||
endif
|
endif
|
||||||
STATICLIB := $(LIBNAME).a
|
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++
|
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)
|
ifeq ($(DEBUG),1)
|
||||||
CXXFLAGS += -D DEBUG -O0
|
CXXFLAGS += -D DEBUG -O0
|
||||||
CONFIG := debug
|
CONFIG := debug
|
||||||
@ -43,72 +37,97 @@ else
|
|||||||
CXXFLAGS += -D NDEBUG -O3
|
CXXFLAGS += -D NDEBUG -O3
|
||||||
CONFIG := release
|
CONFIG := release
|
||||||
endif
|
endif
|
||||||
OUTDIR := build/$(CONFIG)/
|
|
||||||
|
|
||||||
RM := /bin/rm -rf
|
OUTDIR := build/$(CONFIG)
|
||||||
INSTALL := /usr/bin/install -c
|
BUILDDIR := build/obj
|
||||||
|
|
||||||
vpath %.cpp src
|
SRCS := $(notdir $(wildcard src/*.cpp))
|
||||||
vpath %.d $(BUILDDIR)
|
OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o))
|
||||||
vpath %.o $(BUILDDIR)
|
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:
|
$(MANDIR)/man1/%: man/man1/%
|
||||||
@mkdir -p $(BUILDDIR) $(OUTDIR)
|
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)
|
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
|
endif
|
||||||
ifeq ($(UNAME_S),OpenBSD)
|
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
|
endif
|
||||||
ifeq ($(UNAME_S),Linux)
|
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
|
endif
|
||||||
|
|
||||||
%.o %.d: %.cpp
|
|
||||||
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
|
|
||||||
@mv $@ $*.d $(BUILDDIR)
|
|
||||||
|
|
||||||
-include $(addprefix $(BUILDDIR), $(DEPS))
|
-include $(addprefix $(BUILDDIR), $(DEPS))
|
||||||
|
|
||||||
$(OUTDIR)$(STATICLIB): $(OBJS)
|
$(OUTDIR)/$(STATICLIB): $(OBJS)
|
||||||
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
|
ar r $(OUTDIR)/$(STATICLIB) $(OBJS)
|
||||||
|
|
||||||
ifeq ($(GENERATELIBHEADER),1)
|
ifeq ($(GENERATELIBHEADER),1)
|
||||||
$(LIBNAME).hpp: $(HDRS)
|
$(OUTDIR)/$(LIBNAME).hpp: $(HDRS)
|
||||||
@echo updating build/$(LIBNAME).hpp
|
@echo updating $(OUTDIR)/$(LIBNAME).hpp
|
||||||
@cp /dev/null build/$(LIBNAME).hpp
|
@cp /dev/null $(OUTDIR)/$(LIBNAME).hpp
|
||||||
@for h in $(HDRS); \
|
@for h in $(HDRS); \
|
||||||
do \
|
do \
|
||||||
sed '/@exclude/d' $$h >> build/$(LIBNAME).hpp; \
|
sed '/@exclude/d' $$h >> $(OUTDIR)/$(LIBNAME).hpp; \
|
||||||
done
|
done
|
||||||
HEADERSRCDIR := build
|
|
||||||
else
|
|
||||||
HEADERSRCDIR := src
|
|
||||||
INCLUDEDIR := $(INCLUDEDIR)/$(LIBNAME)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(MAKE) -C tests && tests/tests
|
$(MAKE) -C tests && tests/tests
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) build
|
rm -rf build
|
||||||
$(MAKE) -C tests clean
|
$(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)
|
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
|
else
|
||||||
install:
|
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS)
|
||||||
|
install -m 0644 $(HDRS) $(INCLUDEDIR)/$(LIBNAME)
|
||||||
endif
|
endif
|
||||||
$(INSTALL) -d $(LIBDIR)
|
install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR)
|
||||||
$(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
|
install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR)
|
||||||
$(INSTALL) -d $(INCLUDEDIR)
|
|
||||||
$(INSTALL) -m 644 $(HEADERSRCDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
|
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
||||||
endif
|
endif
|
||||||
@ -119,3 +138,5 @@ endif
|
|||||||
ifeq ($(UNAME_S),OpenBSD)
|
ifeq ($(UNAME_S),OpenBSD)
|
||||||
ldconfig -R
|
ldconfig -R
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
-include postmake.make
|
||||||
|
Loading…
x
Reference in New Issue
Block a user