libscconfig/Makefile

295 lines
7.3 KiB
Makefile
Raw Permalink Normal View History

2021-07-02 17:59:45 +02:00
include premake.make
# git commit hash and version for this build
COMMIT-HASH != git log 2>/dev/null | sed -e '1s/^commit //;q'
COMMIT := "static const char* commit = \"$(COMMIT-HASH)\";"
VERSION := "static const char* version = \"$(MAJOR).$(MINOR).$(PATCH)\";"
2021-07-02 17:59:45 +02:00
# some important install locations
2024-09-12 14:49:42 +02:00
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
2024-09-12 14:49:42 +02:00
CONFIGDIR ?= $(PREFIX)/etc
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
MANDIR ?= $(PREFIX)/man
DATADIR ?= $(PREFIX)/share/$(PROJ)
DOCDIR ?= $(DATADIR)/doc
2024-09-12 14:49:42 +02:00
# setup naming and versioning for library product
ifeq ($(UNAME_S), Darwin)
LINKERNAME := $(PROJ).dylib
SONAME := $(PROJ).$(MAJOR).dylib
2021-07-02 17:59:45 +02:00
REALNAME := $(LINKERNAME)
else ifeq ($(UNAME_S), OpenBSD)
REALNAME := $(PROJ).so.$(MAJOR).$(MINOR)
else ifeq ($(UNAME_S), Linux)
LINKERNAME := $(PROJ).so
2021-07-02 17:59:45 +02:00
SONAME := $(LINKERNAME).$(MAJOR)
2021-12-21 09:33:09 +01:00
REALNAME := $(SONAME).$(MINOR).$(PATCH)
2021-07-02 17:59:45 +02:00
endif
STATICLIB := $(PROJ).a
2021-07-02 17:59:45 +02:00
# select default compiler
2021-07-02 17:59:45 +02:00
CXX ?= g++
# setup compiler flags and build config
2024-09-12 14:49:42 +02:00
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
CXXFLAGS += -g3 -fPIC
ifeq ($(DEBUG), 1)
CXXFLAGS += -DDEBUG -O0
2021-07-02 17:59:45 +02:00
CONFIG := debug
else
CXXFLAGS += -DNDEBUG -O3
2021-07-02 17:59:45 +02:00
CONFIG := release
endif
# setup build locations
2024-09-12 14:49:42 +02:00
OUTDIR := build/$(CONFIG)
BUILDDIR := build/obj
BIN := $(OUTDIR)/$(PROJ)
2024-09-12 14:49:42 +02:00
# define sources and derived files
# allow for extra sources defined in premake.make
SRCS += $(notdir $(wildcard src/*.cpp))
2024-09-12 14:49:42 +02:00
OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o))
DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep))
HDRS ?= $(filter-out src/precomp.hpp, $(wildcard src/*.hpp))
2024-09-12 14:49:42 +02:00
MANS := $(addprefix $(PREFIX)/, $(wildcard man/man*/*))
# if project supports plugins, link to libdl where needed
ifdef PLUGINS
ifeq ($(UNAME_S),Darwin)
LDLIBS += -ldl
else ifeq ($(UNAME_S),Linux)
LDLIBS += -ldl
endif
endif
# pattern rules ===========================================================
2024-09-12 14:49:42 +02:00
$(BUILDDIR)/%.o: src/%.cpp
ifeq ($(PRECOMPILE), 1)
$(CXX) $(CXXFLAGS) -o $@ -include precomp.hpp -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $<
else
2024-09-12 14:49:42 +02:00
$(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $<
endif
2024-09-12 14:49:42 +02:00
%.dep: ;
$(MANDIR)/man1/%: man/man1/%
install -m 0644 $< $@
$(MANDIR)/man3/%: man/man3/%
install -m 0644 $< $@
$(MANDIR)/man5/%: man/man5/%
install -m 0644 $< $@
2021-07-02 17:59:45 +02:00
# =========================================================== pattern rules
# targets =================================================================
2021-07-02 17:59:45 +02:00
.PHONY: all commit-hash version plugins test clean dist-clean install-plugins \
install install-data uninstall-data uninstall-plugins uninstall
# main target
ifeq ($(PRODUCT), tool)
all: $(BUILDDIR) $(OUTDIR) commit-hash version plugins $(BIN)
else ifeq ($(PRODUCT), lib)
all: $(BUILDDIR) $(OUTDIR) commit-hash version plugins $(OUTDIR)/$(REALNAME) $(OUTDIR)/$(STATICLIB)
endif
2021-07-02 17:59:45 +02:00
2024-09-12 14:49:42 +02:00
$(BUILDDIR):
mkdir -p $@
2021-07-02 17:59:45 +02:00
2024-09-12 14:49:42 +02:00
$(OUTDIR):
mkdir -p $@
2021-07-02 17:59:45 +02:00
# product build rules
ifeq ($(PRODUCT), tool) # -------------------------------------------- tool
ifeq ($(PRECOMPILE), 1)
$(BIN): precomp.hpp.gch $(OBJS)
else
$(BIN): $(OBJS)
endif
$(CXX) -o $(BIN) $(LDFLAGS) $(OBJS) $(LDLIBS)
@ln -sf $(BIN) $(PROJ)
endif # -------------------------------------------------------------- tool
ifeq ($(PRODUCT), lib) # ---------------------------------------------- lib
ifeq ($(PRECOMPILE), 1)
$(OUTDIR)/$(REALNAME): precomp.hpp.gch $(OBJS)
else
2024-09-12 14:49:42 +02:00
$(OUTDIR)/$(REALNAME): $(OBJS)
endif
2021-07-02 17:59:45 +02:00
ifeq ($(UNAME_S),Darwin)
2024-12-29 16:54:00 +01:00
$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -install_name $(LIBDIR)/$(REALNAME) \
-current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS)
else ifeq ($(UNAME_S),OpenBSD)
2024-09-12 14:49:42 +02:00
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
else ifeq ($(UNAME_S),Linux)
2024-09-12 14:49:42 +02:00
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
2021-07-02 17:59:45 +02:00
endif
2024-09-12 14:49:42 +02:00
$(OUTDIR)/$(STATICLIB): $(OBJS)
ar r $(OUTDIR)/$(STATICLIB) $(OBJS)
2021-12-21 09:33:09 +01:00
2023-02-09 18:58:56 +01:00
ifeq ($(GENERATELIBHEADER),1)
$(OUTDIR)/$(PROJ).hpp: $(HDRS)
@echo updating $(OUTDIR)/$(PROJ).hpp
@cp /dev/null $(OUTDIR)/$(PROJ).hpp
2021-07-02 17:59:45 +02:00
@for h in $(HDRS); \
do \
sed '/@exclude/d' $$h >> $(OUTDIR)/$(PROJ).hpp; \
done
endif
endif # --------------------------------------------------------------- lib
# get generated dependencies, if any
-include $(DEPS)
commit-hash:
@if ! echo $(COMMIT) | diff -q src/commit.inc - >/dev/null 2>&1 ;\
then \
echo $(COMMIT) > src/commit.inc ;\
fi
version:
@if ! echo $(VERSION) | diff -q src/version.inc - >/dev/null 2>&1 ;\
then \
echo $(VERSION) > src/version.inc ;\
fi
$(BUILDDIR)/version.o: src/version.inc src/commit.inc
precomp.hpp.gch: src/precomp.hpp
$(CXX) $< $(CXXFLAGS) -o $@
plugins:
ifdef PLUGINS
@for plug in $(PLUGINS) ;\
do \
$(MAKE) -C $$plug ;\
2021-07-02 17:59:45 +02:00
done
2023-02-09 18:58:56 +01:00
endif
2021-07-02 17:59:45 +02:00
test:
$(MAKE) -C tests && tests/tests
clean:
rm -rf $(BUILDDIR) tests/build tests/tests tests/src/commit.inc tests/src/version.inc
ifdef PLUGINS
@for plug in $(PLUGINS) ;\
do \
$(MAKE) -C $$plug clean ;\
done
endif
dist-clean: clean
rm -rf build $(PROJ) src/commit.inc src/version.inc precomp.hpp.gch
2021-07-02 17:59:45 +02:00
2024-09-12 14:49:42 +02:00
$(MANDIR)/man1:
install -m 0755 -d $@
$(MANDIR)/man3:
install -m 0755 -d $@
$(MANDIR)/man5:
install -m 0755 -d $@
$(DATADIR):
install -m 0755 -d $@
# (un)install targets
ifdef DATAFILES
install-data: $(DATADIR)
install -m 0644 $(DATAFILES) $(DATADIR)
else
install-data:
endif
uninstall-data:
rm -rf $(DATADIR)
install-plugins:
ifdef PLUGINS
@for plug in $(PLUGINS) ;\
do \
$(MAKE) -C $$plug install ;\
done
endif
uninstall-plugins:
ifdef PLUGINS
@for plug in $(PLUGINS) ;\
do \
$(MAKE) -C $$plug uninstall ;\
done
endif
ifeq ($(PRODUCT), tool) # -------------------------------------------- tool
$(BINDIR):
install -m 0755 -d $@
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(BINDIR) $(MANS) install-data install-plugins
install -m 0755 $(BIN) $(BINDIR)
uninstall: uninstall-data uninstall-plugins
rm -f $(BINDIR)/$(PROJ) $(MANS)
endif # -------------------------------------------------------------- tool
ifeq ($(PRODUCT), lib) # ---------------------------------------------- lib
2024-09-12 14:49:42 +02:00
$(LIBDIR):
install -m 0755 -d $@
$(INCLUDEDIR):
install -m 0755 -d $@
$(INCLUDEDIR)/$(PROJ):
install -m 0755 -d $@
ifeq ($(GENERATELIBHEADER), 1)
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(OUTDIR)/$(PROJ).hpp install-data install-plugins
install -m 0644 $(OUTDIR)/$(PROJ).hpp $(INCLUDEDIR)
2023-02-09 18:58:56 +01:00
else
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(INCLUDEDIR)/$(PROJ) install-data install-plugins
install -m 0644 $(HDRS) $(INCLUDEDIR)/$(PROJ)
2023-02-09 18:58:56 +01:00
endif
2024-09-12 14:49:42 +02:00
install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR)
install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR)
ifeq ($(UNAME_S), Darwin)
2021-07-02 17:59:45 +02:00
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
else ifeq ($(UNAME_S), Linux)
2024-09-26 15:13:12 +02:00
ifeq ($(USER), root)
2021-07-02 17:59:45 +02:00
ldconfig
2024-09-26 12:56:37 +02:00
else
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
endif
2021-07-02 17:59:45 +02:00
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
else ifeq ($(UNAME_S), OpenBSD)
ldconfig -R
2021-07-02 17:59:45 +02:00
endif
uninstall: uninstall-data uninstall-plugins
rm -rf $(INCLUDEDIR)/$(PROJ).hpp $(INCLUDEDIR)/$(PROJ) $(MANS) $(LIBDIR)/$(STATICLIB) $(LIBDIR)/$(REALNAME) $(LIBDIR)/$(SONAME) $(LIBDIR)/$(LINKERNAME)
ifeq ($(UNAME_S), Linux)
ldconfig
else ifeq ($(UNAME_S), OpenBSD)
2023-04-15 23:31:39 +02:00
ldconfig -R
endif
2024-09-12 14:49:42 +02:00
endif # --------------------------------------------------------------- lib
# ================================================================= targets
# project-specific targets go in here
2024-09-12 14:49:42 +02:00
-include postmake.make