Make.defaults 6.4 KB

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