mkmakefile 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # Generates a small Makefile used in the root of the output
  3. # directory, to allow make to be started from there.
  4. # The Makefile also allow for more convenient build of external modules
  5. # Usage
  6. # $1 - Kernel src directory
  7. # $2 - Output directory
  8. test ! -r $2/Makefile -o -O $2/Makefile || exit 0
  9. # Only overwrite automatically generated Makefiles
  10. # (so we do not overwrite buildroot Makefile)
  11. if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
  12. then
  13. exit 0
  14. fi
  15. echo " GEN $2/Makefile"
  16. cat << EOF > $2/Makefile
  17. # Automatically generated by $0: don't edit
  18. lastword = \$(word \$(words \$(1)),\$(1))
  19. makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
  20. MAKEARGS := -C $1
  21. MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
  22. MAKEFLAGS += --no-print-directory
  23. .PHONY: _all \$(MAKECMDGOALS)
  24. all := \$(filter-out Makefile,\$(MAKECMDGOALS))
  25. _all:
  26. umask 0022 && \$(MAKE) \$(MAKEARGS) \$(all)
  27. Makefile:;
  28. \$(all): _all
  29. @:
  30. %/: _all
  31. @:
  32. EOF