|
| 1 | +# -*- makefile -*- |
| 2 | +# Copyright (c) 1999-2007 Hewlett-Packard Development Company, L.P. |
| 3 | +# Contributed by David Mosberger <[email protected]> |
| 4 | +# Contributed by Stephane Eranian <[email protected]> |
| 5 | +# |
| 6 | +# All rights reserved. |
| 7 | +# |
| 8 | +# Redistribution and use in source and binary forms, with or without |
| 9 | +# modification, are permitted provided that the following conditions |
| 10 | +# are met: |
| 11 | +# |
| 12 | +# * Redistributions of source code must retain the above copyright |
| 13 | +# notice, this list of conditions and the following disclaimer. |
| 14 | +# * Redistributions in binary form must reproduce the above |
| 15 | +# copyright notice, this list of conditions and the following |
| 16 | +# disclaimer in the documentation and/or other materials |
| 17 | +# provided with the distribution. |
| 18 | +# * Neither the name of Hewlett-Packard Co. nor the names of its |
| 19 | +# contributors may be used to endorse or promote products derived |
| 20 | +# from this software without specific prior written permission. |
| 21 | +# |
| 22 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 23 | +# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 24 | +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 25 | +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 27 | +# BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
| 28 | +# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 29 | +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 30 | +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 31 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 32 | +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 33 | +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | +# SUCH DAMAGE. |
| 35 | +# |
| 36 | + |
| 37 | +TOPDIR ?= $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi) |
| 38 | + |
| 39 | +# |
| 40 | +# Variables below overridable from command-line: |
| 41 | +# make VARNAME=value ... |
| 42 | +# |
| 43 | + |
| 44 | +# |
| 45 | +# Where to install the package. GNU-EFI will create and access |
| 46 | +# lib and include under the root |
| 47 | +# |
| 48 | +DESTDIR ?= / |
| 49 | +ifeq ($(origin INSTALLROOT),undefined) |
| 50 | +INSTALLROOT = $(DESTDIR) |
| 51 | +endif |
| 52 | + |
| 53 | +empty := |
| 54 | +space := $(empty) $(empty) |
| 55 | +stripped = $(subst $(space),/,$(strip $(subst /,$(space),$(1)))) |
| 56 | +unstripped = $(subst $(space),/,$(subst /,$(space),$(1))) |
| 57 | +is_absolute = $(subst $(call stripped,$(1)),$(empty),$(call unstripped,$(1))) |
| 58 | + |
| 59 | +override INSTALLROOT:=$(if $(call is_absolute,$(INSTALLROOT)),,$(TOPDIR)/)$(INSTALLROOT) |
| 60 | + |
| 61 | +PREFIX := /usr/local |
| 62 | +EXEC_PREFIX := $(PREFIX) |
| 63 | +LIBDIR := $(EXEC_PREFIX)/lib |
| 64 | +INCLUDEDIR := $(PREFIX)/include |
| 65 | +INSTALL := install |
| 66 | + |
| 67 | +# Compilation tools |
| 68 | +HOSTCC := $(prefix)gcc |
| 69 | +CC := $(prefix)$(CROSS_COMPILE)gcc |
| 70 | +AS := $(prefix)$(CROSS_COMPILE)as |
| 71 | +LD := $(prefix)$(CROSS_COMPILE)ld |
| 72 | +AR := $(prefix)$(CROSS_COMPILE)ar |
| 73 | +RANLIB := $(prefix)$(CROSS_COMPILE)ranlib |
| 74 | +OBJCOPY := $(prefix)$(CROSS_COMPILE)objcopy |
| 75 | + |
| 76 | +# Set verbose or nonverbose output similarly to automake's silent rules. |
| 77 | +# Default is nonverbose, but, just like with automake, it can be disabled |
| 78 | +# with: 'make V=1' |
| 79 | +ifneq ($(V),1) |
| 80 | + HIDE=@ |
| 81 | + ECHO=echo |
| 82 | +else |
| 83 | + HIDE= |
| 84 | + ECHO=true |
| 85 | +endif |
| 86 | + |
| 87 | +# Host/target identification |
| 88 | +OS := $(shell uname -s) |
| 89 | +USING_APPLE ?= $(shell echo $(OS) | grep -q 'Darwin' && echo 1 || echo 0) |
| 90 | +USING_FREEBSD ?= $(shell echo $(OS) | grep -q 'FreeBSD' && echo 1 || echo 0) |
| 91 | + |
| 92 | +# FreeBSD uses clang with no gcc symlink |
| 93 | +ifeq ($(USING_FREEBSD),1) |
| 94 | +override HOSTCC := $(prefix)clang |
| 95 | +endif |
| 96 | + |
| 97 | +HOSTARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' ) |
| 98 | +ARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' ) |
| 99 | + |
| 100 | +# Get ARCH from the compiler if cross compiling |
| 101 | +ifneq ($(CROSS_COMPILE),) |
| 102 | + override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' ) |
| 103 | +endif |
| 104 | + |
| 105 | +# FreeBSD (and possibly others) reports amd64 instead of x86_64 |
| 106 | +ifeq ($(ARCH),amd64) |
| 107 | + override ARCH := x86_64 |
| 108 | +endif |
| 109 | + |
| 110 | +# Allow UEFI shorthands to be specified for the arch |
| 111 | +ifeq ($(ARCH),x64) |
| 112 | + override ARCH := x86_64 |
| 113 | +endif |
| 114 | +ifeq ($(ARCH),mips64) |
| 115 | + override ARCH := mips64el |
| 116 | +endif |
| 117 | + |
| 118 | +GCCVERSION := $(shell $(CC) -dumpversion | sed -e 's/-win32/.0/' | cut -f1 -d.) |
| 119 | +GCCMINOR := $(shell $(CC) -dumpversion | sed -e 's/-win32/.0/' | cut -f2 -d.) |
| 120 | +USING_CLANG := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang || echo 0) |
| 121 | +NO_GLIBC ?= 0 |
| 122 | + |
| 123 | +# Rely on GCC MS ABI support? |
| 124 | +GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ] \ |
| 125 | + || ( [ $(GCCVERSION) -eq "4" ] \ |
| 126 | + && [ $(GCCMINOR) -ge "7" ] ) ) \ |
| 127 | + && echo 1) |
| 128 | + |
| 129 | +PART_ONE = $(shell echo "$(1)" | cut -f1 -d.) |
| 130 | +PART_TWO = $(shell echo "$(1)" | cut -f2 -d.) |
| 131 | + |
| 132 | +IS_NEW_ENOUGH = $(shell ( [ $(call PART_ONE,$(1)) -gt "$(2)" ] \ |
| 133 | + || ( [ $(call PART_ONE,$(1)) -eq "$(2)" ] \ |
| 134 | + && [ $(call PART_TWO,$(1)) -ge "$(3)" ] ) ) \ |
| 135 | + && echo 1) |
| 136 | + |
| 137 | +# |
| 138 | +# Where to build the package |
| 139 | +# |
| 140 | +OBJDIR := $(TOPDIR)/$(ARCH) |
| 141 | + |
| 142 | +# |
| 143 | +# Variables below derived from variables above |
| 144 | +# |
| 145 | + |
| 146 | +# Arch-specific compilation flags |
| 147 | +CPPFLAGS += -DCONFIG_$(ARCH) |
| 148 | + |
| 149 | +CFLAGS += -Wno-error=pragmas |
| 150 | + |
| 151 | +ifeq ($(ARCH),ia64) |
| 152 | + CFLAGS += -mfixed-range=f32-f127 |
| 153 | +endif |
| 154 | + |
| 155 | +ifeq ($(ARCH),ia32) |
| 156 | + CFLAGS += -mno-mmx -mno-sse |
| 157 | + ifeq ($(HOSTARCH),x86_64) |
| 158 | + ARCH3264 = -m32 |
| 159 | + endif |
| 160 | +endif |
| 161 | + |
| 162 | +# Set ISO C mode |
| 163 | +CPPFLAGS += -std=c11 |
| 164 | + |
| 165 | +ifeq ($(ARCH),x86_64) |
| 166 | + ifeq ($(GCCNEWENOUGH),1) |
| 167 | + CPPFLAGS += -DGNU_EFI_USE_MS_ABI |
| 168 | + ifneq ($(USING_CLANG),clang) |
| 169 | + CPPFLAGS += -maccumulate-outgoing-args |
| 170 | + endif |
| 171 | + endif |
| 172 | + |
| 173 | + CFLAGS += -mno-red-zone |
| 174 | + ifeq ($(HOSTARCH),ia32) |
| 175 | + ARCH3264 = -m64 |
| 176 | + endif |
| 177 | +endif |
| 178 | + |
| 179 | +ifneq (,$(filter $(ARCH),ia32 x86_64)) |
| 180 | + # Disable AVX, if the compiler supports that. |
| 181 | + CC_CAN_DISABLE_AVX=$(shell $(CC) -Werror -c -o /dev/null -xc -mno-avx - </dev/null >/dev/null 2>&1 && echo 1) |
| 182 | + ifeq ($(CC_CAN_DISABLE_AVX), 1) |
| 183 | + CFLAGS += -mno-avx |
| 184 | + endif |
| 185 | +endif |
| 186 | + |
| 187 | +ifeq ($(ARCH),mips64el) |
| 188 | + CFLAGS += -march=mips64r2 |
| 189 | + ARCH3264 = -mabi=64 |
| 190 | +endif |
| 191 | + |
| 192 | +# |
| 193 | +# Set HAVE_EFI_OBJCOPY if objcopy understands --target efi-[app|bsdrv|rtdrv], |
| 194 | +# otherwise we need to compose the PE/COFF header using the assembler |
| 195 | +# |
| 196 | + |
| 197 | +OBJCOPY_VERSION := $(shell $(OBJCOPY) --version | head -n 1 | awk '{print $$(NF)}') |
| 198 | + |
| 199 | +ifneq ($(ARCH),arm) |
| 200 | +ifneq ($(ARCH),mips64el) |
| 201 | +export HAVE_EFI_OBJCOPY=y |
| 202 | +endif |
| 203 | +endif |
| 204 | + |
| 205 | +ifeq ($(ARCH),riscv64) |
| 206 | +ifneq ($(call IS_NEW_ENOUGH,$(OBJCOPY_VERSION),2,42),1) |
| 207 | +export SYSTEM_HAS_EFI_OBJCOPY ?= 0 |
| 208 | +endif |
| 209 | +endif |
| 210 | + |
| 211 | +ifeq ($(ARCH),aarch64) |
| 212 | +ifneq ($(call IS_NEW_ENOUGH,$(OBJCOPY_VERSION),2,38),1) |
| 213 | +export SYSTEM_HAS_EFI_OBJCOPY ?= 0 |
| 214 | +endif |
| 215 | +endif |
| 216 | + |
| 217 | +ifeq ($(ARCH),ia32) |
| 218 | +ifeq ($(USING_APPLE),1) |
| 219 | +export SYSTEM_HAS_EFI_OBJCOPY ?= 0 |
| 220 | +endif |
| 221 | +endif |
| 222 | + |
| 223 | +ifeq ($(HAVE_EFI_OBJCOPY),y) |
| 224 | +export SYSTEM_HAS_EFI_OBJCOPY ?= 1 |
| 225 | +else |
| 226 | +export SYSTEM_HAS_EFI_OBJCOPY ?= 0 |
| 227 | +endif |
| 228 | + |
| 229 | + |
| 230 | +ifeq ($(USING_APPLE),1) |
| 231 | +CFLAGS += -D__GNU_EFI_NO_GLIBC |
| 232 | +endif |
| 233 | + |
| 234 | +ifeq ($(NO_GLIBC),1) |
| 235 | +CFLAGS += -D__GNU_EFI_NO_GLIBC |
| 236 | +endif |
| 237 | + |
| 238 | +ifeq ($(ARCH),arm) |
| 239 | +CFLAGS += -marm |
| 240 | +endif |
| 241 | + |
| 242 | +ifneq (,$(filter $(ARCH),aarch64 arm loongarch64)) |
| 243 | +LDFLAGS += -z common-page-size=4096 |
| 244 | +LDFLAGS += -z max-page-size=4096 |
| 245 | +endif |
| 246 | + |
| 247 | +# Generic compilation flags |
| 248 | +INCDIR += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \ |
| 249 | + -I$(TOPDIR)/inc/protocol |
| 250 | + |
| 251 | +# Only enable -fPIE for non MinGW compilers (unneeded on MinGW) |
| 252 | +GCCMACHINE := $(shell $(CC) -dumpmachine) |
| 253 | +IS_MINGW32 := $(findstring mingw32, $(GCCMACHINE)) |
| 254 | +ifeq ($(IS_MINGW32),) |
| 255 | + CFLAGS += -fPIE |
| 256 | +endif |
| 257 | + |
| 258 | +ifeq ($(USING_FREEBSD),1) |
| 259 | +CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \ |
| 260 | + -fno-strict-aliasing \ |
| 261 | + -ffreestanding -fno-stack-protector |
| 262 | +else |
| 263 | +CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \ |
| 264 | + -fno-strict-aliasing \ |
| 265 | + -ffreestanding -fno-stack-protector \ |
| 266 | + $(if $(findstring 0,$(USING_CLANG)),-Wno-error=maybe-uninitialized,) \ |
| 267 | + $(if $(findstring 0,$(USING_CLANG)),-fno-merge-all-constants,) |
| 268 | +endif |
| 269 | + |
| 270 | +# Force DWARF 4 on LLVM |
| 271 | +# Otherwise readelf becomes very unhappy |
| 272 | +ifeq ($(USING_CLANG),clang) |
| 273 | +CFLAGS += -gdwarf-4 |
| 274 | +endif |
| 275 | + |
| 276 | +# Force hard float (for library mismatch) |
| 277 | +ifeq ($(ARCH),arm) |
| 278 | +ifeq ($(USING_APPLE),1) |
| 279 | +CFLAGS += -mfloat-abi=hard -mfpu=vfpv2 |
| 280 | +endif |
| 281 | +endif |
| 282 | + |
| 283 | +ifeq ($(V),1) |
| 284 | +ARFLAGS := rDv |
| 285 | +else |
| 286 | +ARFLAGS := rD |
| 287 | +endif |
| 288 | +ASFLAGS += $(ARCH3264) |
| 289 | +LDFLAGS += -nostdlib |
| 290 | +ifeq ($(IS_MINGW32),) |
| 291 | + LDFLAGS += --warn-common --no-undefined --fatal-warnings \ |
| 292 | + --build-id=sha1 |
| 293 | + ifeq ($(USING_APPLE),0) |
| 294 | + LDFLAGS += -z norelro -z nocombreloc |
| 295 | + endif |
| 296 | +else |
| 297 | + LDFLAGS += -Wl,--warn-common -Wl,--no-undefined -Wl,--fatal-warnings \ |
| 298 | + -Wl,--build-id=sha1 |
| 299 | +endif |
| 300 | + |
| 301 | +ifneq ($(ARCH),arm) |
| 302 | +export LIBGCC=$(shell $(CC) $(CFLAGS) $(ARCH3264) -print-libgcc-file-name) |
| 303 | +endif |
0 commit comments