| 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 |
ARCHES = ia32 x86_64 ia64 aarch64 arm mips64el |
| 40 |
|
| 41 |
# |
| 42 |
# Variables below overridable from command-line: |
| 43 |
# make VARNAME=value ... |
| 44 |
# |
| 45 |
|
| 46 |
# |
| 47 |
# Where to install the package. GNU-EFI will create and access |
| 48 |
# lib and include under the root |
| 49 |
# |
| 50 |
DESTDIR ?= / |
| 51 |
ifeq ($(origin INSTALLROOT),undefined) |
| 52 |
INSTALLROOT = $(DESTDIR) |
| 53 |
endif |
| 54 |
|
| 55 |
empty := |
| 56 |
space := $(empty) $(empty) |
| 57 |
stripped = $(subst $(space),/,$(strip $(subst /,$(space),$(1)))) |
| 58 |
unstripped = $(subst $(space),/,$(subst /,$(space),$(1))) |
| 59 |
is_absolute = $(subst $(call stripped,$(1)),$(empty),$(call unstripped,$(1))) |
| 60 |
|
| 61 |
override INSTALLROOT:=$(if $(call is_absolute,$(INSTALLROOT)),,$(TOPDIR)/)$(INSTALLROOT) |
| 62 |
|
| 63 |
PREFIX := /usr/local |
| 64 |
LIBDIR := $(PREFIX)/lib |
| 65 |
INSTALL := install |
| 66 |
|
| 67 |
# Compilation tools |
| 68 |
COMPILER ?= gcc |
| 69 |
ARCHIVER ?= gcc-ar |
| 70 |
HOSTCC := $(COMPILER) |
| 71 |
CC := $(CROSS_COMPILE)$(COMPILER) |
| 72 |
AS := $(CROSS_COMPILE)as |
| 73 |
LD := $(CROSS_COMPILE)ld |
| 74 |
AR := $(CROSS_COMPILE)$(ARCHIVER) |
| 75 |
RANLIB := $(CROSS_COMPILE)ranlib |
| 76 |
OBJCOPY := $(CROSS_COMPILE)objcopy |
| 77 |
|
| 78 |
ifneq ($(CCACHE_DISABLE),) |
| 79 |
export CCACHE_DISABLE |
| 80 |
endif |
| 81 |
|
| 82 |
# Host/target identification |
| 83 |
OS := $(shell uname -s) |
| 84 |
HOSTARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' ) |
| 85 |
ARCH ?= $(shell $(CC) $(ARCH3264) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' ) |
| 86 |
|
| 87 |
# FreeBSD (and possibly others) reports amd64 instead of x86_64 |
| 88 |
ifeq ($(ARCH),amd64) |
| 89 |
override ARCH := x86_64 |
| 90 |
endif |
| 91 |
|
| 92 |
# |
| 93 |
# Where to build the package |
| 94 |
# |
| 95 |
OBJDIR := $(abspath .)/$(ARCH) |
| 96 |
|
| 97 |
# |
| 98 |
# Variables below derived from variables above |
| 99 |
# |
| 100 |
|
| 101 |
# Arch-specific compilation flags |
| 102 |
CPPFLAGS += -DCONFIG_$(ARCH) |
| 103 |
|
| 104 |
CFLAGS += -Wno-error=pragmas |
| 105 |
|
| 106 |
ifeq ($(ARCH),ia64) |
| 107 |
CFLAGS += -mfixed-range=f32-f127 |
| 108 |
endif |
| 109 |
|
| 110 |
ifeq ($(ARCH),ia32) |
| 111 |
CFLAGS += -mno-mmx -mno-sse |
| 112 |
ifeq ($(HOSTARCH),x86_64) |
| 113 |
ARCH3264 = -m32 |
| 114 |
endif |
| 115 |
endif |
| 116 |
|
| 117 |
ifeq ($(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 ($(USING_CLANG),clang) |
| 128 |
CPPFLAGS += -DGNU_EFI_USE_MS_ABI -DGNU_EFI_USE_EXTERNAL_STDARG --std=c11 |
| 129 |
else ifeq ($(GCCNEWENOUGH),1) |
| 130 |
CPPFLAGS += -DGNU_EFI_USE_MS_ABI -DGNU_EFI_USE_EXTERNAL_STDARG -maccumulate-outgoing-args --std=c11 |
| 131 |
endif |
| 132 |
|
| 133 |
CFLAGS += -mno-red-zone |
| 134 |
ifeq ($(HOSTARCH),ia32) |
| 135 |
ARCH3264 = -m64 |
| 136 |
endif |
| 137 |
endif |
| 138 |
|
| 139 |
ifneq (,$(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 |
| 145 |
endif |
| 146 |
|
| 147 |
ifeq ($(ARCH),mips64el) |
| 148 |
CFLAGS += -march=mips64r2 |
| 149 |
ARCH3264 = -mabi=64 |
| 150 |
endif |
| 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 |
# |
| 156 |
ifneq ($(ARCH),arm) |
| 157 |
ifneq ($(ARCH),mips64el) |
| 158 |
export HAVE_EFI_OBJCOPY=y |
| 159 |
endif |
| 160 |
endif |
| 161 |
|
| 162 |
ifeq ($(ARCH),arm) |
| 163 |
CFLAGS += -marm |
| 164 |
endif |
| 165 |
|
| 166 |
# Generic compilation flags |
| 167 |
INCDIR += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \ |
| 168 |
-I$(TOPDIR)/inc/protocol |
| 169 |
|
| 170 |
# Only enable -fpic for non MinGW compilers (unneeded on MinGW) |
| 171 |
GCCMACHINE := $(shell $(CC) -dumpmachine) |
| 172 |
ifneq (mingw32,$(findstring mingw32, $(GCCMACHINE))) |
| 173 |
CFLAGS += -fpic |
| 174 |
endif |
| 175 |
|
| 176 |
IS_FREEBSD = $(findstring FreeBSD, $(OS)) |
| 177 |
IS_DARWIN = $(findstring Darwin, $(OS)) |
| 178 |
|
| 179 |
WARNFLAGS ?= -Wall -Wextra |
| 180 |
WERRFLAGS ?= -Werror |
| 181 |
OPTIMIZATIONS ?= -O2 -g |
| 182 |
|
| 183 |
ifneq "$(or $(IS_FREEBSD), $(IS_DARWIN))" "" |
| 184 |
CFLAGS += $(ARCH3264) $(OPTIMIZATIONS) \ |
| 185 |
$(WARNFLAGS) $(WERRFLAGS) \ |
| 186 |
-fshort-wchar -fno-strict-aliasing \ |
| 187 |
-ffreestanding -fno-stack-protector |
| 188 |
else |
| 189 |
CFLAGS += $(ARCH3264) $(OPTIMIZATIONS) \ |
| 190 |
$(WARNFLAGS) $(WERRFLAGS) \ |
| 191 |
-fshort-wchar -fno-strict-aliasing \ |
| 192 |
-ffreestanding -fno-stack-protector \ |
| 193 |
-fno-stack-check -nostdinc \ |
| 194 |
$(CFLAGS_LTO) $(CFLAGS_GCOV) \ |
| 195 |
-isystem $(TOPDIR)/../include/system \ |
| 196 |
-isystem $(shell $(CC) $(ARCH3264) -print-file-name=include) \ |
| 197 |
$(if $(findstring gcc,$(CC)),-fno-merge-all-constants,) |
| 198 |
endif |
| 199 |
|
| 200 |
ifeq "$(IS_DARWIN)" "" |
| 201 |
ARFLAGS += -U |
| 202 |
else |
| 203 |
ARFLAGS := rDv |
| 204 |
endif |
| 205 |
|
| 206 |
ASFLAGS += $(ARCH3264) |
| 207 |
LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \ |
| 208 |
--build-id=sha1 --no-warn-rwx-segments |
| 209 |
|
| 210 |
ifneq ($(ARCH),arm) |
| 211 |
export LIBGCC=$(shell $(CC) $(CFLAGS) $(ARCH3264) -print-libgcc-file-name) |
| 212 |
endif |