libwindmill/Makefile

121 lines
3.9 KiB
Makefile
Executable File

#!/usr/bin/make -f
#******************************************************************************#
# Include variables and message subsystem #
#******************************************************************************#
include Makefile.vars Makefile.msg
#******************************************************************************#
# General targets #
#******************************************************************************#
# Build everything.
all: all-lib
# Mostly clean everything. (remove everything but the end results)
mostlyclean: mostlyclean-lib
mclean: mostlyclean
# Clean everything.
clean fclean: clean-lib
$(call qcmd,$(RM) -r lib$(NAME)-*)
# Clean everything, and configuration.
mrproper: clean
$(call rmsg,Removing configuration.)
$(call qcmd,$(RM) Makefile.cfg)
# Make a distribution tarball
dist: mrproper
$(call bcmd,mkdir,lib$(NAME)-$(VERSION),\
$(MD) .dist)
$(call bcmd,cp,* lib$(NAME)-$(VERSION),\
$(CP) -R * .dist)
$(call qcmd,\
$(MV) .dist lib$(NAME)-$(VERSION))
$(call bcmd,tarball,lib$(NAME)-$(VERSION),\
tar czf lib$(NAME)-$(VERSION).tar.gz \
--exclude .git lib$(NAME)-$(VERSION))
$(call qcmd,$(RM) -r lib$(NAME)-$(VERSION))
# Remake everything. (clean and build)
re: clean all
.PHONY: all mostlyclean mclean clean fclean dist mrproper re
#******************************************************************************#
# 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 maintainer
getmaintainer:
@echo "$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>"
# Get the project version.
getversion:
@echo "$(VERSION)"
.PHONY: getname getmaintainer getversion
#******************************************************************************#
# Library-specific targets #
#******************************************************************************#
# Make the library.
all-lib: $(CHECKCFG) lib$(NAME).a
# Make an object directory.
$(OBJDIR)/ $(DIRS:%=$(OBJDIR)/%):
$(call bcmd,mkdir,$@,$(MD) $@)
# Make an object out of a source file.
define make-obj-rules
ifeq ($(shell test -f $(SRCDIR)/$1.c && echo y),y)
$(OBJDIR)/$1.o: $(SRCDIR)/$1.c $(INC) | $(dir $(OBJDIR)/$1)
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS))
else
$(OBJDIR)/$1.o: $(SRCDIR)/$1.s | $(dir $(OBJDIR)/$1)
$(call bcmd,as,$$@,$(AS) -c -o $$@ $$< $(ASFLAGS))
endif
endef
$(foreach src,$(SRC), \
$(eval $(call make-obj-rules,$(src))))
# Make the library.
lib$(NAME).a: $(SRC:%=$(OBJDIR)/%.o)
$(call bcmd,ar rcs,$@,$(AR) rc $@ $^)
# 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) lib$(NAME).a)
# Remake the library.
re-lib: clean-lib all-lib
.PHONY: all-lib mostlyclean-lib mclean-lib clean-lib re-lib
# End of file.