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

267 lines
9.4 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
#******************************************************************************#
# General targets #
#******************************************************************************#
# Build everything.
2017-01-27 21:49:04 +01:00
all: all-lib $(if $(INSTALL_MANPAGES),all-doc)
2016-10-30 20:18:15 +01:00
2017-01-27 21:49:04 +01:00
# Mostly clean everything (remove everything but the end results).
2016-10-30 20:18:15 +01:00
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
2017-01-27 21:49:04 +01:00
# To original state.
2016-12-03 16:55:01 +01:00
mrproper: clean
$(call rmsg,Removing configuration.)
$(call qcmd,$(RM) Makefile.cfg)
$(call qcmd,$(RM) -r lib$(NAME)-*)
2017-01-27 21:49:04 +01:00
$(call qcmd,$(RM) $(INCDIR)/lib$(NAME)/config.h)
2016-12-03 16:55:01 +01:00
2017-01-27 21:49:04 +01:00
# Remake everything (clean and build).
2016-10-30 20:18:15 +01:00
re: clean all
# Install everything.
2017-01-27 21:49:04 +01:00
install: install-lib $(if $(INSTALL_MANPAGES),install-doc)
2016-10-30 20:18:15 +01:00
2017-01-27 21:49:04 +01:00
# Uninstall everything. (experimental)
uninstall: uninstall-lib uninstall-doc
2016-10-30 20:18:15 +01:00
2017-01-27 21:49:04 +01:00
# Reinstall everything. (experimental)
2016-10-30 20:18:15 +01:00
reinstall: uninstall install
2017-01-04 23:08:47 +01:00
# Make a distribution tarball
2017-01-27 21:49:04 +01:00
dist: mrproper
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
#******************************************************************************#
2017-01-27 21:49:04 +01:00
# Configuration (version) 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))
2017-01-27 21:49:04 +01:00
# Define the rules.
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
2017-01-27 21:49:04 +01:00
.PHONY: check-config check-config-version
2016-10-30 20:18:15 +01:00
#******************************************************************************#
# Information getting from the Makefile variables #
#******************************************************************************#
# Get the project name.
getname:
@echo lib$(NAME)
# Get the project version.
getversion:
@echo $(VERSION)
2017-01-27 21:49:04 +01:00
# Get the maintainer.
getmaintainer:
@echo "$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>"
.PHONY: getname getauthor getmail getversion
2016-10-30 20:18:15 +01:00
#******************************************************************************#
# Library-specific targets #
#******************************************************************************#
# Make the library.
2017-01-27 21:49:04 +01:00
all-lib: $(CHECKCFG) $(if $(STATIC),$(ANAME),$(SONAME))
2016-10-30 20:18:15 +01:00
2016-11-02 16:32:30 +01:00
# Make a module object directory.
2017-02-28 15:01:21 +01:00
$(OBJDIR)/ $(DIRS:%=$(OBJDIR)/%):
2016-10-30 20:18:15 +01:00
$(call bcmd,mkdir,$@,$(MD) $@)
2017-02-28 15:01:21 +01:00
# Make an object out of a source file.
define make-obj-rule
$(OBJDIR)/$1.o: $(SRCDIR)/$1.c $(INC) | $(dir $(OBJDIR)/$1)
2016-11-02 16:32:30 +01:00
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS))
endef
2017-02-28 15:01:21 +01:00
$(foreach src,$(SRC),\
$(eval $(call make-obj-rule,$(src))))
2016-10-30 20:18:15 +01:00
2017-01-27 21:49:04 +01:00
# Make the shared library.
2017-02-28 15:01:21 +01:00
$(SONAME): $(SRC:%=$(OBJDIR)/%.o)
2016-10-30 20:18:15 +01:00
$(call bcmd,ld,$@,$(LD) -o $@ $^ $(LDFLAGS))
2017-01-27 21:49:04 +01:00
# Make the static library.
2017-02-28 15:01:21 +01:00
lib$(NAME).a: $(SRC:%=$(OBJDIR)/%.o)
2017-01-27 21:49:04 +01:00
$(call bcmd,ar rc,$@,$(AR) rcs $@ $^)
2016-10-30 20:18:15 +01:00
# 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.)
2017-01-27 21:49:04 +01:00
$(call qcmd,$(RM) $(SONAMES) $(ANAMES))
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
2017-01-27 21:49:04 +01:00
# Install the library and development files.
LINK_TO_MAJOR := $(if $(INSTALL_DEVEL),$(if $(STATIC),,$(if $(FOR_WINDOWS),,y)))
IWINDLL := $(if $(FOR_WINDOWS),$(if $(STATIC),,y))
install-lib: all-lib $(if $(INSTALL_DEVEL),install-cfgtool)
2016-10-30 20:18:15 +01:00
$(call imsg,Installing the library.)
$(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)")
2017-01-27 21:49:04 +01:00
$(call qcmd,$(INST) -m 755 -t "$(ILIBDIR)" $(if $(STATIC),\
$(if $(FOR_WINDOWS),lib$(NAME).lib,lib$(NAME).a),\
$(if $(FOR_WINDOWS),lib$(NAME).dll.a,$(SONAME))))
$(if $(IWINDLL),$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)"))
2017-02-28 15:01:21 +01:00
$(if $(IWINDLL),$(call qcmd,$(INST) -m 755 -t "$(IBINDIR)" \
2017-01-27 21:49:04 +01:00
lib$(NAME).dll))
2016-12-20 17:29:54 +01:00
$(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"))
2017-01-27 21:49:04 +01:00
2016-10-30 20:18:15 +01:00
$(if $(INSTALL_DEVEL),\
$(call imsg,Installing development files.))
2017-01-27 21:49:04 +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-27 21:49:04 +01:00
$(call qcmd,$(INST) -m 644 $(INCDIR)/$(i) \
"$(IINCDIR)/lib$(NAME)-$(VERSION)/$(i)"$(\n))))
2016-10-30 20:18:15 +01:00
2017-01-27 21:49:04 +01:00
# Uninstall the library and development files. (experimental)
uninstall-lib: $(CHECKCFG) uninstall-cfgtool
2016-10-30 20:18:15 +01:00
$(call rmsg,Uninstalling the library.)
2017-01-27 21:49:04 +01:00
$(call qcmd,$(RM) "$(IBINDIR)/lib$(NAME).dll")
$(call qcmd,$(RM) "$(ILIBDIR)/lib$(NAME).so"* \
"$(ILIBDIR)/lib$(NAME).a" "$(ILIBDIR)/lib$(NAME).dll"*)
$(call rmsg,Uninstalling development files.)
$(call qcmd,$(RM) -r "$(IINCDIR)/lib$(NAME)-$(VERSION)")
2016-10-30 20:18:15 +01:00
$(call qcmd,$(RM) "$(IINCDIR)/lib$(NAME).h")
$(call qcmd,$(RM) -r "$(IINCDIR)/lib$(NAME)")
2017-02-28 15:01:21 +01:00
# Reinstall the library and development files.
reinstall-lib: uninstall-lib install-lib
2016-10-30 20:18:15 +01:00
.PHONY: all-lib mostlyclean-lib mclean-lib clean-lib re-lib
2017-02-28 15:01:21 +01:00
.PHONY: install-lib uninstall-lib reinstall-lib
2016-10-30 20:18:15 +01:00
#******************************************************************************#
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 \
2017-02-20 00:00:16 +01:00
--name=$(NAME) --version=$(VERSION) --target="$(TARGET)" \
2016-12-31 11:37:13 +01:00
--maintainer="$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" \
>"$(IBINDIR)/$(TARGET)lib$(NAME)-config" \
&& chmod 755 "$(IBINDIR)/$(TARGET)lib$(NAME)-config")
2017-01-27 21:49:04 +01:00
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) \
--deps="$(DEPS)" --deps.private="$(DEPS_PRIV)" \
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 qcmd,$(RM) "$(IMANDIR)/man$1/lib$(NAME).$1"* \
2017-01-27 21:49:04 +01:00
"$(IMANDIR)/man$1/$(NAME)_"*".$1"* \
"$(IMANDIR)/man$1/lib$(NAME)-config.$1"*)
2016-10-30 20:18:15 +01:00
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))
2017-01-27 21:49:04 +01:00
# End of file