libscgui/Makefile

147 lines
3.3 KiB
Makefile

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
REALNAME := $(LINKERNAME)
endif
ifeq ($(UNAME_S),OpenBSD)
REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR)
endif
ifeq ($(UNAME_S),Linux)
LINKERNAME := $(LIBNAME).so
SONAME := $(LINKERNAME).$(MAJOR)
REALNAME := $(SONAME).$(MINOR).$(PATCH)
endif
STATICLIB := $(LIBNAME).a
CXX ?= g++
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
CXXFLAGS += -g3 -std=c++20 -fPIC
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
CONFIG := debug
else
CXXFLAGS += -D NDEBUG -O3
CONFIG := release
endif
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 $< $@
.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) $(OBJS) $(LDLIBS)
endif
ifeq ($(UNAME_S),OpenBSD)
$(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) $(OBJS) $(LDLIBS)
endif
-include $(DEPS)
$(OUTDIR)/$(STATICLIB): $(OBJS)
ar r $(OUTDIR)/$(STATICLIB) $(OBJS)
ifeq ($(GENERATELIBHEADER),1)
$(OUTDIR)/$(LIBNAME).hpp: $(HDRS)
@echo updating $(OUTDIR)/$(LIBNAME).hpp
@cp /dev/null $(OUTDIR)/$(LIBNAME).hpp
@for h in $(HDRS); \
do \
sed '/@exclude/d' $$h >> $(OUTDIR)/$(LIBNAME).hpp; \
done
endif
test:
$(MAKE) -C tests && tests/tests
clean:
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: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(OUTDIR)/$(LIBNAME).hpp
install -m 0644 $(OUTDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
else
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS)
install -m 0644 $(HDRS) $(INCLUDEDIR)/$(LIBNAME)
endif
install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR)
install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR)
ifeq ($(UNAME_S),Darwin)
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
endif
ifeq ($(UNAME_S),Linux)
ifeq ($(USER), root)
ldconfig
else
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
endif
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
endif
ifeq ($(UNAME_S),OpenBSD)
ldconfig -R
endif
-include postmake.make