|
1 | 1 | ifneq ($(lastword a b),b) |
2 | | -$(error This Makefile require make 3.81 or newer) |
| 2 | +$(error This Makefile requires make 3.81 or newer) |
3 | 3 | endif |
4 | 4 |
|
5 | 5 | # Detect whether shell style is windows or not |
6 | 6 | # https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069 |
7 | 7 | ifeq '$(findstring ;,$(PATH))' ';' |
| 8 | +# PATH contains semicolon - so we're definitely on Windows. |
8 | 9 | CMDEXE := 1 |
| 10 | + |
| 11 | +# makefile shell commands should use syntax for DOS CMD, not unix sh |
| 12 | +# Unfortunately, SHELL may point to sh or bash, which can't accept DOS syntax. |
| 13 | +# We can't just use sh, because while sh and/or bash shell may be available, |
| 14 | +# many Windows environments won't have utilities like realpath used below, so... |
| 15 | +# Force DOS command shell on Windows. |
| 16 | +SHELL := cmd.exe |
9 | 17 | endif |
10 | 18 |
|
| 19 | +#$(info top.mk: SHELL=$(SHELL)) |
| 20 | +#$(info top.mk: CMDEXE=$(CMDEXE)) |
| 21 | + |
11 | 22 | # Set TOP to be the path to get from the current directory (where make was |
12 | 23 | # invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns |
13 | 24 | # the name of this makefile relative to where make was invoked. |
14 | | - |
15 | 25 | THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) |
| 26 | + |
| 27 | +# strip off /tools/top.mk to get for example ../../.. |
16 | 28 | TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE)) |
| 29 | +#$(info top.mk: Initial TOP=$(TOP)) |
17 | 30 |
|
| 31 | +# Set TOP to an absolute path, for example /tinyUSB (from ../../..) |
18 | 32 | ifeq ($(CMDEXE),1) |
19 | 33 | TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi)) |
20 | 34 | else |
21 | 35 | TOP := $(shell realpath $(TOP)) |
22 | 36 | endif |
23 | | -#$(info Top directory is $(TOP)) |
| 37 | +#$(info top.mk: Top directory is $(TOP)) |
24 | 38 |
|
| 39 | +# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos |
25 | 40 | ifeq ($(CMDEXE),1) |
26 | 41 | CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%))) |
27 | 42 | else |
28 | 43 | CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`) |
29 | 44 | endif |
30 | | -#$(info Path from top is $(CURRENT_PATH)) |
| 45 | +#$(info top.mk: Path from top is $(CURRENT_PATH)) |
0 commit comments