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

225 lines
5.8 KiB
Makefile
Raw Normal View History

2016-10-27 14:36:24 +02:00
#!/usr/bin/make -f
2016-08-16 21:33:44 +02:00
# INCLUDE VARS
include Makefile.vars
# DEDUCED VARS
2016-10-27 14:36:24 +02:00
# - All objects
ALLOBJ := $(foreach mod,$(MODULES),$(SRC_$(mod):%=$(OBJDIR)/$(mod)/%.o))
2016-10-27 14:36:24 +02:00
# - All manpages
ALLMAN := $(foreach s,$(MAN_SECTIONS),\
$(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s)))
# - Configuration version checking 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 14:36:24 +02:00
# - Commands prefix
PCMD := $(if $(MAKE_FULL_LOG),,@)
# - All messages
# -- Command messages
define cmd
@$(if $(MAKE_FULL_LOG),#)printf "\e[32m>\e[0m \e[1m%s\e[0m %s\n" "$1" "$2"
endef
# -- Normal messages
define msg
@$(if $(MAKE_FULL_LOG),#)printf "\e[35m>\e[0m %s\n" "$1"
endef
# -- Remove messages
define rmsg
@$(if $(MAKE_FULL_LOG),#)printf "\e[31m>\e[0m %s\n" "$1"
endef
2016-08-16 21:33:44 +02:00
# TARGETS
## General targets
## - Make it all
all: all-lib all-doc
2016-09-15 10:27:38 +02:00
## - Mostly clean
mostlyclean: mclean-lib
mclean: mostlyclean
## - Clean it all
clean: clean-lib clean-doc
## -- for compatibility
2016-09-15 10:27:38 +02:00
fclean: clean
## - Remake it all
2016-09-15 10:27:38 +02:00
re: clean all
## - Install it all
2016-10-05 18:04:47 +02:00
install: install-lib install-doc
## - Uninstall
2016-10-05 18:04:47 +02:00
uninstall: uninstall-lib uninstall-doc
## - Reinstall library
reinstall: uninstall install
2016-08-16 21:33:44 +02:00
2016-10-12 12:55:34 +02:00
## - Get informations
2016-09-28 14:40:39 +02:00
getname:
@echo lib$(NAME)
2016-10-12 12:55:34 +02:00
getauthor:
@echo $(AUTHOR)
getmail:
@echo $(AUTHOR_MAIL)
2016-09-28 14:40:39 +02:00
getversion:
@echo $(VERSION)
2016-09-15 09:38:17 +02:00
## - Configuration checking
2016-09-15 11:05:22 +02:00
check-config:
2016-09-15 09:38:17 +02:00
@tput setf 4 && \
2016-09-28 14:40:39 +02:00
tput bold && \
echo "No configuration file found !" && \
echo "You should configure before re-running this target." && \
tput setf 7 && \
tput sgr 0 && \
false
check-config-version:
@tput setf 4 && \
tput bold && \
echo "Configuration version is incorrect!" && \
echo "You should re-configure before re-running this target." && \
tput setf 7 && \
tput sgr 0 && \
false
2016-09-15 09:38:17 +02:00
2016-08-16 21:33:44 +02:00
## Library-specific targets
## - Make all libraries
2016-09-15 09:38:17 +02:00
all-lib: $(CHECKCFG) lib$(NAME).so
2016-08-17 15:47:32 +02:00
## - Make a module object directory
$(MODULES:%=$(OBJDIR)/%):
2016-10-27 14:36:24 +02:00
$(call cmd,mkdir,$@)
$(PCMD)$(MD) $@
2016-08-16 21:33:44 +02:00
2016-08-17 15:47:32 +02:00
## - Make a module object out of a module source file
define make-moduleobj-rule
$(OBJDIR)/$1/%.o: $(SRCDIR)/$1/%.c | $(OBJDIR)/$1
2016-10-27 14:36:24 +02:00
$(call cmd,cc,$$@)
$(PCMD)$(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-09-04 13:06:40 +02:00
## - Make the dynamic library
lib$(NAME).so: $(ALLOBJ)
2016-10-27 14:36:24 +02:00
$(call cmd,ld,$@)
$(PCMD)$(LD) -o $@ $^ $(LDFLAGS)
2016-08-16 21:33:44 +02:00
## - Remove object files
2016-09-15 10:27:38 +02:00
mclean-lib:
2016-10-27 14:36:24 +02:00
$(call rmsg,Removing object files.)
$(PCMD)$(RM) $(ALLOBJ)
2016-08-16 21:33:44 +02:00
## - Clean and remove final 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.)
$(PCMD)$(RM) lib$(NAME).so
2016-08-16 21:33:44 +02:00
## - Remake library
2016-09-15 10:27:38 +02:00
re-lib: clean-lib all-lib
2016-08-16 21:33:44 +02:00
2016-08-21 14:30:52 +02:00
## - Install library
2016-10-27 14:36:24 +02:00
install-lib: $(CHECKCFG)
$(call msg,Installing the library.)
$(PCMD)$(INST) -m 755 -d "$(ILIBDIR)"
$(PCMD)$(INST) -m 644 lib$(NAME).so "$(ILIBDIR)/lib$(NAME).so.$(VERSION_MAJOR)"
2016-10-12 12:55:34 +02:00
$(if $(INSTALL_DEVEL),\
2016-10-27 14:36:24 +02:00
$(call msg,Installing development files.))
$(if $(INSTALL_DEVEL),\
$(PCMD)$(LN) lib$(NAME).so.$(VERSION_MAJOR) "$(ILIBDIR)/lib$(NAME).so")
$(if $(INSTALL_DEVEL),\
$(PCMD)$(INST) -m 755 -d "$(IINCDIR)")
$(if $(INSTALL_DEVEL),\
$(PCMD)$(INST) -m 644 -t "$(IINCDIR)" $(INCPUB:%=$(INCDIR)/%.h))
$(if $(INSTALL_UDEV_RULE),\
$(call msg,Installing the udev rule.))
$(if $(INSTALL_UDEV_RULE),\
$(PCMD)$(INST) -m 755 -d "$(UDEVDIR)")
2016-10-12 12:55:34 +02:00
$(if $(INSTALL_UDEV_RULE),\
2016-10-27 14:36:24 +02:00
$(PCMD)$(INST) -m 644 udev.rules "$(UDEVDIR)/60-casio-usb.rules")
2016-08-21 14:30:52 +02:00
2016-09-04 13:06:40 +02:00
## - Uninstall library
2016-09-15 09:38:17 +02:00
uninstall-lib: $(CHECKCFG)
2016-10-27 14:36:24 +02:00
$(call rmsg,Uninstalling the library.)
$(PCMD)$(RM) "$(ILIBDIR)/lib$(NAME).a" "$(ILIBDIR)/lib$(NAME).so"*
$(PCMD)$(RM) "$(IINCDIR)/lib$(NAME).h"
$(PCMD)$(RM) -r "$(IINCDIR)/lib$(NAME)"
$(PCMD)$(RM) "$(UDEVDIR)/60-casio-usb.rules"
2016-09-04 13:06:40 +02:00
2016-08-21 14:30:52 +02:00
## Documentation related
## - Make all manpages
all-doc: $(ALLMAN)
2016-08-21 14:30:52 +02:00
## - Make manpages directories
$(MAN_SECTIONS:%=$(MANDIR)/man%):
2016-10-27 14:36:24 +02:00
$(call cmd,mkdir,$@)
$(PCMD)$(MD) $@
2016-08-21 14:30:52 +02:00
## - Make-A-Manpage
define make-manpage-rule
2016-10-27 14:36:24 +02:00
$(MANDIR)/man$1/%.$1: $(DOCDIR)/%.$1.txt | $(MANDIR)/man$1
$(call cmd,a2x,$$<)
$(PCMD)$(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))))
## - Remove all manpages
clean-doc:
2016-10-27 14:36:24 +02:00
$(call rmsg,Removing manpages.)
$(PCMD)$(RM) $(ALLMAN)
2016-08-21 14:30:52 +02:00
2016-09-15 10:27:38 +02:00
## - Remake docs
re-doc: clean-doc all-doc
2016-10-27 14:36:24 +02:00
## - Install-A-Manpage-Section
define make-installmansection-rule
install-doc-$1: $(MAN_$1:%=$(MANDIR)/man$1/%.$1)
$(call msg,Installing manpages section $1.)
$(PCMD)$(INST) -m 755 -d "$(IMANDIR)/man$1"
$(PCMD)$(INST) -m 644 -t "$(IMANDIR)/man$1" $(MAN_$1:%=$(MANDIR)/man$1/%.$1)
$(PCMD)$(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
## - Install manpages
2016-10-12 12:55:34 +02:00
install-doc: $(CHECKCFG) $(if $(INSTALL_MANPAGES),\
2016-10-27 14:36:24 +02:00
$(MAN_SECTIONS:%=install-doc-%))
## - Clean a man 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.)
$(PCMD)$(RM) "$(IMANDIR)/man$1/lib$(NAME).$1"
$(PCMD)$(RM) "$(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))))
## - Uninstall manpages
2016-09-15 09:38:17 +02:00
uninstall-doc: $(CHECKCFG) $(MAN_SECTIONS:%=uninstall-doc-%)
2016-09-12 17:25:30 +02:00
## Package targets
2016-09-14 23:28:06 +02:00
## - Debian
2016-09-12 17:25:30 +02:00
deb:
debuild --no-tgz-check -us -uc
# PHONY
# - General
2016-09-28 14:40:39 +02:00
.PHONY: all mostlyclean mclean clean fclean re install uninstall
2016-10-27 14:36:24 +02:00
.PHONY: getname getauthor getmail getversion
.PHONY: check-config check-config-version
# - Library-related
2016-09-15 10:27:38 +02:00
.PHONY: all-lib mclean-lib clean-lib re-lib install-lib uninstall-lib
.PHONY: $(INCPUB:%=install-lib-$(INCDIR)/%.h)
2016-09-25 22:01:42 +02:00
# - Scripts-related
.PHONY: install-bin uninstall-bin
# - Documentation related
.PHONY: all-doc clean-doc install-doc uninstall-doc
2016-10-27 14:36:24 +02:00
.PHONY: $(MAN_SECTIONS:%=install-doc-%) $(MAN_SECTIONS:%=uninstall-doc-%)
2016-09-12 19:59:14 +02:00
# - Packaging
.PHONY: deb
2016-08-16 21:33:44 +02:00
# END OF FILE