2018-11-24 19:55:51 +01:00
|
|
|
ifneq ($(lastword a b),b)
|
2023-01-22 18:11:50 +01:00
|
|
|
$(error This Makefile requires make 3.81 or newer)
|
2018-11-24 19:55:51 +01:00
|
|
|
endif
|
|
|
|
|
2021-01-13 17:19:43 +01:00
|
|
|
# Detect whether shell style is windows or not
|
2021-01-10 12:46:29 +01:00
|
|
|
# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069
|
|
|
|
ifeq '$(findstring ;,$(PATH))' ';'
|
2023-01-22 18:11:50 +01:00
|
|
|
# PATH contains semicolon - so we're definitely on Windows.
|
|
|
|
CMDEXE := 1# makefile shell commands should use syntax for DOS CMD, not unix sh
|
|
|
|
# Unfortunately, SHELL may point to sh or bash, which can't accept DOS syntax.
|
|
|
|
# $(info top.mk: SHELL=$(SHELL))
|
|
|
|
# We can't just use sh, because while sh and/or bash shell may be available,
|
|
|
|
# many Windows environments won't have utilities like realpath used below, so...
|
|
|
|
SHELL := cmd.exe# Force DOS command shell on Windows.
|
2021-01-10 12:46:29 +01:00
|
|
|
endif
|
|
|
|
|
2023-01-22 18:11:50 +01:00
|
|
|
#$(info top.mk: SHELL=$(SHELL))
|
|
|
|
#$(info top.mk: CMDEXE=$(CMDEXE)...)
|
|
|
|
|
2018-11-24 19:55:51 +01:00
|
|
|
# Set TOP to be the path to get from the current directory (where make was
|
|
|
|
# invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
|
|
|
|
# the name of this makefile relative to where make was invoked.
|
2023-01-22 18:11:50 +01:00
|
|
|
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))# this makefile is the one most recently appended to the list of makefiles
|
|
|
|
TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE))# strip off /tools/top.mk to get for example ../../..
|
|
|
|
#$(info top.mk: Initial TOP=$(TOP))
|
2018-11-24 19:55:51 +01:00
|
|
|
|
2023-01-22 18:11:50 +01:00
|
|
|
# Set TOP to an absolute path, for example /tinyUSB (from ../../..)
|
2021-01-13 17:19:43 +01:00
|
|
|
ifeq ($(CMDEXE),1)
|
2021-01-10 12:46:29 +01:00
|
|
|
TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi))
|
|
|
|
else
|
2018-11-24 19:55:51 +01:00
|
|
|
TOP := $(shell realpath $(TOP))
|
2021-01-10 12:46:29 +01:00
|
|
|
endif
|
2023-01-22 18:11:50 +01:00
|
|
|
#$(info top.mk: Top directory is $(TOP))
|
2018-11-24 19:55:51 +01:00
|
|
|
|
2023-01-22 18:11:50 +01:00
|
|
|
# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos
|
2021-01-13 17:19:43 +01:00
|
|
|
ifeq ($(CMDEXE),1)
|
2021-01-10 12:46:29 +01:00
|
|
|
CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%)))
|
|
|
|
else
|
2018-11-24 19:55:51 +01:00
|
|
|
CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`)
|
2021-01-10 12:46:29 +01:00
|
|
|
endif
|
2023-01-22 18:11:50 +01:00
|
|
|
#$(info top.mk: Path from top is $(CURRENT_PATH))
|