From df1a8de79755939ce66ed5646e84ae6c1f5536d0 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Tue, 20 Dec 2016 17:29:54 +0100 Subject: [PATCH] Added configuration tool generation --- .gitignore | 3 +- Makefile | 80 ++++++++++++++++++++++++++++------------- Makefile.vars | 9 +++-- configure | 13 +++++-- tools/write-config | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 163 insertions(+), 30 deletions(-) create mode 100755 tools/write-config diff --git a/.gitignore b/.gitignore index 5a5fee9..6c579af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /Makefile.cfg /obj /libg1m.so* -/libg1m-*.dll +/libg1m.dll /man +/bin diff --git a/Makefile b/Makefile index fa39e6e..4ab9896 100755 --- a/Makefile +++ b/Makefile @@ -9,14 +9,14 @@ include Makefile.msg # General targets # #******************************************************************************# # Build everything. -all: all-lib all-doc +all: all-lib all-doc all-cfgtool # Mostly clean everything. (remove everything but the end results) mostlyclean: mostlyclean-lib mostlyclean-doc mclean: mostlyclean # Clean everything. -clean: clean-lib clean-doc +clean: clean-lib clean-doc clean-cfgtool fclean: clean # Clean everything, and configuration. @@ -28,10 +28,11 @@ mrproper: clean re: clean all # Install everything. -install: install-lib $(if $(INSTALL_MANPAGES),install-doc) +install: install-lib $(if $(INSTALL_MANPAGES),install-doc) \ + $(if $(INSTALL_DEVEL),install-cfgtool) # Uninstall everything. (EXPERIMENTAL) -uninstall: uninstall-lib uninstall-doc +uninstall: uninstall-lib uninstall-doc uninstall-cfgtool # Reinstall everything. (EXPERIMENTAL) reinstall: uninstall install @@ -103,54 +104,86 @@ $(eval $(call make-moduleobj-rule,$(mod)))) # Remove the objects directory. mostlyclean-lib: $(call rmsg,Removing object directory.) - $(call rcmd,$(OBJDIR),$(RM) -r $(OBJDIR)) + $(call qcmd,$(RM) -r $(OBJDIR)) mclean-lib: mostlyclean-lib # Clean and remove the built library. clean-lib: mclean-lib $(call rmsg,Removing the library.) - $(call rcmd,$(SONAMES),$(RM) $(SONAMES)) + $(call qcmd,$(RM) $(SONAMES)) # Remake the library. re-lib: clean-lib all-lib # Install the library, development files and udev rule. -install-lib: $(CHECKCFG) lib$(NAME).so.$(MAJOR) +LINK_TO_MAJOR := $(if $(INSTALL_DEVEL),$(if $(FOR_WINDOWS),,y)) +install-lib: $(CHECKCFG) $(SONAME) $(call imsg,Installing the library.) $(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)") - $(call icmd,lib$(NAME).so.$(MAJOR),\ - $(INST) -m 755 -t "$(ILIBDIR)" lib$(NAME).so.$(MAJOR)) + $(call qcmd,$(INST) -m 755 -t "$(ILIBDIR)" $(SONAME)) - $(if $(INSTALL_DEVEL),\ + $(if $(LINK_TO_MAJOR),\ $(call imsg,Linking lib$(NAME).so to lib$(NAME).so.$(MAJOR).)) - $(if $(INSTALL_DEVEL),\ - $(call qcmd,$(LN) lib$(NAME).so.$(MAJOR) \ - "$(ILIBDIR)/lib$(NAME).so")) + $(if $(LINK_TO_MAJOR),\ + $(call qcmd,$(LN) lib$(NAME).so.$(MAJOR) "$(ILIBDIR)/lib$(NAME).so")) $(if $(INSTALL_DEVEL),\ $(call imsg,Installing development files.)) $(if $(INSTALL_DEVEL),\ $(call qcmd,$(INST) -m 755 -d $(patsubst %,"$(IINCDIR)/%",\ $(sort $(dir $(INCPUB)))))) - $(if $(INSTALL_DEVEL),\ - $(foreach i,$(INCPUB),\ - $(call icmd,$(i).h,\ - $(INST) -m 644 $(INCDIR)/$(i).h "$(IINCDIR)/$(i).h"$(\n)))) + $(if $(INSTALL_DEVEL),$(foreach i,$(INCPUB),\ + $(call qcmd,$(INST) -m 644 $(INCDIR)/$(i).h "$(IINCDIR)/$(i).h"$(\n)))) # Uninstall the library, development files and udev rule. (experimental) uninstall-lib: $(CHECKCFG) $(call rmsg,Uninstalling the library.) - $(call rcmd,lib$(NAME).a) - $(call rcmd,lib$(NAME).so.*) - $(call qcmd,$(RM) "$(ILIBDIR)/lib$(NAME).a" "$(ILIBDIR)/lib$(NAME).so"*) - $(call rcmd,include/lib$(NAME).h) - $(call rcmd,include/lib$(NAME)) + $(call qcmd,$(RM) "$(ILIBDIR)/lib$(NAME).a" \ + "$(ILIBDIR)/lib$(NAME).so"* "$(ILIBDIR)/lib$(NAME).dll") $(call qcmd,$(RM) "$(IINCDIR)/lib$(NAME).h") $(call qcmd,$(RM) -r "$(IINCDIR)/lib$(NAME)") .PHONY: all-lib mostlyclean-lib mclean-lib clean-lib re-lib .PHONY: install-lib uninstall-lib #******************************************************************************# +# Configuration tool-related # +#******************************************************************************# +# Make it all! + all-cfgtool: $(CHECKCFG) $(BINDIR)/lib$(NAME)-config + +# Make the directory. + $(BINDIR): + $(call bcmd,md,$@,$(MD) $@) + +# Build it. + $(BINDIR)/lib$(NAME)-config:| $(BINDIR) + $(call bcmd,writecfg,lib$(NAME),\ + tools/write-config --name=lib$(NAME) --version=$(VERSION) \ + --author-name="$(AUTHOR)" --author-mail="$(AUTHOR_MAIL)" \ + --incdir="$(IINCDIR)" --libdir="$(IBINDIR)" >$@ && chmod 755 $@) + +# Clean it. + clean-cfgtool: + $(call rmsg,Removing configuration tool.) + $(call qcmd,$(RM) -r $(BINDIR)) + +# Remake it. + re-cfgtool: clean-cfgtool all-cfgtool + +# Install it. + install-cfgtool: $(CHECKCFG) all-cfgtool + $(call imsg,Installing the configuration tool.) + $(call qcmd,$(INST) -m 755 -d "$(IBINDIR)") + $(call qcmd,$(INST) -m 755 -t "$(IBINDIR)" $(BINDIR)/lib$(NAME)-config) + +# Uninstall it + uninstall-cfgtool: $(CHECKCFG) + $(call rmsg,Uninstalling configuration tool.) + $(call qcmd,$(RM) "$(IBINDIR)/lib$(NAME)-config" + +.PHONY: all-cfgtool clean-cfgtool re-cfgtool +.PHONY: install-cfgtool uninstall-cfgtool +#******************************************************************************# # Documentation-related # #******************************************************************************# # Make all manpages. @@ -175,7 +208,7 @@ mclean-doc: mostlyclean-doc # Remove all built manpages. clean-doc: $(call rmsg,Removing manpages directory.) - $(call rcmd,$(MANDIR),$(RM) -r $(MANDIR)) + $(call qcmd,$(RM) -r $(MANDIR)) # Remake all manpages. # (I don't really know why some people would want to do that though) @@ -186,7 +219,6 @@ define make-installmansection-rule install-doc-$1: $(MAN_$1:%=$(MANDIR)/man$1/%.$1) $(call imsg,Installing manpages section $1.) $(call qcmd,$(INST) -m 755 -d "$(IMANDIR)/man$1") - $(foreach i,$(MAN_$1),$(call icmd,man$1/$(i).$1)) $(call qcmd,$(INST) -m 644 -t "$(IMANDIR)/man$1" \ $(MAN_$1:%=$(MANDIR)/man$1/%.$1)) $(call qcmd,$(GZIP) $(MAN_$1:%="$(IMANDIR)/man$1/%.$1")) diff --git a/Makefile.vars b/Makefile.vars index a8f2e95..07ba94c 100755 --- a/Makefile.vars +++ b/Makefile.vars @@ -48,12 +48,15 @@ # Manpages directory - where the manpages will be put. MANDIR := ./man +# Executables directory - where the executables will be put. + BINDIR := ./bin + #******************************************************************************# # Object names # #******************************************************************************# # Dynamic library name - SONAME := $(if $(FOR_WINDOWS),lib$(NAME)-$(VERSION).dll,lib$(NAME).so.$(MAJOR)) - SONAMES := $(if $(FOR_WINDOWS),lib$(NAME)-*.dll,lib$(NAME).so.*) + SONAME := $(if $(FOR_WINDOWS),lib$(NAME).dll,lib$(NAME).so.$(MAJOR)) + SONAMES := $(if $(FOR_WINDOWS),lib$(NAME).dll,lib$(NAME).so.*) #******************************************************************************# # Binary utilities # @@ -145,7 +148,7 @@ $(eval $(call check-man,$(patsubst .%,%,$(suffix $(doc))),$(basename $(doc))))) define add-dest-dir $1 = $(DESTDIR)$($1) endef -$(if $(DESTDIR), $(foreach idir,ILIBDIR IINCDIR IMANDIR UDEVDIR, \ +$(if $(DESTDIR), $(foreach idir,IBINDIR ILIBDIR IINCDIR IMANDIR, \ $(eval $(call add-dest-dir,$(idir))))) # END OF FILE diff --git a/configure b/configure index 6ed4b7f..5f4ed27 100755 --- a/configure +++ b/configure @@ -27,6 +27,7 @@ loglevel=none # none, info, warn, error, fatal # Installation directories root='' prefix='${root}/usr' +prefix_set= bindir='${prefix}/bin' libdir='${prefix}/lib'"$platform" includedir='${prefix}/include'"$platform" @@ -53,7 +54,7 @@ General options: Build options: --target=TARGET the target [$target] - --loglevel library log level [$loglevel] + --loglevel=LOGLEVEL library log level [$loglevel] Installation options: --noinstall-manpages should not install manpages @@ -123,7 +124,7 @@ got '$level'" --noinstall-manpages) install_manpages= ;; --noinstall-devel) install_devel= ;; --root=*) root="${arg#*=}" ;; ---prefix=*) prefix="${arg#*=}" ;; +--prefix=*) prefix="${arg#*=}"; prefix_set=y ;; --bindir=*) bindir="${arg#*=}" ;; --libdir=*) libdir="${arg#*=}" ;; --includedir=*) includedir="${arg#*=}" ;; @@ -131,6 +132,14 @@ got '$level'" *) echo "$arg: didn't read" ;; esac; done +#******************************************************************************# +# Check for defaults # +#******************************************************************************# +# MS-Windows things +if [ ! $prefix_set ] && [ $(echo $target | grep mingw) ]; then + prefix='${root}/usr/'"$target" +fi + #******************************************************************************# # Evaluate variables # #******************************************************************************# diff --git a/tools/write-config b/tools/write-config new file mode 100755 index 0000000..aa95e96 --- /dev/null +++ b/tools/write-config @@ -0,0 +1,88 @@ +#!/bin/sh +#******************************************************************************# +# Defaults # +#******************************************************************************# +# Project variables +name="libg1m" +version="" + +# Author +author_name="Unknown name" +author_mail="unknown@mail" + +# Directories +libdir='' +incdir='' + +#******************************************************************************# +# Read arguments # +#******************************************************************************# +for arg ; do case "$arg" in +--name=*) name="${arg#*=}" ;; +--version=*) version="${arg#*=}" ;; +--author-name=*) author_name="${arg#*=}" ;; +--author-mail=*) author_mail="${arg#*=}" ;; +--libdir=*) libdir="${arg#*=}" ;; +--incdir=*) incdir="${arg#*=}" ;; +esac; done + +#******************************************************************************# +# Write result # +#******************************************************************************# +cat <<_EOF +#!/bin/sh +#******************************************************************************# +# Help message # +#******************************************************************************# +usage() { +cat <. +EOF +exit 0 +} + +#******************************************************************************# +# Version message # +#******************************************************************************# +version() { +cat <&2 ;; +esac; done + +# Put +[ \$put_cflags ] && echo "-I$incdir" +[ \$put_libs ] && echo "-L$libdir -lg1m" +[ \$put_cflags\$put_libs ] || usage + +# End of file +_EOF