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

240 lines
8.3 KiB
Makefile
Executable File

#!/usr/bin/make -f
#******************************************************************************#
# Include variables and message subsystem #
#******************************************************************************#
include Makefile.vars
include Makefile.msg
#******************************************************************************#
# General targets #
#******************************************************************************#
# Build everything.
all: all-lib all-doc
# Mostly clean everything. (remove everything but the end results)
mostlyclean: mostlyclean-lib mostlyclean-doc
mclean: mostlyclean
# Clean everything.
clean: clean-lib clean-doc
fclean: clean
# Clean everything, and configuration.
mrproper: clean
$(call rmsg,Removing configuration.)
$(call qcmd,$(RM) Makefile.cfg)
# Remake everything. (clean and build)
re: clean all
# Install everything.
install: install-lib $(if $(INSTALL_MANPAGES),install-doc) \
$(if $(INSTALL_DEVEL),install-cfgtool)
# Uninstall everything. (EXPERIMENTAL)
uninstall: uninstall-lib uninstall-doc uninstall-cfgtool
# Reinstall everything. (EXPERIMENTAL)
reinstall: uninstall install
.PHONY: all mostlyclean mclean clean fclean mrproper re
.PHONY: install uninstall reinstall
#******************************************************************************#
# Configuration (version) checking dependencies #
#******************************************************************************#
# Define the dependencies.
CHECKCFG := $(if $(shell test -f Makefile.cfg || echo y),check-config, \
$(if $(shell [ "$(VERSION)" = "$(CONFIG_VERSION)" ] || echo y), \
check-config-version))
# Define the rules.
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
.PHONY: check-config check-config-version
#******************************************************************************#
# Information getting from the Makefile variables #
#******************************************************************************#
# Get the project name.
getname:
@echo lib$(NAME)
# Get the project author.
getauthor:
@echo $(AUTHOR)
# Get the project author email.
getmail:
@echo $(AUTHOR_MAIL)
# Get the project version.
getversion:
@echo $(VERSION)
.PHONY: getname getauthor getmail getversion
#******************************************************************************#
# Library-specific targets #
#******************************************************************************#
# Make the library.
all-lib: $(CHECKCFG) $(SONAME)
# Make a module object directory.
$(MODULES:%=$(OBJDIR)/%):
$(call bcmd,mkdir,$@,$(MD) $@)
# 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
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS))
endef
$(foreach mod,$(MODULES), \
$(eval $(call make-moduleobj-rule,$(mod))))
# Make the library (shared).
$(SONAME): \
$(foreach m,$(MODULES),$(SRC_$(m):%=$(OBJDIR)/$(m)/%.o))
$(call bcmd,ld,$@,$(LD) -o $@ $^ $(LDFLAGS))
# Remove the objects directory.
mostlyclean-lib:
$(call rmsg,Removing object directory.)
$(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 qcmd,$(RM) $(SONAMES))
# Remake the library.
re-lib: clean-lib all-lib
# Install the library, development files and udev rule.
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 qcmd,$(INST) -m 755 -t "$(ILIBDIR)" $(SONAME))
$(if $(LINK_TO_MAJOR),\
$(call imsg,Linking lib$(NAME).so to lib$(NAME).so.$(MAJOR).))
$(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 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 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 #
#******************************************************************************#
# Install it.
install-cfgtool: $(CHECKCFG)
$(call imsg,Installing the configuration tool.)
$(call qcmd,$(INST) -m 755 -d "$(IBINDIR)")
$(call qcmd,tools/write-config --name=lib$(NAME) --version=$(VERSION) \
--author-name="$(AUTHOR)" --author-mail="$(AUTHOR_MAIL)" \
--incdir="$(IINCDIR)" --libdir="$(IBINDIR)" \
>"$(IBINDIR)/lib$(NAME)-config" \
&& chmod 755 "$(IBINDIR)/lib$(NAME)-config")
$(call imsg,Installing the pkg-config configuration.)
$(call qcmd,$(INST) -m 755 -d "$(IPKGDIR)")
$(call qcmd,tools/write-pkg-config --name=$(NAME) --version=$(VERSION) \
--description="$(DESCRIPTION)" \
--incdir="$(OIINCDIR)" --libdir="$(OILIBDIR)" \
>"$(IPKGDIR)/lib$(NAME).pc" \
&& chmod 644 "$(IPKGDIR)/lib$(NAME).pc")
# Uninstall it
uninstall-cfgtool: $(CHECKCFG)
$(call rmsg,Uninstalling configuration tool.)
$(call qcmd,$(RM) "$(IBINDIR)/lib$(NAME)-config" "$(IPKGDIR)/lib$(NAME).pc")
.PHONY: install-cfgtool uninstall-cfgtool
#******************************************************************************#
# Documentation-related #
#******************************************************************************#
# Make all manpages.
all-doc: $(foreach s,$(MAN_SECTIONS), $(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s)))
# 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)
mostlyclean-doc:
mclean-doc: mostlyclean-doc
# Remove all built manpages.
clean-doc:
$(call rmsg,Removing manpages directory.)
$(call qcmd,$(RM) -r $(MANDIR))
# Remake all manpages.
# (I don't really know why some people would want to do that though)
re-doc: clean-doc all-doc
# 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.
install-doc: $(CHECKCFG) $(MAN_SECTIONS:%=install-doc-%)
# 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
uninstall-doc: $(CHECKCFG) $(MAN_SECTIONS:%=uninstall-doc-%)
.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.