Make.defaults 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
  37. #
  38. # Variables below overridable from command-line:
  39. # make VARNAME=value ...
  40. #
  41. #
  42. # Where to install the package. GNU-EFI will create and access
  43. # lib and include under the root
  44. #
  45. DESTDIR ?= /
  46. ifeq ($(origin INSTALLROOT),undefined)
  47. INSTALLROOT = $(DESTDIR)
  48. endif
  49. empty :=
  50. space := $(empty) $(empty)
  51. stripped = $(subst $(space),/,$(strip $(subst /,$(space),$(1))))
  52. unstripped = $(subst $(space),/,$(subst /,$(space),$(1)))
  53. is_absolute = $(subst $(call stripped,$(1)),$(empty),$(call unstripped,$(1)))
  54. override INSTALLROOT:=$(if $(call is_absolute,$(INSTALLROOT)),,$(TOPDIR)/)$(INSTALLROOT)
  55. PREFIX := /usr/local
  56. LIBDIR := $(PREFIX)/lib
  57. INSTALL := install
  58. # Compilation tools
  59. HOSTCC := $(prefix)gcc
  60. CC := $(prefix)$(CROSS_COMPILE)gcc
  61. AS := $(prefix)$(CROSS_COMPILE)as
  62. LD := $(prefix)$(CROSS_COMPILE)ld
  63. AR := $(prefix)$(CROSS_COMPILE)ar
  64. RANLIB := $(prefix)$(CROSS_COMPILE)ranlib
  65. OBJCOPY := $(prefix)$(CROSS_COMPILE)objcopy
  66. # Host/target identification
  67. OS := $(shell uname -s)
  68. HOSTARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
  69. ARCH ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
  70. # Get ARCH from the compiler if cross compiling
  71. ifneq ($(CROSS_COMPILE),)
  72. override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed -e s,i[3456789]86,ia32, -e 's,armv[67].*,arm,' )
  73. endif
  74. # FreeBSD (and possibly others) reports amd64 instead of x86_64
  75. ifeq ($(ARCH),amd64)
  76. override ARCH := x86_64
  77. endif
  78. #
  79. # Where to build the package
  80. #
  81. OBJDIR := $(TOPDIR)/$(ARCH)
  82. #
  83. # Variables below derived from variables above
  84. #
  85. # Arch-specific compilation flags
  86. CPPFLAGS += -DCONFIG_$(ARCH)
  87. CFLAGS += -Wno-error=pragmas
  88. ifeq ($(ARCH),ia64)
  89. CFLAGS += -mfixed-range=f32-f127
  90. endif
  91. ifeq ($(ARCH),ia32)
  92. CFLAGS += -mno-mmx -mno-sse
  93. ifeq ($(HOSTARCH),x86_64)
  94. ARCH3264 = -m32
  95. endif
  96. endif
  97. ifeq ($(ARCH),x86_64)
  98. GCCVERSION := $(shell $(CC) -dumpversion | cut -f1 -d.)
  99. GCCMINOR := $(shell $(CC) -dumpversion | cut -f2 -d.)
  100. USING_CLANG := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang)
  101. # Rely on GCC MS ABI support?
  102. GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ] \
  103. || ( [ $(GCCVERSION) -eq "4" ] \
  104. && [ $(GCCMINOR) -ge "7" ] ) ) \
  105. && echo 1)
  106. ifeq ($(GCCNEWENOUGH),1)
  107. CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args --std=c11
  108. else ifeq ($(USING_CLANG),clang)
  109. CPPFLAGS += -DGNU_EFI_USE_MS_ABI --std=c11
  110. endif
  111. CFLAGS += -mno-red-zone
  112. ifeq ($(HOSTARCH),ia32)
  113. ARCH3264 = -m64
  114. endif
  115. endif
  116. ifneq (,$(filter $(ARCH),ia32 x86_64))
  117. # Disable AVX, if the compiler supports that.
  118. CC_CAN_DISABLE_AVX=$(shell $(CC) -Werror -c -o /dev/null -xc -mno-avx - </dev/null >/dev/null 2>&1 && echo 1)
  119. ifeq ($(CC_CAN_DISABLE_AVX), 1)
  120. CFLAGS += -mno-avx
  121. endif
  122. endif
  123. ifeq ($(ARCH),mips64el)
  124. CFLAGS += -march=mips64r2
  125. ARCH3264 = -mabi=64
  126. endif
  127. #
  128. # Set HAVE_EFI_OBJCOPY if objcopy understands --target efi-[app|bsdrv|rtdrv],
  129. # otherwise we need to compose the PE/COFF header using the assembler
  130. #
  131. ifneq ($(ARCH),arm)
  132. ifneq ($(ARCH),mips64el)
  133. ifneq ($(ARCH),riscv64)
  134. ifneq ($(ARCH),loongarch64)
  135. export HAVE_EFI_OBJCOPY=y
  136. endif
  137. endif
  138. endif
  139. endif
  140. ifneq ($(ARCH),arm)
  141. export LIBGCC=$(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
  142. endif
  143. ifeq ($(ARCH),arm)
  144. CFLAGS += -marm
  145. endif
  146. ifeq ($(ARCH),aarch64)
  147. LDFLAGS += -z common-page-size=4096
  148. LDFLAGS += -z max-page-size=4096
  149. endif
  150. # Generic compilation flags
  151. INCDIR += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \
  152. -I$(TOPDIR)/inc/protocol
  153. # Only enable -fPIE for non MinGW compilers (unneeded on MinGW)
  154. GCCMACHINE := $(shell $(CC) -dumpmachine)
  155. ifneq (mingw32,$(findstring mingw32, $(GCCMACHINE)))
  156. CFLAGS += -fPIE
  157. endif
  158. ifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
  159. CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
  160. -fshort-wchar -fno-strict-aliasing \
  161. -ffreestanding -fno-stack-protector
  162. else
  163. CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign -Werror \
  164. -fshort-wchar -fno-strict-aliasing \
  165. -ffreestanding -fno-stack-protector -fno-stack-check \
  166. -fno-stack-check \
  167. $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,)
  168. endif
  169. ARFLAGS := rDv
  170. ASFLAGS += $(ARCH3264)
  171. LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \
  172. --build-id=sha1