1# -*- makefile -*- 2# Copyright (c) 1999-2007 Hewlett-Packard Development Company, L.P. 3# Contributed by David Mosberger <davidm@hpl.hp.com> 4# Contributed by Stephane Eranian <eranian@hpl.hp.com> 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 37TOPDIR := $(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# 48DESTDIR ?= / 49ifeq ($(origin INSTALLROOT),undefined) 50INSTALLROOT = $(DESTDIR) 51endif 52 53empty := 54space := $(empty) $(empty) 55stripped = $(subst $(space),/,$(strip $(subst /,$(space),$(1)))) 56unstripped = $(subst $(space),/,$(subst /,$(space),$(1))) 57is_absolute = $(subst $(call stripped,$(1)),$(empty),$(call unstripped,$(1))) 58 59override INSTALLROOT:=$(if $(call is_absolute,$(INSTALLROOT)),,$(TOPDIR)/)$(INSTALLROOT) 60 61PREFIX := /usr/local 62LIBDIR := $(PREFIX)/lib 63INSTALL := install 64 65# Compilation tools 66HOSTCC := $(prefix)gcc 67CC := $(prefix)$(CROSS_COMPILE)gcc 68AS := $(prefix)$(CROSS_COMPILE)as 69LD := $(prefix)$(CROSS_COMPILE)ld 70AR := $(prefix)$(CROSS_COMPILE)ar 71RANLIB := $(prefix)$(CROSS_COMPILE)ranlib 72OBJCOPY := $(prefix)$(CROSS_COMPILE)objcopy 73 74 75# Host/target identification 76OS := $(shell uname -s) 77HOSTARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' ) 78ARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' ) 79 80# Get ARCH from the compiler if cross compiling 81ifneq ($(CROSS_COMPILE),) 82 override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' ) 83endif 84 85# FreeBSD (and possibly others) reports amd64 instead of x86_64 86ifeq ($(ARCH),amd64) 87 override ARCH := x86_64 88endif 89 90# 91# Where to build the package 92# 93OBJDIR := $(TOPDIR)/$(ARCH) 94 95# 96# Variables below derived from variables above 97# 98 99# Arch-specific compilation flags 100CPPFLAGS += -DCONFIG_$(ARCH) 101 102CFLAGS += -Wno-error=pragmas 103 104ifeq ($(ARCH),ia64) 105 CFLAGS += -mfixed-range=f32-f127 106endif 107 108ifeq ($(ARCH),ia32) 109 CFLAGS += -mno-mmx -mno-sse 110 ifeq ($(HOSTARCH),x86_64) 111 ARCH3264 = -m32 112 endif 113endif 114 115ifeq ($(ARCH),x86_64) 116 GCCVERSION := $(shell $(CC) -dumpversion | cut -f1 -d.) 117 GCCMINOR := $(shell $(CC) -dumpversion | cut -f2 -d.) 118 USING_CLANG := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang) 119 120 # Rely on GCC MS ABI support? 121 GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ] \ 122 || ( [ $(GCCVERSION) -eq "4" ] \ 123 && [ $(GCCMINOR) -ge "7" ] ) ) \ 124 && echo 1) 125 ifeq ($(GCCNEWENOUGH),1) 126 CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args --std=c11 127 else ifeq ($(USING_CLANG),clang) 128 CPPFLAGS += -DGNU_EFI_USE_MS_ABI --std=c11 129 endif 130 131 CFLAGS += -mno-red-zone 132 ifeq ($(HOSTARCH),ia32) 133 ARCH3264 = -m64 134 endif 135endif 136 137ifneq (,$(filter $(ARCH),ia32 x86_64)) 138 # Disable AVX, if the compiler supports that. 139 CC_CAN_DISABLE_AVX=$(shell $(CC) -Werror -c -o /dev/null -xc -mno-avx - </dev/null >/dev/null 2>&1 && echo 1) 140 ifeq ($(CC_CAN_DISABLE_AVX), 1) 141 CFLAGS += -mno-avx 142 endif 143endif 144 145ifeq ($(ARCH),mips64el) 146 CFLAGS += -march=mips64r2 147 ARCH3264 = -mabi=64 148endif 149 150# 151# Set HAVE_EFI_OBJCOPY if objcopy understands --target efi-[app|bsdrv|rtdrv], 152# otherwise we need to compose the PE/COFF header using the assembler 153# 154ifneq ($(ARCH),arm) 155ifneq ($(ARCH),mips64el) 156ifneq ($(ARCH),riscv64) 157ifneq ($(ARCH),loongarch64) 158export HAVE_EFI_OBJCOPY=y 159endif 160endif 161endif 162endif 163 164ifneq ($(ARCH),arm) 165export LIBGCC=$(shell $(CC) $(ARCH3264) -print-libgcc-file-name) 166endif 167 168ifeq ($(ARCH),arm) 169CFLAGS += -marm 170endif 171 172ifeq ($(ARCH),aarch64) 173LDFLAGS += -z common-page-size=4096 174LDFLAGS += -z max-page-size=4096 175endif 176 177# Generic compilation flags 178INCDIR += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \ 179 -I$(TOPDIR)/inc/protocol 180 181# Only enable -fPIE for non MinGW compilers (unneeded on MinGW) 182GCCMACHINE := $(shell $(CC) -dumpmachine) 183ifneq (mingw32,$(findstring mingw32, $(GCCMACHINE))) 184 CFLAGS += -fPIE 185endif 186 187ifeq (FreeBSD, $(findstring FreeBSD, $(OS))) 188CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \ 189 -fshort-wchar -fno-strict-aliasing \ 190 -ffreestanding -fno-stack-protector 191else 192CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign -Werror \ 193 -fshort-wchar -fno-strict-aliasing \ 194 -ffreestanding -fno-stack-protector -fno-stack-check \ 195 -fno-stack-check \ 196 $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,) 197endif 198 199ARFLAGS := rDv 200ASFLAGS += $(ARCH3264) 201LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \ 202 --build-id=sha1 203