xref: /arm-trusted-firmware/make_helpers/windows.mk (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu#
2*91f16700Schasinglulu# Copyright (c) 2016-2023, Arm Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu#
4*91f16700Schasinglulu# SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu#
6*91f16700Schasinglulu
7*91f16700Schasinglulu# OS specific parts for builds in a Windows_NT environment. The
8*91f16700Schasinglulu# environment variable OS is set to Windows_NT on all modern Windows platforms
9*91f16700Schasinglulu
10*91f16700Schasinglulu# Include generic windows command definitions.
11*91f16700Schasinglulu
12*91f16700Schasingluluifndef WINDOWS_MK
13*91f16700Schasinglulu    WINDOWS_MK := $(lastword $(MAKEFILE_LIST))
14*91f16700Schasinglulu
15*91f16700Schasinglulu    ECHO_BLANK_LINE := @cmd /c echo.
16*91f16700Schasinglulu    ECHO_QUIET := @rem
17*91f16700Schasinglulu    DIR_DELIM := $(strip \)
18*91f16700Schasinglulu    BIN_EXT   := .exe
19*91f16700Schasinglulu    PATH_SEP  := ;
20*91f16700Schasinglulu
21*91f16700Schasinglulu    # For some Windows native commands there is a problem with the directory delimiter.
22*91f16700Schasinglulu    # Make uses / (slash) and the commands expect \ (backslash)
23*91f16700Schasinglulu    # We have to provide a means of translating these, so we define local functions.
24*91f16700Schasinglulu
25*91f16700Schasinglulu    # ${1} is the file to be copied.
26*91f16700Schasinglulu    # ${2} is the destination file name.
27*91f16700Schasinglulu    define SHELL_COPY
28*91f16700Schasinglulu	$(eval tmp_from_file:=$(subst /,\,${1}))
29*91f16700Schasinglulu	$(eval tmp_to_file:=$(subst /,\,${2}))
30*91f16700Schasinglulu	copy "${tmp_from_file}" "${tmp_to_file}"
31*91f16700Schasinglulu    endef
32*91f16700Schasinglulu
33*91f16700Schasinglulu    # ${1} is the directory to be copied.
34*91f16700Schasinglulu    # ${2} is the destination directory path.
35*91f16700Schasinglulu    define SHELL_COPY_TREE
36*91f16700Schasinglulu	$(eval tmp_from_dir:=$(subst /,\,${1}))
37*91f16700Schasinglulu	$(eval tmp_to_dir:=$(subst /,\,${2}))
38*91f16700Schasinglulu	xcopy /HIVE "${tmp_from_dir}" "${tmp_to_dir}"
39*91f16700Schasinglulu    endef
40*91f16700Schasinglulu
41*91f16700Schasinglulu    # ${1} is the file to be deleted.
42*91f16700Schasinglulu    define SHELL_DELETE
43*91f16700Schasinglulu	$(eval tmp_del_file:=$(subst /,\,${*}))
44*91f16700Schasinglulu	-@if exist $(tmp_del_file)  del /Q $(tmp_del_file)
45*91f16700Schasinglulu    endef
46*91f16700Schasinglulu
47*91f16700Schasinglulu    # ${1} is a space delimited list of files to be deleted.
48*91f16700Schasinglulu    define SHELL_DELETE_ALL
49*91f16700Schasinglulu	$(eval $(foreach filename,$(wildcard ${1}),$(call DELETE_IF_THERE,${filename})))
50*91f16700Schasinglulu    endef
51*91f16700Schasinglulu
52*91f16700Schasinglulu    # ${1} is the directory to be generated.
53*91f16700Schasinglulu    # ${2} is optional, and allows prerequisites to be specified.
54*91f16700Schasinglulu    # Do nothing if $1 == $2, to ignore self dependencies.
55*91f16700Schasinglulu    define MAKE_PREREQ_DIR
56*91f16700Schasinglulu        ifneq (${1},${2})
57*91f16700Schasinglulu
58*91f16700Schasinglulu${1} : ${2}
59*91f16700Schasinglulu	$(eval tmp_dir:=$(subst /,\,${1}))
60*91f16700Schasinglulu	-@if not exist "$(tmp_dir)"  mkdir "${tmp_dir}"
61*91f16700Schasinglulu
62*91f16700Schasinglulu        endif
63*91f16700Schasinglulu    endef
64*91f16700Schasinglulu
65*91f16700Schasinglulu    # ${1} is the directory to be removed.
66*91f16700Schasinglulu    define SHELL_REMOVE_DIR
67*91f16700Schasinglulu	$(eval tmp_dir:=$(subst /,\,${1}))
68*91f16700Schasinglulu	-@if exist "$(tmp_dir)"  rd /Q /S "$(tmp_dir)"
69*91f16700Schasinglulu    endef
70*91f16700Schasinglulu
71*91f16700Schasingluluendif
72*91f16700Schasinglulu
73*91f16700Schasinglulu# Because git is not available from CMD.EXE, we need to avoid
74*91f16700Schasinglulu# the BUILD_STRING generation which uses git.
75*91f16700Schasinglulu# For now we use "development build".
76*91f16700Schasinglulu# This can be overridden from the command line or environment.
77*91f16700SchasingluluBUILD_STRING ?= development build
78*91f16700Schasinglulu
79*91f16700Schasinglulu# The DOS echo shell command does not strip ' characters from the command
80*91f16700Schasinglulu# parameters before printing. We therefore use an alternative method invoked
81*91f16700Schasinglulu# by defining the MAKE_BUILD_STRINGS macro.
82*91f16700SchasingluluBUILT_TIME_DATE_STRING = const char build_message[] = "Built : "${BUILD_MESSAGE_TIMESTAMP};
83*91f16700SchasingluluVERSION_STRING_MESSAGE = const char version_string[] = "${VERSION_STRING}";
84*91f16700SchasingluluVERSION_MESSAGE = const char version[] = "${VERSION}";
85*91f16700Schasingluludefine MAKE_BUILD_STRINGS
86*91f16700Schasinglulu	$$(file >$1.in,$$(TF_CFLAGS) $$(CFLAGS))
87*91f16700Schasinglulu	@echo $$(BUILT_TIME_DATE_STRING) $$(VERSION_STRING_MESSAGE) $$(VERSION_MESSAGE) | \
88*91f16700Schasinglulu		$$(CC) @$1.in -x c -c - -o $1
89*91f16700Schasingluluendef
90*91f16700Schasinglulu
91*91f16700SchasingluluMSVC_NMAKE := nmake.exe
92*91f16700Schasinglulu
93