top.mk 941 B

123456789101112131415161718192021222324252627282930
  1. ifneq ($(lastword a b),b)
  2. $(error This Makefile require make 3.81 or newer)
  3. endif
  4. # Detect whether shell style is windows or not
  5. # https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069
  6. ifeq '$(findstring ;,$(PATH))' ';'
  7. CMDEXE := 1
  8. endif
  9. # Set TOP to be the path to get from the current directory (where make was
  10. # invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
  11. # the name of this makefile relative to where make was invoked.
  12. THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
  13. TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE))
  14. ifeq ($(CMDEXE),1)
  15. TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi))
  16. else
  17. TOP := $(shell realpath $(TOP))
  18. endif
  19. #$(info Top directory is $(TOP))
  20. ifeq ($(CMDEXE),1)
  21. CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%)))
  22. else
  23. CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`)
  24. endif
  25. #$(info Path from top is $(CURRENT_PATH))