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