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

251 lines
8.3 KiB
Makefile
Raw Normal View History

2016-10-30 20:18:15 +01:00
#!/usr/bin/make -f
#******************************************************************************#
# Include variables and message subsystem #
#******************************************************************************#
include Makefile.vars
include Makefile.msg
#******************************************************************************#
# General targets #
#******************************************************************************#
# Build everything.
2016-12-20 17:29:54 +01:00
all: all-lib all-doc all-cfgtool
2016-10-30 20:18:15 +01:00
# Mostly clean everything. (remove everything but the end results)
mostlyclean: mostlyclean-lib mostlyclean-doc
mclean: mostlyclean
# Clean everything.
2016-12-20 17:29:54 +01:00
clean: clean-lib clean-doc clean-cfgtool
2016-10-30 20:18:15 +01:00
fclean: clean
2016-12-03 16:55:01 +01:00
# Clean everything, and configuration.
mrproper: clean
$(call rmsg,Removing configuration.)
$(call qcmd,$(RM) Makefile.cfg)
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
2016-12-03 16:55:01 +01:00
.PHONY: all mostlyclean mclean clean fclean mrproper re
.PHONY: install uninstall reinstall
2016-10-30 20:18:15 +01:00
#******************************************************************************#
# 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)
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.
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-10-30 20:18:15 +01:00
mclean-lib: mostlyclean-lib
2016-11-02 16:32:30 +01:00
# Clean and remove the built library.
2016-10-30 20:18:15 +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-10-30 20:18:15 +01:00
re-lib: clean-lib all-lib
2016-11-02 16:32:30 +01:00
# Install the library, development files and udev rule.
2016-12-20 17:29:54 +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))
2016-10-30 20:18:15 +01:00
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"))
2016-10-30 20:18:15 +01:00
$(if $(INSTALL_DEVEL),\
$(call imsg,Installing development files.))
$(if $(INSTALL_DEVEL),\
$(call qcmd,$(INST) -m 755 -d $(patsubst %,"$(IINCDIR)/%",\
$(sort $(dir $(INCPUB))))))
2016-12-20 17:29:54 +01:00
$(if $(INSTALL_DEVEL),$(foreach i,$(INCPUB),\
$(call qcmd,$(INST) -m 644 $(INCDIR)/$(i).h "$(IINCDIR)/$(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-10-30 20:18:15 +01:00
uninstall-lib: $(CHECKCFG)
$(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-20 17:29:54 +01:00
# 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
#******************************************************************************#
2016-10-30 20:18:15 +01:00
# 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.)
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)
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.