cake
/
libp7
Archived
1
0
Fork 1
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.
libp7/Makefile

217 lines
7.2 KiB
Makefile
Raw Normal View History

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
include Makefile.msg
2016-08-16 21:33:44 +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
2016-12-18 12:09:32 +01:00
# To original state.
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)
# Uninstall everything. (experimental)
uninstall: uninstall-lib uninstall-doc
# Reinstall everything. (experimental)
reinstall: uninstall install
2016-12-18 12:09:32 +01:00
.PHONY: all mostlyclean mclean clean fclean mrproper re
.PHONY: 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
#******************************************************************************#
# Library-specific targets #
#******************************************************************************#
# Make the library.
2016-11-22 15:32:25 +01:00
all-lib: $(CHECKCFG) lib$(NAME).so.$(MAJOR)
2016-10-28 14:27:03 +02:00
# Make a module object directory.
$(MODULES:%=$(OBJDIR)/%):
$(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
$(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).
2016-11-22 15:32:25 +01:00
lib$(NAME).so.$(MAJOR): $(foreach m,$(MODULES),$(SRC_$(m):%=$(OBJDIR)/$(m)/%.o))
$(call bcmd,ld,$@,$(LD) -o $@ $^ $(LDFLAGS))
2016-08-16 21:33:44 +02:00
# Remove the objects directory.
2016-10-28 14:27:03 +02:00
mostlyclean-lib:
$(call rmsg,Removing object directory.)
2016-12-18 12:09:32 +01:00
$(call qcmd,$(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-12-18 12:09:32 +01:00
$(call qcmd,$(RM) lib$(NAME).so.$(MAJOR))
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-11-16 02:27:16 +01:00
# Install the library and development files.
2016-11-22 15:32:25 +01:00
install-lib: $(CHECKCFG) lib$(NAME).so.$(MAJOR)
$(call imsg,Installing the library.)
2016-10-27 15:12:00 +02:00
$(call qcmd,$(INST) -m 755 -d "$(ILIBDIR)")
2016-12-18 12:09:32 +01:00
$(call qcmd,$(INST) -m 755 -t "$(ILIBDIR)" lib$(NAME).so.$(MAJOR))
2016-10-27 15:12:00 +02:00
2016-10-12 12:55:34 +02:00
$(if $(INSTALL_DEVEL),\
2016-11-22 15:32:25 +01:00
$(call imsg,Linking lib$(NAME).so to lib$(NAME).so.$(MAJOR).))
2016-10-27 14:36:24 +02:00
$(if $(INSTALL_DEVEL),\
2016-11-22 15:32:25 +01:00
$(call qcmd,$(LN) lib$(NAME).so.$(MAJOR) \
2016-10-27 15:12:00 +02:00
"$(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-12-18 12:09:32 +01:00
$(if $(INSTALL_DEVEL),$(foreach i,$(INCPUB),\
$(call qcmd,$(INST) -m 644 $(INCDIR)/$(i).h "$(IINCDIR)/$(i).h"$(\n))))
2016-10-27 15:12:00 +02:00
2016-11-16 02:27:16 +01:00
# Uninstall the library and development files. (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-27 15:12:00 +02:00
$(call qcmd,$(RM) "$(ILIBDIR)/lib$(NAME).a" "$(ILIBDIR)/lib$(NAME).so"*)
2016-12-18 12:09:32 +01:00
$(call rmsg,Uninstalling development files.)
2016-10-27 15:12:00 +02:00
$(call qcmd,$(RM) "$(IINCDIR)/lib$(NAME).h")
$(call qcmd,$(RM) -r "$(IINCDIR)/lib$(NAME)")
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.
all-doc: $(foreach s,$(MAN_SECTIONS), $(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s)))
2016-10-28 14:27:03 +02:00
# Make manpages directories.
$(MAN_SECTIONS:%=$(MANDIR)/man%):
$(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
$(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:
$(call rmsg,Removing manpages directory.)
2016-12-18 12:09:32 +01:00
$(call qcmd,$(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)
$(call imsg,Installing manpages section $1.)
2016-10-27 15:12:00 +02:00
$(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"))
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-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-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-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-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