summaryrefslogtreecommitdiff
path: root/BaseTools/Source/C/Makefiles/header.makefile
blob: 55a7307a5ec0216b9502eee20fb8a60e0f554721 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
## @file
#
# The makefile can be invoked with
# HOST_ARCH = x86_64 or x64 for EM64T build
# HOST_ARCH = ia32 or IA32 for IA32 build
# HOST_ARCH = Arm or ARM for ARM build
#
# Copyright (c) 2007 - 2025, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent

# Set SEP to the platform specific path seperator
ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
  SHELL := cmd.exe
  SEP:=$(shell echo \)
else
  SEP:=/
endif

EDK2_PATH ?= $(MAKEROOT)/../../..
ifndef PYTHON_COMMAND
  ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
    #
    # Try using the Python Launcher for Windows to find an interperter.
    #
    CHECK_PY := $(shell where py.exe || echo NotFound)
    ifeq ($(CHECK_PY),NotFound)
      #
      # PYTHON_HOME is the old method of specifying a Python interperter on Windows.
      # Check if an interperter can be found using PYTHON_HOME.
      #
      ifdef PYTHON_HOME
        ifndef (,$(wildcard $(PYTHON_HOME)$(SEP)python.exe)) # Make sure the file exists
          PYTHON_COMMAND := $(PYTHON_HOME)$(SEP)python.exe
        else
          $(error Unable to find a Python interperter, if one is installed, set the PYTHON_COMMAND environment variable!)
        endif
      endif
    else
      PYTHON_COMMAND := $(shell py -3 -c "import sys; print(sys.executable)")
      ifdef (,$(wildcard $(PYTHON_COMMAND))) # Make sure the file exists
        $(error Unable to find a Python interperter, if one is installed, set the PYTHON_COMMAND environment variable!)
      endif
    endif
    undefine CHECK_PY
  else # UNIX
    PYTHON_COMMAND := $(shell /usr/bin/env python3 -c "import sys; print(sys.executable)")
    ifdef (,$(wildcard $(PYTHON_COMMAND))) # Make sure the file exists
      PYTHON_COMMAND := $(shell /usr/bin/env python -c "import sys; print(sys.executable)")
      ifdef (,$(wildcard $(PYTHON_COMMAND))) # Make sure the file exists
        undefine PYTHON_COMMAND
      endif
    endif
    ifndef PYTHON_COMMAND
      $(error Unable to find a Python interpreter, if one is installed, set the PYTHON_COMMAND environment variable!)
    endif
  endif
  export PYTHON_COMMAND
endif

# GnuMakeUtils.py is able to handle forward slashes in file paths on Windows systems
GNU_MAKE_UTILS_PY := $(PYTHON_COMMAND) $(MAKEROOT)$(SEP)Makefiles$(SEP)GnuMakeUtils.py
CP := $(GNU_MAKE_UTILS_PY) cp
MV := $(GNU_MAKE_UTILS_PY) mv
RM := $(GNU_MAKE_UTILS_PY) rm
MD := $(GNU_MAKE_UTILS_PY) md
RD := $(GNU_MAKE_UTILS_PY) rd

ifndef HOST_ARCH
  #
  # If HOST_ARCH is not defined, then we use 'GnuMakeUtils.py' to attempt
  # try to figure out the appropriate HOST_ARCH.
  #
  GET_GNU_HOST_ARCH_PY:=$(MAKEROOT)$(SEP)Makefiles$(SEP)GnuMakeUtils.py get_host_arch
  ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
    HOST_ARCH:=$(shell if defined PYTHON_COMMAND $(PYTHON_COMMAND) $(GET_GNU_HOST_ARCH_PY))
  else
    HOST_ARCH:=$(shell if command -v $(PYTHON_COMMAND) >/dev/null 1; then $(PYTHON_COMMAND) $(GET_GNU_HOST_ARCH_PY); else python $(GET_GNU_HOST_ARCH_PY); fi)
  endif
  ifeq ($(HOST_ARCH),)
    $(info HOST_ARCH detection failed.)
    undefine HOST_ARCH
  endif
  ifeq ($(HOST_ARCH),Unknown)
    $(info HOST_ARCH detection failed.)
    undefine HOST_ARCH
  endif
endif
ifndef HOST_ARCH
  $(error HOST_ARCH is not defined!)
endif

#Set up BaseTools binary path for Windows builds
ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
  ifndef BIN_PATH
    BIN_PATH_BASE=$(MAKEROOT)/../../Bin
    ifeq ($(HOST_ARCH),X64)
      BIN_PATH=$(BIN_PATH_BASE)/Win64
    else
      ifeq ($(HOST_ARCH),AARCH64)
        BIN_PATH=$(BIN_PATH_BASE)/Win64
      else
        BIN_PATH=$(BIN_PATH_BASE)/Win32
      endif
    endif
  endif
endif

ifneq ($(findstring cmd,$(SHELL)),cmd)
  CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
  LINUX:=$(findstring Linux, $(shell uname -s))
  DARWIN:=$(findstring Darwin, $(shell uname -s))
else
  #Don't use uname on Windows
  CYGWIN:=
  LINUX:=
  DARWIN:=
endif
CLANG := $(findstring clang,$(shell $(CC) --version))
ifneq ($(CLANG),)
CC ?= $(CLANG_BIN)clang
CXX ?= $(CLANG_BIN)clang++
AS ?= $(CLANG_BIN)clang
AR ?= $(CLANG_BIN)llvm-ar
LD ?= $(CLANG_BIN)llvm-ld
else ifeq ($(origin CC),default)
CC = $(GCC_PREFIX)gcc
CXX = $(GCC_PREFIX)g++
AS = $(GCC_PREFIX)gcc
AR = $(GCC_PREFIX)ar
LD = $(GCC_PREFIX)ld
endif
LINKER ?= $(CC)
ifeq ($(HOST_ARCH), IA32)
ARCH_INCLUDE = -I $(EDK2_PATH)/MdePkg/Include/Ia32/

else ifeq ($(HOST_ARCH), X64)
ARCH_INCLUDE = -I $(EDK2_PATH)/MdePkg/Include/X64/

else ifeq ($(HOST_ARCH), ARM)
ARCH_INCLUDE = -I $(EDK2_PATH)/MdePkg/Include/Arm/

else ifeq ($(HOST_ARCH), AARCH64)
ARCH_INCLUDE = -I $(EDK2_PATH)/MdePkg/Include/AArch64/

else ifeq ($(HOST_ARCH), RISCV64)
ARCH_INCLUDE = -I $(EDK2_PATH)/MdePkg/Include/RiscV64/

else ifeq ($(HOST_ARCH), LOONGARCH64)
ARCH_INCLUDE = -I $(EDK2_PATH)/MdePkg/Include/LoongArch64/

else
$(error Bad HOST_ARCH)
endif

INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKEROOT)/Include/ -I $(MAKEROOT)/Include/IndustryStandard -I $(MAKEROOT)/Common/ -I .. -I . $(ARCH_INCLUDE)
INCLUDE += -I $(EDK2_PATH)/MdePkg/Include
CPPFLAGS = $(INCLUDE)

# keep EXTRA_OPTFLAGS last
BUILD_OPTFLAGS = -O2 $(EXTRA_OPTFLAGS)

ifeq ($(DARWIN),Darwin)
# assume clang or clang compatible flags on OS X
CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror \
-Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g
else
ifneq ($(CLANG),)
CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
-fno-delete-null-pointer-checks -Wall -Werror \
-Wno-deprecated-declarations -Wno-self-assign \
-Wno-unused-result -nostdlib -g
else
CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
-fno-delete-null-pointer-checks -Wall -Werror \
-Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict \
-Wno-unused-result -nostdlib -g
endif
endif
ifneq ($(CLANG),)
LDFLAGS =
CXXFLAGS = -Wno-deprecated-register -Wno-unused-result -std=c++14
else
LDFLAGS =
CXXFLAGS = -Wno-unused-result
endif
ifeq ($(HOST_ARCH), IA32)
#
# Snow Leopard  is a 32-bit and 64-bit environment. uname -m returns i386, but gcc defaults
#  to x86_64. So make sure tools match uname -m. You can manual have a 64-bit kernal on Snow Leopard
#  so only do this is uname -m returns i386.
#
ifeq ($(DARWIN),Darwin)
  CFLAGS   += -arch i386
  CPPFLAGS += -arch i386
  LDFLAGS  += -arch i386
endif
endif

# keep BUILD_OPTFLAGS last
CFLAGS   += $(BUILD_OPTFLAGS)
CXXFLAGS += $(BUILD_OPTFLAGS)

# keep EXTRA_LDFLAGS last
LDFLAGS += $(EXTRA_LDFLAGS)

.PHONY: all
.PHONY: install
.PHONY: clean

all:

$(MAKEROOT)/libs:
	$(MD) $(MAKEROOT)/libs

$(MAKEROOT)/bin:
	$(MD) $(MAKEROOT)/bin
ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
	$(MD) $(BIN_PATH)
endif