From 5315fd6786c32d39378961e1fcebd15eeb451304 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Tue, 19 Jul 2016 20:47:36 -0700 Subject: [PATCH] Make 'make clean' not depend on genfiles metadata Previously even 'make clean' would first produce dependency information (slow) and sinclude all the metadata, possibly restarting the make, before removing the things it just did. Now dependencies are only processed when something explicitly depends on them, by calling 'make' on the rules around generated files, rather than sincluding them. Net result: make clean is faster and safer. Additionally, bash tab-completion for 'make' does not run the slow 'find' any more. --- Makefile | 28 +++++++++++++++++++++------- Makefile.generated_files | 34 ++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index d9c9aa75e07..5dd0600eff4 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ DBG_MAKEFILE ?= ifeq ($(DBG_MAKEFILE),1) - $(warning ***** starting makefile for goal(s) "$(MAKECMDGOALS)") + $(warning ***** starting Makefile for goal(s) "$(MAKECMDGOALS)") $(warning ***** $(shell date)) else # If we're not debugging the Makefile, don't echo recipes. @@ -29,7 +29,7 @@ endif # test: Run tests. # clean: Clean up. -# It's necessary to set this because some docker images don't make sh -> bash. +# It's necessary to set this because some environments don't link sh -> bash. SHELL := /bin/bash # We don't need make's built-in rules. @@ -37,16 +37,17 @@ MAKEFLAGS += --no-builtin-rules .SUFFIXES: # Constants used throughout. +.EXPORT_ALL_VARIABLES: OUT_DIR ?= _output BIN_DIR := $(OUT_DIR)/bin PRJ_SRC_PATH := k8s.io/kubernetes +GENERATED_FILE_PREFIX := zz_generated. # Metadata for driving the build lives here. META_DIR := .make -export KUBE_GOFLAGS := $(GOFLAGS) - -export KUBE_GOLDFLAGS := $(GOLDFLAGS) +KUBE_GOFLAGS := $(GOFLAGS) +KUBE_GOLDFLAGS := $(GOLDFLAGS) # Build code. # @@ -184,6 +185,14 @@ clean: clean_meta clean_meta: rm -rf $(META_DIR) +# Remove all auto-generated artifacts. +# +# Example: +# make clean_generated +.PHONY: clean_generated +clean_generated: + find . -type f -name $(GENERATED_FILE_PREFIX)\* | xargs rm -f + # Run 'go vet'. # # Args: @@ -230,5 +239,10 @@ cross: $(notdir $(abspath $(wildcard cmd/*/))): generated_files hack/make-rules/build.sh cmd/$@ -# Include logic for generated files. -include Makefile.generated_files +# Produce auto-generated files needed for the build. +# +# Example: +# make generated_files +.PHONY: generated_files +generated_files: + $(MAKE) -f Makefile.$@ $@ diff --git a/Makefile.generated_files b/Makefile.generated_files index c1c6a4472cb..f140b52745c 100644 --- a/Makefile.generated_files +++ b/Makefile.generated_files @@ -12,8 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Constants used throughout. -GENERATED_FILE_PREFIX := zz_generated. +# Don't allow an implicit 'all' rule. This is not a user-facing file. +ifeq ($(MAKECMDGOALS),) + $(error This Makefile requires an explicit rule to be specified) +endif + +ifeq ($(DBG_MAKEFILE),1) + $(warning ***** starting Makefile.generated_files for goal(s) "$(MAKECMDGOALS)") + $(warning ***** $(shell date)) +endif + + +# It's necessary to set this because some environments don't link sh -> bash. +SHELL := /bin/bash + +# This rule collects all the generated file sets into a single rule. Other +# rules should depend on this to ensure generated files are rebuilt. +.PHONY: generated_files +generated_files: gen_deepcopy gen_conversion # Code-generation logic. # @@ -455,17 +471,3 @@ sinclude $(META_DIR)/$(CONVERSION_GEN).mk $(CONVERSION_GEN): hack/make-rules/build.sh cmd/libs/go2idl/conversion-gen touch $@ - -# This rule collects all the generated file sets into a single dep, which is -# defined BELOW the *_FILES variables and leaves higher-level rules clean. -# Top-level rules should depend on this to ensure generated files are rebuilt. -.PHONY: generated_files -generated_files: gen_deepcopy gen_conversion - -# Remove all auto-generated artifacts. -# -# Example: -# make clean_generated -.PHONY: clean_generated -clean_generated: - find . -type f -name $(GENERATED_FILE_PREFIX)\* | xargs rm -f