2016-10-27 14:36:24 +02:00
|
|
|
#!/usr/bin/make -f
|
2016-10-28 14:27:03 +02:00
|
|
|
#******************************************************************************#
|
|
|
|
# Include variables and message subsystem #
|
|
|
|
#******************************************************************************#
|
2016-08-16 21:33:44 +02:00
|
|
|
include Makefile.vars
|
2016-10-28 13:29:17 +02:00
|
|
|
include Makefile.msg
|
2016-08-16 21:33:44 +02:00
|
|
|
|
2016-10-28 14:31:37 +02:00
|
|
|
#******************************************************************************#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Remake everything (clean and build).
|
|
|
|
re: clean all
|
|
|
|
|
|
|
|
# Install everything.
|
|
|
|
install: install-lib $(if $(INSTALL_MANPAGES),install-doc)
|
|
|
|
|
|
|
|
# Uninstall everything. (experimental)
|
|
|
|
uninstall: uninstall-lib uninstall-doc
|
|
|
|
|
|
|
|
# Reinstall everything. (experimental)
|
|
|
|
reinstall: uninstall install
|
|
|
|
|
|
|
|
.PHONY: all mostlyclean mclean clean fclean re install uninstall reinstall
|
2016-10-28 14:27:03 +02:00
|
|
|
#******************************************************************************#
|
|
|
|
# Configuration (version) checking dependencies #
|
|
|
|
#******************************************************************************#
|
|
|
|
# Define the dependencies.
|
2016-09-28 14:40:39 +02:00
|
|
|
CHECKCFG := $(if $(shell test -f Makefile.cfg || echo y),check-config, \
|
|
|
|
$(if $(shell [ "$(VERSION)" = "$(CONFIG_VERSION)" ] || echo y), \
|
|
|
|
check-config-version))
|
2016-10-27 15:12:00 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# 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
|
2016-08-16 21:33:44 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
.PHONY: check-config check-config-version
|
|
|
|
#******************************************************************************#
|
|
|
|
# Information getting from the Makefile variables #
|
|
|
|
#******************************************************************************#
|
|
|
|
# Get the project name.
|
2016-09-28 14:40:39 +02:00
|
|
|
getname:
|
|
|
|
@echo lib$(NAME)
|
2016-10-28 14:27:03 +02:00
|
|
|
|
|
|
|
# Get the project author.
|
2016-10-12 12:55:34 +02:00
|
|
|
getauthor:
|
|
|
|
@echo $(AUTHOR)
|
2016-10-28 14:27:03 +02:00
|
|
|
|
|
|
|
# Get the project author email.
|
2016-10-12 12:55:34 +02:00
|
|
|
getmail:
|
|
|
|
@echo $(AUTHOR_MAIL)
|
2016-10-28 14:27:03 +02:00
|
|
|
|
|
|
|
# Get the project version.
|
2016-09-28 14:40:39 +02:00
|
|
|
getversion:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
.PHONY: getname getauthor getmail getversion
|
|
|
|
#******************************************************************************#
|
|
|
|
# Display help #
|
|
|
|
#******************************************************************************#
|
|
|
|
# Main rule.
|
2016-10-27 22:44:59 +02:00
|
|
|
help:
|
|
|
|
@echo -e "=================== \033[1mlibp7 - Makefile Howto\033[0m =========================="
|
|
|
|
@echo -e "========= \033[1mall\033[0m[-{section}]: make everything in the section. =========="
|
|
|
|
@echo -e "======= \033[1mclean\033[0m[-{section}]: clean everything in the section. ========="
|
|
|
|
@echo -e "===== \033[1minstall\033[0m[-{section}]: install everything from the section. ====="
|
|
|
|
@echo -e "=== \033[1muninstall\033[0m[-{section}]: uninstall everything from the section. ==="
|
|
|
|
@echo -e "====================================================================="
|
|
|
|
@echo -e "================ Available sections are: \033[1mlib\033[0m, \033[1mdoc\033[0m. =================="
|
|
|
|
halp: help
|
|
|
|
usage: help
|
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
.PHONY: help halp usage
|
|
|
|
#******************************************************************************#
|
|
|
|
# Library-specific targets #
|
|
|
|
#******************************************************************************#
|
|
|
|
# Make the library.
|
2016-09-15 09:38:17 +02:00
|
|
|
all-lib: $(CHECKCFG) lib$(NAME).so
|
2016-09-12 14:38:35 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Make a module object directory.
|
2016-10-03 21:07:10 +02:00
|
|
|
$(MODULES:%=$(OBJDIR)/%):
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call bcmd,mkdir,$@,$(MD) $@)
|
2016-08-16 21:33:44 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Make a module object out of a module source file.
|
2016-08-17 15:47:32 +02:00
|
|
|
define make-moduleobj-rule
|
2016-10-28 14:27:03 +02:00
|
|
|
$(OBJDIR)/$1/%.o: $(SRCDIR)/$1/%.c | $(OBJDIR)/$1
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS))
|
2016-08-17 15:47:32 +02:00
|
|
|
endef
|
|
|
|
$(foreach mod,$(MODULES), \
|
|
|
|
$(eval $(call make-moduleobj-rule,$(mod))))
|
2016-08-16 21:33:44 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Make the library (shared).
|
|
|
|
lib$(NAME).so: $(foreach m,$(MODULES),$(SRC_$(m):%=$(OBJDIR)/$(m)/%.o))
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call bcmd,ld,$@,$(LD) -o $@ $^ $(LDFLAGS))
|
2016-08-16 21:33:44 +02:00
|
|
|
|
2016-11-16 01:04:19 +01:00
|
|
|
# Remove the objects directory.
|
2016-10-28 14:27:03 +02:00
|
|
|
mostlyclean-lib:
|
2016-10-27 16:06:26 +02:00
|
|
|
$(call rmsg,Removing object directory.)
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call rcmd,$(OBJDIR),$(RM) -r $(OBJDIR))
|
2016-10-28 14:27:03 +02:00
|
|
|
mclean-lib: mostlyclean-lib
|
2016-08-16 21:33:44 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Clean and remove the built library.
|
2016-09-15 10:27:38 +02:00
|
|
|
clean-lib: mclean-lib
|
2016-10-27 14:36:24 +02:00
|
|
|
$(call rmsg,Removing the library.)
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call rcmd,lib$(NAME).so,$(RM) lib$(NAME).so)
|
2016-08-16 21:33:44 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Remake the library.
|
2016-09-15 10:27:38 +02:00
|
|
|
re-lib: clean-lib all-lib
|
2016-08-16 21:33:44 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Install the library, development files and udev rule.
|
2016-10-27 16:06:26 +02:00
|
|
|
install-lib: $(CHECKCFG) lib$(NAME).so
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call imsg,Installing the library.)
|
2016-10-27 15:12:00 +02:00
|
|
|
$(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)")
|
2016-10-27 16:06:26 +02:00
|
|
|
$(call icmd,lib$(NAME).so.$(VERSION_MAJOR),\
|
2016-10-28 13:07:12 +02:00
|
|
|
$(INST) -m 755 lib$(NAME).so "$(ILIBDIR)/lib$(NAME).so.$(VERSION_MAJOR)")
|
2016-10-27 15:12:00 +02:00
|
|
|
|
2016-10-12 12:55:34 +02:00
|
|
|
$(if $(INSTALL_DEVEL),\
|
2016-10-28 14:27:03 +02:00
|
|
|
$(call imsg,Linking lib$(NAME).so to lib$(NAME).so.$(VERSION_MAJOR).))
|
2016-10-27 14:36:24 +02:00
|
|
|
$(if $(INSTALL_DEVEL),\
|
2016-10-27 15:12:00 +02:00
|
|
|
$(call qcmd,$(LN) lib$(NAME).so.$(VERSION_MAJOR) \
|
|
|
|
"$(ILIBDIR)/lib$(NAME).so"))
|
2016-10-27 17:07:24 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
$(if $(INSTALL_DEVEL),\
|
|
|
|
$(call imsg,Installing development files.))
|
2016-10-27 14:36:24 +02:00
|
|
|
$(if $(INSTALL_DEVEL),\
|
2016-10-27 17:07:24 +02:00
|
|
|
$(call qcmd,$(INST) -m 755 -d $(patsubst %,"$(IINCDIR)/%",\
|
|
|
|
$(sort $(dir $(INCPUB))))))
|
2016-10-27 14:36:24 +02:00
|
|
|
$(if $(INSTALL_DEVEL),\
|
2016-10-27 17:07:24 +02:00
|
|
|
$(foreach i,$(INCPUB),\
|
|
|
|
$(call icmd,$(i).h,\
|
|
|
|
$(INST) -m 644 $(INCDIR)/$(i).h "$(IINCDIR)/$(i).h"$(\n))))
|
2016-10-27 15:12:00 +02:00
|
|
|
|
2016-10-27 14:36:24 +02:00
|
|
|
$(if $(INSTALL_UDEV_RULE),\
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call imsg,Installing the udev rule.))
|
2016-10-27 14:36:24 +02:00
|
|
|
$(if $(INSTALL_UDEV_RULE),\
|
2016-10-27 15:12:00 +02:00
|
|
|
$(call qcmd,$(INST) -m 755 -d "$(UDEVDIR)"))
|
2016-10-12 12:55:34 +02:00
|
|
|
$(if $(INSTALL_UDEV_RULE),\
|
2016-10-27 16:06:26 +02:00
|
|
|
$(call icmd,60-casio-usb.rules,\
|
|
|
|
$(INST) -m 644 udev.rules "$(UDEVDIR)/60-casio-usb.rules"))
|
2016-08-21 14:30:52 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Uninstall the library, development files and udev rule. (experimental)
|
2016-09-15 09:38:17 +02:00
|
|
|
uninstall-lib: $(CHECKCFG)
|
2016-10-27 14:36:24 +02:00
|
|
|
$(call rmsg,Uninstalling the library.)
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call rcmd,lib$(NAME).a)
|
|
|
|
$(call rcmd,lib$(NAME).so.*)
|
2016-10-27 15:12:00 +02:00
|
|
|
$(call qcmd,$(RM) "$(ILIBDIR)/lib$(NAME).a" "$(ILIBDIR)/lib$(NAME).so"*)
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call rcmd,include/lib$(NAME).h)
|
|
|
|
$(call rcmd,include/lib$(NAME))
|
2016-10-27 15:12:00 +02:00
|
|
|
$(call qcmd,$(RM) "$(IINCDIR)/lib$(NAME).h")
|
|
|
|
$(call qcmd,$(RM) -r "$(IINCDIR)/lib$(NAME)")
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call rcmd,60-casio-usb.rules,\
|
2016-10-27 16:06:26 +02:00
|
|
|
$(RM) "$(UDEVDIR)/60-casio-usb.rules")
|
2016-09-04 13:06:40 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
.PHONY: all-lib mostlyclean-lib mclean-lib clean-lib re-lib
|
|
|
|
.PHONY: install-lib uninstall-lib
|
|
|
|
#******************************************************************************#
|
|
|
|
# Documentation-related #
|
|
|
|
#******************************************************************************#
|
|
|
|
# Make all manpages.
|
2016-10-27 16:06:26 +02:00
|
|
|
all-doc: $(foreach s,$(MAN_SECTIONS), $(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s)))
|
2016-09-12 14:38:35 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Make manpages directories.
|
2016-10-03 21:07:10 +02:00
|
|
|
$(MAN_SECTIONS:%=$(MANDIR)/man%):
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call bcmd,mkdir,$@,$(MD) $@)
|
2016-08-21 14:30:52 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Make a manpage.
|
2016-08-21 14:30:52 +02:00
|
|
|
define make-manpage-rule
|
2016-10-27 14:36:24 +02:00
|
|
|
$(MANDIR)/man$1/%.$1: $(DOCDIR)/%.$1.txt | $(MANDIR)/man$1
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call bcmd,a2x,$$<,$(A2X) -f manpage -D $$| $$< 2>/dev/null)
|
2016-08-21 14:30:52 +02:00
|
|
|
endef
|
|
|
|
$(foreach section, $(MAN_SECTIONS), \
|
|
|
|
$(eval $(call make-manpage-rule,$(section))))
|
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Mostly clean (do nothing, really)
|
|
|
|
mostlyclean-doc:
|
|
|
|
mclean-doc: mostlyclean-doc
|
|
|
|
|
|
|
|
# Remove all built manpages.
|
2016-08-21 14:30:52 +02:00
|
|
|
clean-doc:
|
2016-10-27 16:06:26 +02:00
|
|
|
$(call rmsg,Removing manpages directory.)
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call rcmd,$(MANDIR),$(RM) -r $(MANDIR))
|
2016-08-21 14:30:52 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Remake all manpages.
|
|
|
|
# (I don't really know why some people would want to do that though)
|
2016-09-15 10:27:38 +02:00
|
|
|
re-doc: clean-doc all-doc
|
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Install a manpages section.
|
2016-10-27 14:36:24 +02:00
|
|
|
define make-installmansection-rule
|
|
|
|
install-doc-$1: $(MAN_$1:%=$(MANDIR)/man$1/%.$1)
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call imsg,Installing manpages section $1.)
|
2016-10-27 15:12:00 +02:00
|
|
|
$(call qcmd,$(INST) -m 755 -d "$(IMANDIR)/man$1")
|
2016-10-27 16:06:26 +02:00
|
|
|
$(foreach i,$(MAN_$1),$(call icmd,man$1/$(i).$1))
|
2016-10-27 15:12:00 +02:00
|
|
|
$(call qcmd,$(INST) -m 644 -t "$(IMANDIR)/man$1" \
|
|
|
|
$(MAN_$1:%=$(MANDIR)/man$1/%.$1))
|
|
|
|
$(call qcmd,$(GZIP) $(MAN_$1:%="$(IMANDIR)/man$1/%.$1"))
|
2016-08-21 14:30:52 +02:00
|
|
|
endef
|
|
|
|
$(foreach section, $(MAN_SECTIONS), \
|
2016-10-27 14:36:24 +02:00
|
|
|
$(eval $(call make-installmansection-rule,$(section))))
|
2016-08-21 14:30:52 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Install manpages.
|
|
|
|
install-doc: $(CHECKCFG) $(MAN_SECTIONS:%=install-doc-%)
|
2016-09-12 14:38:35 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Clean a manpages section.
|
2016-09-25 22:01:42 +02:00
|
|
|
define make-uninstall-doc-rule
|
|
|
|
uninstall-doc-$1:
|
2016-10-27 14:36:24 +02:00
|
|
|
$(call rmsg,Uninstalling manpages section $1.)
|
2016-10-28 13:29:17 +02:00
|
|
|
$(call rcmd,man$1/lib$(NAME).$1)
|
|
|
|
$(call rcmd,man$1/$(NAME)_*.$1)
|
2016-10-27 17:22:30 +02:00
|
|
|
$(call qcmd,$(RM) "$(IMANDIR)/man$1/lib$(NAME).$1"* \
|
|
|
|
"$(IMANDIR)/man$1/$(NAME)_"*".$1"*)
|
2016-09-25 22:01:42 +02:00
|
|
|
endef
|
|
|
|
$(foreach sec,$(MAN_SECTIONS), \
|
|
|
|
$(eval $(call make-uninstall-doc-rule,$(sec))))
|
2016-09-12 14:38:35 +02:00
|
|
|
|
2016-10-28 14:27:03 +02:00
|
|
|
# Uninstall manpages
|
2016-09-15 09:38:17 +02:00
|
|
|
uninstall-doc: $(CHECKCFG) $(MAN_SECTIONS:%=uninstall-doc-%)
|
2016-09-12 14:38:35 +02:00
|
|
|
|
2016-10-28 14:27:03 +02: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))
|
|
|
|
#******************************************************************************#
|
|
|
|
# Packaging #
|
|
|
|
#******************************************************************************#
|
|
|
|
# Package for debian.
|
2016-09-12 17:25:30 +02:00
|
|
|
deb:
|
|
|
|
debuild --no-tgz-check -us -uc
|
|
|
|
|
2016-09-12 19:59:14 +02:00
|
|
|
.PHONY: deb
|
2016-10-28 14:27:03 +02:00
|
|
|
# End of file
|