xref: /DragonStub/Make.defaults (revision f412fd2a1a248b546b7085648dece8d908077fab)
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
92GCCVERSION   := $(shell $(CC) -dumpversion | cut -f1 -d.)
93GCCMINOR     := $(shell $(CC) -dumpversion | cut -f2 -d.)
94USING_CLANG  := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang)
95
96# Rely on GCC MS ABI support?
97GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ]           \
98                          || ( [ $(GCCVERSION) -eq "4" ]      \
99                          && [ $(GCCMINOR) -ge "7" ] ) ) \
100                          && echo 1)
101
102#
103# Where to build the package
104#
105OBJDIR       := $(TOPDIR)/$(ARCH)
106
107#
108# Variables below derived from variables above
109#
110
111# Arch-specific compilation flags
112CPPFLAGS += -DCONFIG_$(ARCH) -DCONFIG_64BIT
113
114CFLAGS += -Wno-error=pragmas
115
116ifeq ($(ARCH),ia64)
117  CFLAGS += -mfixed-range=f32-f127
118endif
119
120ifeq ($(ARCH),ia32)
121  CFLAGS += -mno-mmx -mno-sse
122  ifeq ($(HOSTARCH),x86_64)
123    ARCH3264 = -m32
124  endif
125endif
126
127# Set ISO C mode
128CPPFLAGS += -std=c11
129
130ifeq ($(ARCH),x86_64)
131  ifeq ($(GCCNEWENOUGH),1)
132    CPPFLAGS += -DGNU_EFI_USE_MS_ABI
133    ifneq ($(USING_CLANG),clang)
134      CPPFLAGS +=  -maccumulate-outgoing-args
135    endif
136  endif
137
138  CFLAGS += -mno-red-zone
139  ifeq ($(HOSTARCH),ia32)
140    ARCH3264 = -m64
141  endif
142endif
143
144ifneq (,$(filter $(ARCH),ia32 x86_64))
145  # Disable AVX, if the compiler supports that.
146  CC_CAN_DISABLE_AVX=$(shell $(CC) -Werror -c -o /dev/null -xc -mno-avx - </dev/null >/dev/null 2>&1 && echo 1)
147  ifeq ($(CC_CAN_DISABLE_AVX), 1)
148    CFLAGS += -mno-avx
149  endif
150endif
151
152ifeq ($(ARCH),mips64el)
153  CFLAGS += -march=mips64r2
154  ARCH3264 = -mabi=64
155endif
156
157#
158# Set HAVE_EFI_OBJCOPY if objcopy understands --target efi-[app|bsdrv|rtdrv],
159# otherwise we need to compose the PE/COFF header using the assembler
160#
161ifneq ($(ARCH),arm)
162ifneq ($(ARCH),mips64el)
163ifneq ($(ARCH),riscv64)
164ifneq ($(ARCH),loongarch64)
165export HAVE_EFI_OBJCOPY=y
166endif
167endif
168endif
169endif
170
171ifeq ($(ARCH),arm)
172CFLAGS += -marm
173endif
174
175ifneq (,$(filter $(ARCH),aarch64 arm))
176LDFLAGS += -z common-page-size=4096
177LDFLAGS += -z max-page-size=4096
178endif
179
180# Generic compilation flags
181INCDIR  += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \
182           -I$(TOPDIR)/inc/protocol
183
184# Only enable -fPIE for non MinGW compilers (unneeded on MinGW)
185GCCMACHINE := $(shell $(CC) -dumpmachine)
186ifneq (mingw32,$(findstring mingw32, $(GCCMACHINE)))
187  CFLAGS += -fPIE
188endif
189
190ifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
191CFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
192           -funsigned-char -fshort-wchar -fno-strict-aliasing \
193           -ffreestanding -fno-stack-protector
194else
195CFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign  \
196           -funsigned-char -fshort-wchar -fno-strict-aliasing \
197	   -ffreestanding -fno-stack-protector -fno-stack-check \
198           $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,)
199endif
200
201ARFLAGS := rDv
202ASFLAGS += $(ARCH3264)
203LDFLAGS	+= -nostdlib --warn-common --no-undefined --fatal-warnings \
204	   --build-id=sha1 -z nocombreloc
205
206ifneq ($(ARCH),arm)
207export LIBGCC=$(shell $(CC) $(CFLAGS) $(ARCH3264) -print-libgcc-file-name)
208endif
209