cake
/
libg1m
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libg1m/Makefile

269 lines
9.6 KiB
Makefile
Raw Normal View History

2016-10-30 20:18:15 +01:00
#!/usr/bin/make -f
#******************************************************************************#
# Include variables and message subsystem #
#******************************************************************************#
2016-12-21 16:39:26 +01:00
include Makefile.vars Makefile.msg
2016-10-30 20:18:15 +01:00
# Check if we're a git repository
ISGIT := $(shell test -e .git && echo y)
2016-10-30 20:18:15 +01:00
#******************************************************************************#
# General targets #
#******************************************************************************#
# Build everything.
all: all-lib all-doc
2016-10-30 20:18:15 +01:00
# Mostly clean everything. (remove everything but the end results)
mostlyclean: mostlyclean-lib mostlyclean-doc
2016-12-21 00:24:30 +01:00
mclean: mostlyclean
2016-10-30 20:18:15 +01:00
# Clean everything.
clean: clean-lib clean-doc
2016-12-21 00:24:30 +01:00
fclean: clean
2016-10-30 20:18:15 +01:00
2016-12-03 16:55:01 +01:00
# Clean everything, and configuration.
mrproper: clean
$(call rmsg,Removing configuration.)
$(call qcmd,$(RM) Makefile.cfg)
$(call qcmd,$(RM) -r lib$(NAME)-*)
2016-12-03 16:55:01 +01:00
2016-10-30 20:18:15 +01:00
# Remake everything. (clean and build)
re: clean all
# Install everything.
2016-12-20 17:29:54 +01:00
install: install-lib $(if $(INSTALL_MANPAGES),install-doc) \
$(if $(INSTALL_DEVEL),install-cfgtool)
2016-10-30 20:18:15 +01:00
# Uninstall everything. (EXPERIMENTAL)
2016-12-20 17:29:54 +01:00
uninstall: uninstall-lib uninstall-doc uninstall-cfgtool
2016-10-30 20:18:15 +01:00
# Reinstall everything. (EXPERIMENTAL)
reinstall: uninstall install
2017-01-04 23:08:47 +01:00
# Make a distribution tarball
dist: mrproper $(if $(ISGIT),reinit-gitmodules)
2017-01-04 23:08:47 +01:00
$(call bcmd,mkdir,lib$(NAME)-$(VERSION),\
$(MD) .dist)
$(call bcmd,cp,* lib$(NAME)-$(VERSION),\
$(CP) -R * .dist)
$(call qcmd,\
$(MV) .dist lib$(NAME)-$(VERSION))
2016-12-27 02:59:36 +01:00
$(call bcmd,tarball,lib$(NAME)-$(VERSION),\
tar czf lib$(NAME)-$(VERSION).tar.gz \
2017-01-04 23:08:47 +01:00
--exclude .git lib$(NAME)-$(VERSION))
$(call qcmd,$(RM) -r lib$(NAME)-$(VERSION))
2016-12-27 02:59:36 +01:00
2016-12-03 16:55:01 +01:00
.PHONY: all mostlyclean mclean clean fclean mrproper re
2016-12-27 02:59:36 +01:00
.PHONY: dist install uninstall reinstall
2016-10-30 20:18:15 +01:00
#******************************************************************************#
# Git submodules management #
#******************************************************************************#
# Main rule.
reinit-gitmodules:
$(call bcmd,Deinitializing git submodules.)
$(call qcmd,git submodule deinit -f --quiet -- \
$(shell grep path .gitmodules | sed 's/.*= //'))
$(call bcmd,Reinitializing git submodules.)
$(call qcmd,git submodule update --init --recursive --quiet)
.PHONY: reinit-gitmodules
#******************************************************************************#
# Checking dependencies #
2016-10-30 20:18:15 +01:00
#******************************************************************************#
# Define the dependencies.
CHECKCFG := $(if $(shell test -f Makefile.cfg || echo y),check-config, \
$(if $(shell [ "$(VERSION)" = "$(CONFIG_VERSION)" ] || echo y), \
check-config-version))
CHECKFC := $(if $(ISGIT),check-gitmodules)
2016-10-30 20:18:15 +01:00
# Configuration checking.
2016-10-30 20:18:15 +01:00
check-config:
@echo -e "\033[1;31mNo configuration file found!"
@echo -e "You should configure before re-running this target.\033[0m"
@false
check-config-version:
@echo -e "\033[1;31mConfiguration version is incorrect!"
@echo -e "You should re-configure before re-running this target.\033[0m"
@false
# Git submodules checking.
check-gitmodules:
$(call bcmd,Checking git modules.)
$(call qcmd,git submodule update --init --recursive)
.PHONY: check-config check-config-version check-gitmodules
2016-10-30 20:18:15 +01:00
#******************************************************************************#
# Information getting from the Makefile variables #
#******************************************************************************#
# Get the project name.
getname:
@echo lib$(NAME)
2016-12-31 11:37:13 +01:00
# Get the project maintainer.
getmaintainer:
@echo "$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>"
2016-10-30 20:18:15 +01:00
# Get the project version.
getversion:
@echo $(VERSION)
2016-12-31 11:37:13 +01:00
.PHONY: getname getmaintainer getversion
2016-10-30 20:18:15 +01:00
#******************************************************************************#
# Library-specific targets #
#******************************************************************************#
# Make the library.
2016-12-21 00:24:30 +01:00
all-lib: $(CHECKCFG) $(SONAME)
2016-10-30 20:18:15 +01:00
2016-11-02 16:32:30 +01:00
# Make a module object directory.
$(MODULES:%=$(OBJDIR)/%):
2016-10-30 20:18:15 +01:00
$(call bcmd,mkdir,$@,$(MD) $@)
2016-11-02 16:32:30 +01:00
# Make a module object out of a module source file.
define make-moduleobj-rule
$(OBJDIR)/$1/%.o: $(SRCDIR)/$1/%.c $(INC:%=$(INCDIR)/%.h) | $(OBJDIR)/$1
2016-11-02 16:32:30 +01:00
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS))
endef
$(foreach mod,$(MODULES), \
$(eval $(call make-moduleobj-rule,$(mod))))
2016-10-30 20:18:15 +01:00
2016-11-02 16:32:30 +01:00
# Make the library (shared).
$(SONAME): \
2016-11-19 12:05:54 +01:00
$(foreach m,$(MODULES),$(SRC_$(m):%=$(OBJDIR)/$(m)/%.o))
2016-10-30 20:18:15 +01:00
$(call bcmd,ld,$@,$(LD) -o $@ $^ $(LDFLAGS))
# Remove the objects directory.
2016-12-21 00:24:30 +01:00
mostlyclean-lib:
2016-11-02 16:32:30 +01:00
$(call rmsg,Removing object directory.)
2016-12-20 17:29:54 +01:00
$(call qcmd,$(RM) -r $(OBJDIR))
2016-12-21 00:24:30 +01:00
mclean-lib: mostlyclean-lib
2016-10-30 20:18:15 +01:00
2016-11-02 16:32:30 +01:00
# Clean and remove the built library.
2016-12-21 00:24:30 +01:00
clean-lib: mclean-lib
2016-11-02 16:32:30 +01:00
$(call rmsg,Removing the library.)
2016-12-20 17:29:54 +01:00
$(call qcmd,$(RM) $(SONAMES))
2016-10-30 20:18:15 +01:00
2016-11-02 16:32:30 +01:00
# Remake the library.
2016-12-21 00:24:30 +01:00
re-lib: clean-lib all-lib
2016-10-30 20:18:15 +01:00
2016-11-02 16:32:30 +01:00
# Install the library, development files and udev rule.
2016-12-21 00:24:30 +01:00
LINK_TO_MAJOR := $(if $(INSTALL_DEVEL),$(if $(FOR_WINDOWS),,y))
install-lib: $(CHECKCFG) $(SONAME)
2016-10-30 20:18:15 +01:00
$(call imsg,Installing the library.)
$(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)")
2016-12-20 17:29:54 +01:00
$(call qcmd,$(INST) -m 755 -t "$(ILIBDIR)" $(SONAME))
$(if $(LINK_TO_MAJOR),\
2016-11-19 12:05:54 +01:00
$(call imsg,Linking lib$(NAME).so to lib$(NAME).so.$(MAJOR).))
2016-12-20 17:29:54 +01:00
$(if $(LINK_TO_MAJOR),\
$(call qcmd,$(LN) lib$(NAME).so.$(MAJOR) "$(ILIBDIR)/lib$(NAME).so"))
2016-10-30 20:18:15 +01:00
$(if $(INSTALL_DEVEL),\
$(call imsg,Installing development files.))
2017-01-04 23:08:47 +01:00
$(if $(INSTALL_DEVEL),$(call qcmd,$(INST) -m 755 -d $(patsubst %,\
"$(IINCDIR)/lib$(NAME)-$(VERSION)/%",$(sort $(dir $(INCPUB))))))
2016-12-20 17:29:54 +01:00
$(if $(INSTALL_DEVEL),$(foreach i,$(INCPUB),\
2017-01-04 23:08:47 +01:00
$(call qcmd,$(INST) -m 644 $(INCDIR)/$(i).h \
"$(IINCDIR)/lib$(NAME)-$(VERSION)/$(i).h"$(\n))))
2016-10-30 20:18:15 +01:00
2016-11-02 16:32:30 +01:00
# Uninstall the library, development files and udev rule. (experimental)
2016-12-21 00:24:30 +01:00
uninstall-lib: $(CHECKCFG)
2016-10-30 20:18:15 +01:00
$(call rmsg,Uninstalling the library.)
2016-12-20 17:29:54 +01:00
$(call qcmd,$(RM) "$(ILIBDIR)/lib$(NAME).a" \
"$(ILIBDIR)/lib$(NAME).so"* "$(ILIBDIR)/lib$(NAME).dll")
2016-10-30 20:18:15 +01:00
$(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
#******************************************************************************#
2016-12-21 16:39:26 +01:00
# Configuration tools-related #
2016-12-20 17:29:54 +01:00
#******************************************************************************#
# Install it.
install-cfgtool: $(CHECKCFG)
2016-12-20 17:29:54 +01:00
$(call imsg,Installing the configuration tool.)
$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)")
2016-12-21 16:39:26 +01:00
$(call qcmd,tools/write-config \
--name=lib$(NAME) --version=$(VERSION) \
2016-12-31 11:37:13 +01:00
--maintainer="$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" \
2017-01-04 23:08:47 +01:00
--incdir="$(OIINCDIR)/lib$(NAME)-$(VERSION)" --libdir="$(OILIBDIR)" \
>"$(IBINDIR)/lib$(NAME)-config" \
&& chmod 755 "$(IBINDIR)/lib$(NAME)-config")
2016-12-20 21:59:26 +01:00
$(call imsg,Installing the pkg-config configuration.)
$(call qcmd,$(INST) -m 755 -d "$(IPKGDIR)")
2016-12-21 16:39:26 +01:00
$(call qcmd,tools/write-pkg-config \
--name=$(NAME) --version=$(VERSION) \
2016-12-20 21:59:26 +01:00
--description="$(DESCRIPTION)" \
2017-01-04 23:08:47 +01:00
--incdir="$(OIINCDIR)/lib$(NAME)-$(VERSION)" --libdir="$(OILIBDIR)" \
2016-12-20 21:59:26 +01:00
>"$(IPKGDIR)/lib$(NAME).pc" \
&& chmod 644 "$(IPKGDIR)/lib$(NAME).pc")
2016-12-20 17:29:54 +01:00
# Uninstall it
uninstall-cfgtool: $(CHECKCFG)
2016-12-21 16:39:26 +01:00
$(call rmsg,Uninstalling configuration tool and package.)
2016-12-20 22:30:30 +01:00
$(call qcmd,$(RM) "$(IBINDIR)/lib$(NAME)-config" "$(IPKGDIR)/lib$(NAME).pc")
2016-12-20 17:29:54 +01:00
.PHONY: install-cfgtool uninstall-cfgtool
#******************************************************************************#
2016-10-30 20:18:15 +01:00
# Documentation-related #
#******************************************************************************#
# Make all manpages.
2016-12-21 00:24:30 +01:00
all-doc: $(foreach s,$(MAN_SECTIONS), $(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s)))
2016-10-30 20:18:15 +01:00
# Make manpages directories.
$(MAN_SECTIONS:%=$(MANDIR)/man%):
$(call bcmd,mkdir,$@,$(MD) $@)
# Make a manpage.
define make-manpage-rule
$(MANDIR)/man$1/%.$1: $(DOCDIR)/%.$1.txt | $(MANDIR)/man$1
$(call bcmd,a2x,$$<,$(A2X) -f manpage -D $$| $$< 2>/dev/null)
endef
$(foreach section, $(MAN_SECTIONS), \
$(eval $(call make-manpage-rule,$(section))))
# Mostly clean (do nothing, really)
2016-12-21 00:24:30 +01:00
mostlyclean-doc:
mclean-doc: mostlyclean-doc
2016-10-30 20:18:15 +01:00
# Remove all built manpages.
2016-12-21 00:24:30 +01:00
clean-doc:
2016-10-30 20:18:15 +01:00
$(call rmsg,Removing manpages directory.)
2016-12-20 17:29:54 +01:00
$(call qcmd,$(RM) -r $(MANDIR))
2016-10-30 20:18:15 +01:00
# Remake all manpages.
# (I don't really know why some people would want to do that though)
2016-12-21 00:24:30 +01:00
re-doc: clean-doc all-doc
2016-10-30 20:18:15 +01:00
# Install a manpages section.
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")
$(call qcmd,$(INST) -m 644 -t "$(IMANDIR)/man$1" \
$(MAN_$1:%=$(MANDIR)/man$1/%.$1))
$(call qcmd,$(GZIP) $(MAN_$1:%="$(IMANDIR)/man$1/%.$1"))
endef
$(foreach section, $(MAN_SECTIONS), \
$(eval $(call make-installmansection-rule,$(section))))
# Install manpages.
2016-12-21 00:24:30 +01:00
install-doc: $(CHECKCFG) $(MAN_SECTIONS:%=install-doc-%)
2016-10-30 20:18:15 +01:00
# Clean a manpages section.
define make-uninstall-doc-rule
uninstall-doc-$1:
$(call rmsg,Uninstalling manpages section $1.)
$(call rcmd,man$1/lib$(NAME).$1)
$(call rcmd,man$1/$(NAME)_*.$1)
$(call qcmd,$(RM) "$(IMANDIR)/man$1/lib$(NAME).$1"* \
"$(IMANDIR)/man$1/$(NAME)_"*".$1"*)
endef
$(foreach sec,$(MAN_SECTIONS), \
$(eval $(call make-uninstall-doc-rule,$(sec))))
# Uninstall manpages
2016-12-21 00:24:30 +01:00
uninstall-doc: $(CHECKCFG) $(MAN_SECTIONS:%=uninstall-doc-%)
2016-10-30 20:18:15 +01:00
.PHONY: all-doc mostlyclean-doc mclean-doc clean-doc re-doc
.PHONY: install-doc uninstall-doc
.PHONY: $(foreach s,$(MAN_SECTIONS),install-doc-$(s) uninstall-doc-$(s))
# End of file.