Skip to content

Instantly share code, notes, and snippets.

@bukowa
Created February 17, 2023 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bukowa/d5aae7c7415085355dfea238e5c177ba to your computer and use it in GitHub Desktop.
Save bukowa/d5aae7c7415085355dfea238e5c177ba to your computer and use it in GitHub Desktop.
supress silence quiet Makefile warning: overriding commands for target warning: ignoring old commands for target
# Makefile utility for including other Makefiles only once
# Function that includes a Makefile if it hasn't been included before
#
# Usage:
# $(call include_makefile_once, <filename>)
#
# where <filename> is the name of the Makefile to include
define include_makefile_once
ifeq ($(filter %$(1),$(MAKEFILE_LIST)),)
include $(1)
endif
endef
# Macro that includes multiple Makefiles only once
#
# Usage:
# $(call include_makefiles_once, <filenames>)
#
# where <filenames> is a space-separated list of filenames to include
#
# Example:
# $(call include_makefiles_once, git.mk otherlib.mk thirdlib.mk)
#
# This will include the Makefiles git.mk, otherlib.mk, and thirdlib.mk
# only once each, if they exist.
define include_makefiles_once
$(foreach FILE,$(1),$(eval $(call include_makefile_once,$(FILE))))
endef
include lib/include.mk
MAKEFILES_INCLUDES = help.mk print.mk git.mk
$(call include_makefiles_once,$(MAKEFILES_INCLUDES))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment