Migrate to latest project structure
Bump version to 1.1.0
This commit is contained in:
		
							
								
								
									
										238
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										238
									
								
								Makefile
									
									
									
									
									
								
							| @@ -1,54 +1,78 @@ | ||||
| include premake.make | ||||
|  | ||||
| LIBNAME := $(shell basename $$(pwd)) | ||||
| UNAME_S := $(shell uname -s) | ||||
| # 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)\";" | ||||
|  | ||||
| # some important install locations | ||||
| PREFIX ?= /usr/local | ||||
| BINDIR ?= $(PREFIX)/bin | ||||
| CONFIGDIR ?= $(PREFIX)/etc | ||||
| INCLUDEDIR ?= $(PREFIX)/include | ||||
| LIBDIR ?= $(PREFIX)/lib | ||||
| DATADIR ?= $(PREFIX)/share | ||||
| DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc | ||||
| MANDIR ?= $(PREFIX)/man | ||||
| DATADIR ?= $(PREFIX)/share/$(PROJ) | ||||
| DOCDIR ?= $(DATADIR)/doc | ||||
|  | ||||
| ifeq ($(UNAME_S),Darwin) | ||||
| 	LINKERNAME := $(LIBNAME).dylib | ||||
| 	SONAME := $(LIBNAME).$(MAJOR).dylib | ||||
| # setup naming and versioning for library product | ||||
| ifeq ($(UNAME_S), Darwin) | ||||
| 	LINKERNAME := $(PROJ).dylib | ||||
| 	SONAME := $(PROJ).$(MAJOR).dylib | ||||
| 	REALNAME := $(LINKERNAME) | ||||
| endif | ||||
| ifeq ($(UNAME_S),OpenBSD) | ||||
| 	REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR) | ||||
| endif | ||||
| ifeq ($(UNAME_S),Linux) | ||||
| 	LINKERNAME := $(LIBNAME).so | ||||
| else ifeq ($(UNAME_S), OpenBSD) | ||||
| 	REALNAME := $(PROJ).so.$(MAJOR).$(MINOR) | ||||
| else ifeq ($(UNAME_S), Linux) | ||||
| 	LINKERNAME := $(PROJ).so | ||||
| 	SONAME := $(LINKERNAME).$(MAJOR) | ||||
| 	REALNAME := $(SONAME).$(MINOR).$(PATCH) | ||||
| endif | ||||
| STATICLIB := $(LIBNAME).a | ||||
| STATICLIB := $(PROJ).a | ||||
|  | ||||
| # select default compiler | ||||
| CXX ?= g++ | ||||
|  | ||||
| # setup compiler flags and build config | ||||
| CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter | ||||
| CXXFLAGS += -g3 -std=c++20 -fPIC | ||||
| ifeq ($(DEBUG),1) | ||||
| 	CXXFLAGS += -D DEBUG -O0 | ||||
| CXXFLAGS += -g3 -fPIC | ||||
| ifeq ($(DEBUG), 1) | ||||
| 	CXXFLAGS += -DDEBUG -O0 | ||||
| 	CONFIG := debug | ||||
| else | ||||
| 	CXXFLAGS += -D NDEBUG -O3 | ||||
| 	CXXFLAGS += -DNDEBUG -O3 | ||||
| 	CONFIG := release | ||||
| endif | ||||
|  | ||||
| # setup build locations | ||||
| OUTDIR := build/$(CONFIG) | ||||
| BUILDDIR := build/obj | ||||
| BIN := $(OUTDIR)/$(PROJ) | ||||
|  | ||||
| SRCS := $(notdir $(wildcard src/*.cpp)) | ||||
| # define sources and derived files | ||||
| # allow for extra sources defined in premake.make | ||||
| SRCS += $(notdir $(wildcard src/*.cpp)) | ||||
| OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o)) | ||||
| DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep)) | ||||
| HDRS ?= $(wildcard src/*.hpp) | ||||
| HDRS ?= $(filter-out src/precomp.hpp, $(wildcard src/*.hpp)) | ||||
| 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 =========================================================== | ||||
|  | ||||
| $(BUILDDIR)/%.o: src/%.cpp | ||||
| ifeq ($(PRECOMPILE), 1) | ||||
| 	$(CXX) $(CXXFLAGS) -o $@ -include precomp.hpp -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $< | ||||
| else | ||||
| 	$(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $< | ||||
| endif | ||||
|  | ||||
| %.dep: ; | ||||
|  | ||||
| @@ -61,9 +85,19 @@ $(MANDIR)/man3/%: man/man3/% | ||||
| $(MANDIR)/man5/%: man/man5/% | ||||
| 	install -m 0644 $< $@ | ||||
|  | ||||
| .PHONY: all test clean install | ||||
| # =========================================================== pattern rules | ||||
|  | ||||
| all: $(BUILDDIR) $(OUTDIR) $(OUTDIR)/$(REALNAME) $(OUTDIR)/$(STATICLIB) | ||||
| # targets ================================================================= | ||||
|  | ||||
| .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 | ||||
|  | ||||
| $(BUILDDIR): | ||||
| 	mkdir -p $@ | ||||
| @@ -71,29 +105,75 @@ $(BUILDDIR): | ||||
| $(OUTDIR): | ||||
| 	mkdir -p $@ | ||||
|  | ||||
| # 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 | ||||
| $(OUTDIR)/$(REALNAME): $(OBJS) | ||||
| endif | ||||
| ifeq ($(UNAME_S),Darwin) | ||||
| 	$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS) | ||||
| endif | ||||
| ifeq ($(UNAME_S),OpenBSD) | ||||
| 	$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -install_name $(LIBDIR)/$(REALNAME) \ | ||||
| -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS) | ||||
| else ifeq ($(UNAME_S),OpenBSD) | ||||
| 	$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS) | ||||
| endif | ||||
| ifeq ($(UNAME_S),Linux) | ||||
| else 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 | ||||
| $(OUTDIR)/$(PROJ).hpp: $(HDRS) | ||||
| 	@echo updating $(OUTDIR)/$(PROJ).hpp | ||||
| 	@cp /dev/null $(OUTDIR)/$(PROJ).hpp | ||||
| 	@for h in $(HDRS); \ | ||||
| 	do \ | ||||
| 		sed '/@exclude/d' $$h >> $(OUTDIR)/$(LIBNAME).hpp; \ | ||||
| 		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 ;\ | ||||
| 	done | ||||
| endif | ||||
|  | ||||
| @@ -101,8 +181,16 @@ test: | ||||
| 	$(MAKE) -C tests && tests/tests | ||||
|  | ||||
| clean: | ||||
| 	rm -rf build | ||||
| 	$(MAKE) -C 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 | ||||
|  | ||||
| $(MANDIR)/man1: | ||||
| 	install -m 0755 -d $@ | ||||
| @@ -113,34 +201,94 @@ $(MANDIR)/man3: | ||||
| $(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 | ||||
|  | ||||
| $(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) | ||||
| $(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) | ||||
| else | ||||
| install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) | ||||
| 	install -m 0644 $(HDRS) $(INCLUDEDIR)/$(LIBNAME) | ||||
| install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(INCLUDEDIR)/$(PROJ) install-data install-plugins | ||||
| 	install -m 0644 $(HDRS) $(INCLUDEDIR)/$(PROJ) | ||||
| endif | ||||
| 	install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR) | ||||
| 	install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR) | ||||
| ifeq ($(UNAME_S),Darwin) | ||||
| ifeq ($(UNAME_S), Darwin) | ||||
| 	cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME) | ||||
| endif | ||||
| ifeq ($(UNAME_S),Linux) | ||||
| else 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) | ||||
| else ifeq ($(UNAME_S), OpenBSD) | ||||
| 	ldconfig -R | ||||
| 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) | ||||
| 	ldconfig -R | ||||
| endif | ||||
|  | ||||
| endif # --------------------------------------------------------------- lib | ||||
|  | ||||
| # ================================================================= targets | ||||
|  | ||||
| # project-specific targets go in here | ||||
| -include postmake.make | ||||
|   | ||||
		Reference in New Issue
	
	Block a user