xref: /DragonStub/Make.defaults (revision cd78649395a16692d5bac0faaa91ac1aa2dca908)
1530d68baSNigel Croxon# -*- makefile -*-
2530d68baSNigel Croxon# Copyright (c) 1999-2007 Hewlett-Packard Development Company, L.P.
3530d68baSNigel Croxon#	Contributed by David Mosberger <davidm@hpl.hp.com>
4530d68baSNigel Croxon#	Contributed by Stephane Eranian <eranian@hpl.hp.com>
5530d68baSNigel Croxon#
6530d68baSNigel Croxon#    All rights reserved.
7530d68baSNigel Croxon#
8530d68baSNigel Croxon#    Redistribution and use in source and binary forms, with or without
9530d68baSNigel Croxon#    modification, are permitted provided that the following conditions
10530d68baSNigel Croxon#    are met:
11530d68baSNigel Croxon#
12530d68baSNigel Croxon#    * Redistributions of source code must retain the above copyright
13530d68baSNigel Croxon#      notice, this list of conditions and the following disclaimer.
14530d68baSNigel Croxon#    * Redistributions in binary form must reproduce the above
15530d68baSNigel Croxon#      copyright notice, this list of conditions and the following
16530d68baSNigel Croxon#      disclaimer in the documentation and/or other materials
17530d68baSNigel Croxon#      provided with the distribution.
18530d68baSNigel Croxon#    * Neither the name of Hewlett-Packard Co. nor the names of its
19530d68baSNigel Croxon#      contributors may be used to endorse or promote products derived
20530d68baSNigel Croxon#      from this software without specific prior written permission.
21530d68baSNigel Croxon#
22530d68baSNigel Croxon#    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23530d68baSNigel Croxon#    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24530d68baSNigel Croxon#    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25530d68baSNigel Croxon#    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26530d68baSNigel Croxon#    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
27530d68baSNigel Croxon#    BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28530d68baSNigel Croxon#    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29530d68baSNigel Croxon#    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30530d68baSNigel Croxon#    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31530d68baSNigel Croxon#    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
32530d68baSNigel Croxon#    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
33530d68baSNigel Croxon#    THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34530d68baSNigel Croxon#    SUCH DAMAGE.
35530d68baSNigel Croxon#
36530d68baSNigel Croxon
37530d68baSNigel CroxonTOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
38530d68baSNigel Croxon
39530d68baSNigel Croxon#
40530d68baSNigel Croxon# Variables below overridable from command-line:
41530d68baSNigel Croxon#   make VARNAME=value ...
42530d68baSNigel Croxon#
43530d68baSNigel Croxon
44530d68baSNigel Croxon#
45530d68baSNigel Croxon# Where to install the package. GNU-EFI will create and access
46530d68baSNigel Croxon# lib and include under the root
47530d68baSNigel Croxon#
484ee8cf56SPeter JonesDESTDIR ?= /
494ee8cf56SPeter Jonesifeq ($(origin INSTALLROOT),undefined)
504ee8cf56SPeter JonesINSTALLROOT = $(DESTDIR)
514ee8cf56SPeter Jonesendif
524ee8cf56SPeter Jones
534ee8cf56SPeter Jonesempty :=
544ee8cf56SPeter Jonesspace := $(empty) $(empty)
554ee8cf56SPeter Jonesstripped = $(subst $(space),/,$(strip $(subst /,$(space),$(1))))
564ee8cf56SPeter Jonesunstripped = $(subst $(space),/,$(subst /,$(space),$(1)))
574ee8cf56SPeter Jonesis_absolute = $(subst $(call stripped,$(1)),$(empty),$(call unstripped,$(1)))
584ee8cf56SPeter Jones
594ee8cf56SPeter Jonesoverride INSTALLROOT:=$(if $(call is_absolute,$(INSTALLROOT)),,$(TOPDIR)/)$(INSTALLROOT)
604ee8cf56SPeter Jones
61530d68baSNigel CroxonPREFIX       := /usr/local
6263a9a4d4SCallum FarmerEXEC_PREFIX  := $(PREFIX)
6363a9a4d4SCallum FarmerLIBDIR 	 := $(EXEC_PREFIX)/lib
6463a9a4d4SCallum FarmerINCLUDEDIR   := $(PREFIX)/include
65530d68baSNigel CroxonINSTALL	 := install
66530d68baSNigel Croxon
67530d68baSNigel Croxon# Compilation tools
68530d68baSNigel CroxonHOSTCC       := $(prefix)gcc
69530d68baSNigel CroxonCC           := $(prefix)$(CROSS_COMPILE)gcc
70530d68baSNigel CroxonAS           := $(prefix)$(CROSS_COMPILE)as
71530d68baSNigel CroxonLD           := $(prefix)$(CROSS_COMPILE)ld
72530d68baSNigel CroxonAR           := $(prefix)$(CROSS_COMPILE)ar
73530d68baSNigel CroxonRANLIB       := $(prefix)$(CROSS_COMPILE)ranlib
74530d68baSNigel CroxonOBJCOPY      := $(prefix)$(CROSS_COMPILE)objcopy
75530d68baSNigel Croxon
76530d68baSNigel Croxon
77530d68baSNigel Croxon# Host/target identification
78530d68baSNigel CroxonOS           := $(shell uname -s)
7944267b59SBen WolsiefferHOSTARCH     ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
8044267b59SBen WolsiefferARCH         ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
81530d68baSNigel Croxon
82530d68baSNigel Croxon# Get ARCH from the compiler if cross compiling
83530d68baSNigel Croxonifneq ($(CROSS_COMPILE),)
8444267b59SBen Wolsieffer  override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
85530d68baSNigel Croxonendif
86530d68baSNigel Croxon
87530d68baSNigel Croxon# FreeBSD (and possibly others) reports amd64 instead of x86_64
88530d68baSNigel Croxonifeq ($(ARCH),amd64)
89530d68baSNigel Croxon  override ARCH := x86_64
90530d68baSNigel Croxonendif
91530d68baSNigel Croxon
9253b89f52SCallum FarmerGCCVERSION   := $(shell $(CC) -dumpversion | cut -f1 -d.)
9353b89f52SCallum FarmerGCCMINOR     := $(shell $(CC) -dumpversion | cut -f2 -d.)
9453b89f52SCallum FarmerUSING_CLANG  := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang)
9553b89f52SCallum Farmer
9653b89f52SCallum Farmer# Rely on GCC MS ABI support?
9753b89f52SCallum FarmerGCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ]           \
9853b89f52SCallum Farmer                          || ( [ $(GCCVERSION) -eq "4" ]      \
9953b89f52SCallum Farmer                          && [ $(GCCMINOR) -ge "7" ] ) ) \
10053b89f52SCallum Farmer                          && echo 1)
10153b89f52SCallum Farmer
102530d68baSNigel Croxon#
103ce7098fbSNigel Croxon# Where to build the package
104ce7098fbSNigel Croxon#
105ce7098fbSNigel CroxonOBJDIR       := $(TOPDIR)/$(ARCH)
106ce7098fbSNigel Croxon
107ce7098fbSNigel Croxon#
108530d68baSNigel Croxon# Variables below derived from variables above
109530d68baSNigel Croxon#
110530d68baSNigel Croxon
111530d68baSNigel Croxon# Arch-specific compilation flags
112530d68baSNigel CroxonCPPFLAGS += -DCONFIG_$(ARCH)
113530d68baSNigel Croxon
114be57aadbSPeter JonesCFLAGS += -Wno-error=pragmas
115be57aadbSPeter Jones
116530d68baSNigel Croxonifeq ($(ARCH),ia64)
117530d68baSNigel Croxon  CFLAGS += -mfixed-range=f32-f127
118530d68baSNigel Croxonendif
119530d68baSNigel Croxon
120530d68baSNigel Croxonifeq ($(ARCH),ia32)
121530d68baSNigel Croxon  CFLAGS += -mno-mmx -mno-sse
122530d68baSNigel Croxon  ifeq ($(HOSTARCH),x86_64)
123530d68baSNigel Croxon    ARCH3264 = -m32
124530d68baSNigel Croxon  endif
125530d68baSNigel Croxonendif
126530d68baSNigel Croxon
12753b89f52SCallum Farmer# Set ISO C mode
12853b89f52SCallum FarmerCPPFLAGS += -std=c11
129530d68baSNigel Croxon
13053b89f52SCallum Farmerifeq ($(ARCH),x86_64)
131530d68baSNigel Croxon  ifeq ($(GCCNEWENOUGH),1)
13253b89f52SCallum Farmer    CPPFLAGS += -DGNU_EFI_USE_MS_ABI
13353b89f52SCallum Farmer    ifneq ($(USING_CLANG),clang)
13453b89f52SCallum Farmer      CPPFLAGS +=  -maccumulate-outgoing-args
13553b89f52SCallum Farmer    endif
136530d68baSNigel Croxon  endif
137530d68baSNigel Croxon
138b2c4db06SNigel Croxon  CFLAGS += -mno-red-zone
139530d68baSNigel Croxon  ifeq ($(HOSTARCH),ia32)
140530d68baSNigel Croxon    ARCH3264 = -m64
141530d68baSNigel Croxon  endif
142530d68baSNigel Croxonendif
143530d68baSNigel Croxon
14499d94682SNigel Croxonifneq (,$(filter $(ARCH),ia32 x86_64))
14599d94682SNigel Croxon  # Disable AVX, if the compiler supports that.
14699d94682SNigel Croxon  CC_CAN_DISABLE_AVX=$(shell $(CC) -Werror -c -o /dev/null -xc -mno-avx - </dev/null >/dev/null 2>&1 && echo 1)
14799d94682SNigel Croxon  ifeq ($(CC_CAN_DISABLE_AVX), 1)
14899d94682SNigel Croxon    CFLAGS += -mno-avx
14999d94682SNigel Croxon  endif
15099d94682SNigel Croxonendif
15199d94682SNigel Croxon
1523f234f5bSNigel Croxonifeq ($(ARCH),mips64el)
1533f234f5bSNigel Croxon  CFLAGS += -march=mips64r2
1543f234f5bSNigel Croxon  ARCH3264 = -mabi=64
1553f234f5bSNigel Croxonendif
1563f234f5bSNigel Croxon
157530d68baSNigel Croxon#
158530d68baSNigel Croxon# Set HAVE_EFI_OBJCOPY if objcopy understands --target efi-[app|bsdrv|rtdrv],
159530d68baSNigel Croxon# otherwise we need to compose the PE/COFF header using the assembler
160530d68baSNigel Croxon#
161530d68baSNigel Croxonifneq ($(ARCH),arm)
1623f234f5bSNigel Croxonifneq ($(ARCH),mips64el)
163b95f138fSHeinrich Schuchardtifneq ($(ARCH),riscv64)
164e7db4418Szhoumingtaoifneq ($(ARCH),loongarch64)
165530d68baSNigel Croxonexport HAVE_EFI_OBJCOPY=y
166530d68baSNigel Croxonendif
167530d68baSNigel Croxonendif
1683f234f5bSNigel Croxonendif
169b95f138fSHeinrich Schuchardtendif
170530d68baSNigel Croxon
171530d68baSNigel Croxonifeq ($(ARCH),arm)
172530d68baSNigel CroxonCFLAGS += -marm
173530d68baSNigel Croxonendif
174530d68baSNigel Croxon
175*cd786493SCallum Farmerifneq (,$(filter $(ARCH),aarch64 arm))
17604e6df70SCallum FarmerLDFLAGS += -z common-page-size=4096
17704e6df70SCallum FarmerLDFLAGS += -z max-page-size=4096
17804e6df70SCallum Farmerendif
17904e6df70SCallum Farmer
180530d68baSNigel Croxon# Generic compilation flags
181530d68baSNigel CroxonINCDIR  += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \
182530d68baSNigel Croxon           -I$(TOPDIR)/inc/protocol
183530d68baSNigel Croxon
184368cdf12SPeter Jones# Only enable -fPIE for non MinGW compilers (unneeded on MinGW)
18550b88377SNigel CroxonGCCMACHINE := $(shell $(CC) -dumpmachine)
18650b88377SNigel Croxonifneq (mingw32,$(findstring mingw32, $(GCCMACHINE)))
187368cdf12SPeter Jones  CFLAGS += -fPIE
18850b88377SNigel Croxonendif
18950b88377SNigel Croxon
190530d68baSNigel Croxonifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
19150b88377SNigel CroxonCFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
192e3987480SCallum Farmer           -funsigned-char -fshort-wchar -fno-strict-aliasing \
193530d68baSNigel Croxon           -ffreestanding -fno-stack-protector
194530d68baSNigel Croxonelse
195b9c4b23dSPeter JonesCFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign -Werror \
196e3987480SCallum Farmer           -funsigned-char -fshort-wchar -fno-strict-aliasing \
197f0bf464aSPeter Jones	   -ffreestanding -fno-stack-protector -fno-stack-check \
198f0bf464aSPeter Jones           -fno-stack-check \
199f0bf464aSPeter Jones           $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,)
200530d68baSNigel Croxonendif
201530d68baSNigel Croxon
202656e495dSPeter JonesARFLAGS := rDv
203530d68baSNigel CroxonASFLAGS += $(ARCH3264)
20411a459baSNigel CroxonLDFLAGS	+= -nostdlib --warn-common --no-undefined --fatal-warnings \
205486b1c20SCallum Farmer	   --build-id=sha1 -z nocombreloc
20698ef7f9fSPeter Jones
20798ef7f9fSPeter Jonesifneq ($(ARCH),arm)
20898ef7f9fSPeter Jonesexport LIBGCC=$(shell $(CC) $(CFLAGS) $(ARCH3264) -print-libgcc-file-name)
20998ef7f9fSPeter Jonesendif
210