xref: /DragonStub/Make.defaults (revision 787cb7fcd8954f8865249128d99626e4d2c0c252)
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#
48530d68baSNigel CroxonINSTALLROOT  := /
49530d68baSNigel CroxonPREFIX       := /usr/local
50530d68baSNigel CroxonLIBDIR 	     := $(PREFIX)/lib
51530d68baSNigel CroxonINSTALL	     := install
52530d68baSNigel Croxon
53530d68baSNigel Croxon# Compilation tools
54530d68baSNigel CroxonHOSTCC       := $(prefix)gcc
55530d68baSNigel CroxonCC           := $(prefix)$(CROSS_COMPILE)gcc
56530d68baSNigel CroxonAS           := $(prefix)$(CROSS_COMPILE)as
57530d68baSNigel CroxonLD           := $(prefix)$(CROSS_COMPILE)ld
58530d68baSNigel CroxonAR           := $(prefix)$(CROSS_COMPILE)ar
59530d68baSNigel CroxonRANLIB       := $(prefix)$(CROSS_COMPILE)ranlib
60530d68baSNigel CroxonOBJCOPY      := $(prefix)$(CROSS_COMPILE)objcopy
61530d68baSNigel Croxon
62530d68baSNigel Croxon
63530d68baSNigel Croxon# Host/target identification
64530d68baSNigel CroxonOS           := $(shell uname -s)
65530d68baSNigel CroxonHOSTARCH     := $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed s,i[3456789]86,ia32,)
66530d68baSNigel CroxonARCH         := $(HOSTARCH)
67530d68baSNigel Croxon
68530d68baSNigel Croxon# Get ARCH from the compiler if cross compiling
69530d68baSNigel Croxonifneq ($(CROSS_COMPILE),)
70530d68baSNigel Croxon  override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed s,i[3456789]86,ia32,)
71530d68baSNigel Croxonendif
72530d68baSNigel Croxon
73530d68baSNigel Croxon# FreeBSD (and possibly others) reports amd64 instead of x86_64
74530d68baSNigel Croxonifeq ($(ARCH),amd64)
75530d68baSNigel Croxon  override ARCH := x86_64
76530d68baSNigel Croxonendif
77530d68baSNigel Croxon
78530d68baSNigel Croxon#
79ce7098fbSNigel Croxon# Where to build the package
80ce7098fbSNigel Croxon#
81ce7098fbSNigel CroxonOBJDIR       := $(TOPDIR)/$(ARCH)
82ce7098fbSNigel Croxon
83ce7098fbSNigel Croxon#
84530d68baSNigel Croxon# Variables below derived from variables above
85530d68baSNigel Croxon#
86530d68baSNigel Croxon
87530d68baSNigel Croxon# Arch-specific compilation flags
88530d68baSNigel CroxonCPPFLAGS += -DCONFIG_$(ARCH)
89530d68baSNigel Croxon
90530d68baSNigel Croxonifeq ($(ARCH),ia64)
91530d68baSNigel Croxon  CFLAGS += -mfixed-range=f32-f127
92530d68baSNigel Croxonendif
93530d68baSNigel Croxon
94530d68baSNigel Croxonifeq ($(ARCH),ia32)
95530d68baSNigel Croxon  CFLAGS += -mno-mmx -mno-sse
96530d68baSNigel Croxon  ifeq ($(HOSTARCH),x86_64)
97530d68baSNigel Croxon    ARCH3264 = -m32
98530d68baSNigel Croxon  endif
99530d68baSNigel Croxonendif
100530d68baSNigel Croxon
101530d68baSNigel Croxonifeq ($(ARCH),x86_64)
102530d68baSNigel Croxon  GCCVERSION   := $(shell $(CC) -dumpversion | cut -f1 -d.)
103530d68baSNigel Croxon  GCCMINOR     := $(shell $(CC) -dumpversion | cut -f2 -d.)
104*787cb7fcSNigel Croxon  USING_CLANG  := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang)
105530d68baSNigel Croxon
106530d68baSNigel Croxon  # Rely on GCC MS ABI support?
107530d68baSNigel Croxon  GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ]           \
108530d68baSNigel Croxon                            || ( [ $(GCCVERSION) -eq "4" ]      \
109530d68baSNigel Croxon                                 && [ $(GCCMINOR) -ge "7" ] ) ) \
110530d68baSNigel Croxon                          && echo 1)
111530d68baSNigel Croxon  ifeq ($(GCCNEWENOUGH),1)
112530d68baSNigel Croxon    CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args --std=c11
113*787cb7fcSNigel Croxon  else ifeq ($(USING_CLANG),clang)
114*787cb7fcSNigel Croxon    CPPFLAGS += -DGNU_EFI_USE_MS_ABI --std=c11
115530d68baSNigel Croxon  endif
116530d68baSNigel Croxon
117b2c4db06SNigel Croxon  CFLAGS += -mno-red-zone
118530d68baSNigel Croxon  ifeq ($(HOSTARCH),ia32)
119530d68baSNigel Croxon    ARCH3264 = -m64
120530d68baSNigel Croxon  endif
121530d68baSNigel Croxonendif
122530d68baSNigel Croxon
1233f234f5bSNigel Croxonifeq ($(ARCH),mips64el)
1243f234f5bSNigel Croxon  CFLAGS += -march=mips64r2
1253f234f5bSNigel Croxon  ARCH3264 = -mabi=64
1263f234f5bSNigel Croxonendif
1273f234f5bSNigel Croxon
128530d68baSNigel Croxon#
129530d68baSNigel Croxon# Set HAVE_EFI_OBJCOPY if objcopy understands --target efi-[app|bsdrv|rtdrv],
130530d68baSNigel Croxon# otherwise we need to compose the PE/COFF header using the assembler
131530d68baSNigel Croxon#
132530d68baSNigel Croxonifneq ($(ARCH),aarch64)
133530d68baSNigel Croxonifneq ($(ARCH),arm)
1343f234f5bSNigel Croxonifneq ($(ARCH),mips64el)
135530d68baSNigel Croxonexport HAVE_EFI_OBJCOPY=y
136530d68baSNigel Croxonendif
137530d68baSNigel Croxonendif
1383f234f5bSNigel Croxonendif
139530d68baSNigel Croxon
140530d68baSNigel Croxonifneq ($(ARCH),arm)
141530d68baSNigel Croxonexport LIBGCC=$(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
142530d68baSNigel Croxonendif
143530d68baSNigel Croxon
144530d68baSNigel Croxonifeq ($(ARCH),arm)
145530d68baSNigel CroxonCFLAGS += -marm
146530d68baSNigel Croxonendif
147530d68baSNigel Croxon
148530d68baSNigel Croxon# Generic compilation flags
149530d68baSNigel CroxonINCDIR  += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \
150530d68baSNigel Croxon           -I$(TOPDIR)/inc/protocol
151530d68baSNigel Croxon
15250b88377SNigel Croxon# Only enable -fpic for non MinGW compilers (unneeded on MinGW)
15350b88377SNigel CroxonGCCMACHINE := $(shell $(CC) -dumpmachine)
15450b88377SNigel Croxonifneq (mingw32,$(findstring mingw32, $(GCCMACHINE)))
15550b88377SNigel Croxon  CFLAGS += -fpic
15650b88377SNigel Croxonendif
15750b88377SNigel Croxon
158530d68baSNigel Croxonifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
15950b88377SNigel CroxonCFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
160a213b514SNigel Croxon           -fshort-wchar -fno-strict-aliasing \
161530d68baSNigel Croxon           -ffreestanding -fno-stack-protector
162530d68baSNigel Croxonelse
16350b88377SNigel CroxonCFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
164a213b514SNigel Croxon           -fshort-wchar -fno-strict-aliasing \
165*787cb7fcSNigel Croxon           -fno-merge-all-constants -ffreestanding -fno-stack-protector \
166530d68baSNigel Croxon           -fno-stack-check
167530d68baSNigel Croxonendif
168530d68baSNigel Croxon
169bd38ba4bSNigel CroxonARFLAGS += -U
170530d68baSNigel CroxonASFLAGS += $(ARCH3264)
17111a459baSNigel CroxonLDFLAGS	+= -nostdlib --warn-common --no-undefined --fatal-warnings \
17211a459baSNigel Croxon	   --build-id=sha1
173