mkmakefile 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Generates a small Makefile used in the root of the output
  4. # directory, to allow make to be started from there.
  5. # The Makefile also allow for more convinient build of external modules
  6. # Usage
  7. # $1 - Kernel src directory
  8. # $2 - Output directory
  9. # $3 - version
  10. # $4 - patchlevel
  11. test ! -r $2/Makefile -o -O $2/Makefile || exit 0
  12. # Only overwrite automatically generated Makefiles
  13. # (so we do not overwrite kernel Makefile)
  14. if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
  15. then
  16. exit 0
  17. fi
  18. if [ "${quiet}" != "silent_" ]; then
  19. echo " GEN $2/Makefile"
  20. fi
  21. cat << EOF > $2/Makefile
  22. # Automatically generated by $0: don't edit
  23. VERSION = $3
  24. PATCHLEVEL = $4
  25. lastword = \$(word \$(words \$(1)),\$(1))
  26. makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
  27. ifeq ("\$(origin V)", "command line")
  28. VERBOSE := \$(V)
  29. endif
  30. ifneq (\$(VERBOSE),1)
  31. Q := @
  32. endif
  33. MAKEARGS := -C $1
  34. MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
  35. MAKEFLAGS += --no-print-directory
  36. .PHONY: __sub-make \$(MAKECMDGOALS)
  37. __sub-make:
  38. \$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS)
  39. \$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make
  40. @:
  41. EOF