mirror of https://github.com/ipxe/ipxe.git
[build] Allow for per-architecture cross-compilation prefixes
We currently require the variable CROSS (or CROSS_COMPILE) to be set to specify the global cross-compilation prefix. This becomes cumbersome when developing across multiple CPU architectures, requiring frequent editing of build command lines and preventing incompatible architectures from being built with a single command. Allow a default cross-compilation prefix for each architecture to be specified via the CROSS_COMPILE_<arch> variables. These may then be provided as environment variables, e.g. using export CROSS_COMPILE_arm32=arm-linux-gnu- export CROSS_COMPILE_arm64=aarch64-linux-gnu- export CROSS_COMPILE_loong64=loongarch64-linux-gnu- export CROSS_COMPILE_riscv32=riscv64-linux-gnu- export CROSS_COMPILE_riscv64=riscv64-linux-gnu- This change requires some portions of the Makefile to be rearranged, to allow for the fact that $(CROSS_COMPILE) may not have been set until the build directory has been parsed to determine the CPU architecture. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1330/head
parent
19f44d2998
commit
8fc11d8a4a
20
src/Makefile
20
src/Makefile
|
@ -26,16 +26,16 @@ PRINTF := printf
|
||||||
PERL := perl
|
PERL := perl
|
||||||
PYTHON := python
|
PYTHON := python
|
||||||
TRUE := true
|
TRUE := true
|
||||||
CC := $(CROSS_COMPILE)gcc
|
CC = $(CROSS_COMPILE)gcc
|
||||||
CPP := $(CC) -E
|
CPP = $(CC) -E
|
||||||
AS := $(CROSS_COMPILE)as
|
AS = $(CROSS_COMPILE)as
|
||||||
LD := $(CROSS_COMPILE)ld
|
LD = $(CROSS_COMPILE)ld
|
||||||
SIZE := $(CROSS_COMPILE)size
|
SIZE = $(CROSS_COMPILE)size
|
||||||
AR := $(CROSS_COMPILE)ar
|
AR = $(CROSS_COMPILE)ar
|
||||||
RANLIB := $(CROSS_COMPILE)ranlib
|
RANLIB = $(CROSS_COMPILE)ranlib
|
||||||
OBJCOPY := $(CROSS_COMPILE)objcopy
|
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||||
NM := $(CROSS_COMPILE)nm
|
NM = $(CROSS_COMPILE)nm
|
||||||
OBJDUMP := $(CROSS_COMPILE)objdump
|
OBJDUMP = $(CROSS_COMPILE)objdump
|
||||||
OPENSSL := openssl
|
OPENSSL := openssl
|
||||||
CSPLIT := csplit
|
CSPLIT := csplit
|
||||||
PARSEROM := ./util/parserom.pl
|
PARSEROM := ./util/parserom.pl
|
||||||
|
|
|
@ -3,6 +3,20 @@
|
||||||
# This file contains various boring housekeeping functions that would
|
# This file contains various boring housekeeping functions that would
|
||||||
# otherwise seriously clutter up the main Makefile.
|
# otherwise seriously clutter up the main Makefile.
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# Make syntax does not allow use of comma or space in certain places.
|
||||||
|
# This ugly workaround is suggested in the manual.
|
||||||
|
#
|
||||||
|
COMMA := ,
|
||||||
|
EMPTY :=
|
||||||
|
SPACE := $(EMPTY) $(EMPTY)
|
||||||
|
HASH := \#
|
||||||
|
define NEWLINE
|
||||||
|
|
||||||
|
|
||||||
|
endef
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# Find a usable "echo -e" substitute.
|
# Find a usable "echo -e" substitute.
|
||||||
|
@ -68,56 +82,6 @@ HOST_OS := $(shell uname -s)
|
||||||
hostos :
|
hostos :
|
||||||
@$(ECHO) $(HOST_OS)
|
@$(ECHO) $(HOST_OS)
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
#
|
|
||||||
# Determine compiler
|
|
||||||
|
|
||||||
CCDEFS := $(shell $(CC) -E -x c -c /dev/null -dM | cut -d" " -f2)
|
|
||||||
ccdefs:
|
|
||||||
@$(ECHO) $(CCDEFS)
|
|
||||||
|
|
||||||
ifeq ($(filter __GNUC__,$(CCDEFS)),__GNUC__)
|
|
||||||
CCTYPE := gcc
|
|
||||||
endif
|
|
||||||
cctype:
|
|
||||||
@$(ECHO) $(CCTYPE)
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
#
|
|
||||||
# Check for tools that can cause failed builds
|
|
||||||
#
|
|
||||||
|
|
||||||
ifeq ($(CCTYPE),gcc)
|
|
||||||
GCC_2_96_BANNER := $(shell $(CC) -v 2>&1 | grep -is 'gcc version 2\.96')
|
|
||||||
ifneq ($(GCC_2_96_BANNER),)
|
|
||||||
$(warning gcc 2.96 is unsuitable for compiling iPXE)
|
|
||||||
$(warning Use gcc 2.95 or a newer version instead)
|
|
||||||
$(error Unsuitable build environment found)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
PERL_UNICODE_CHECK := $(shell $(PERL) -e 'use bytes; print chr(255)' | wc -c)
|
|
||||||
ifeq ($(PERL_UNICODE_CHECK),2)
|
|
||||||
$(warning Your Perl version has a Unicode handling bug)
|
|
||||||
$(warning Execute this command before building iPXE:)
|
|
||||||
$(warning export LANG=$${LANG%.UTF-8})
|
|
||||||
$(error Unsuitable build environment found)
|
|
||||||
endif
|
|
||||||
|
|
||||||
LD_GOLD_BANNER := $(shell $(LD) -v 2>&1 | grep 'GNU gold')
|
|
||||||
ifneq ($(LD_GOLD_BANNER),)
|
|
||||||
$(warning GNU gold is unsuitable for building iPXE)
|
|
||||||
$(warning Use GNU ld instead)
|
|
||||||
$(error Unsuitable build environment found)
|
|
||||||
endif
|
|
||||||
|
|
||||||
OBJCOPY_ETC_BANNER := $(shell $(OBJCOPY) --version | grep 'elftoolchain')
|
|
||||||
ifneq ($(OBJCOPY_ETC_BANNER),)
|
|
||||||
$(warning The elftoolchain objcopy is unsuitable for building iPXE)
|
|
||||||
$(warning Use binutils objcopy instead)
|
|
||||||
$(error Unsuitable build environment found)
|
|
||||||
endif
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# Check if $(eval ...) is available to use
|
# Check if $(eval ...) is available to use
|
||||||
|
@ -130,74 +94,6 @@ endif
|
||||||
eval :
|
eval :
|
||||||
@$(ECHO) $(HAVE_EVAL)
|
@$(ECHO) $(HAVE_EVAL)
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
#
|
|
||||||
# Check for various tool workarounds
|
|
||||||
#
|
|
||||||
|
|
||||||
WORKAROUND_CFLAGS :=
|
|
||||||
WORKAROUND_ASFLAGS :=
|
|
||||||
WORKAROUND_LDFLAGS :=
|
|
||||||
|
|
||||||
# Make syntax does not allow use of comma or space in certain places.
|
|
||||||
# This ugly workaround is suggested in the manual.
|
|
||||||
#
|
|
||||||
COMMA := ,
|
|
||||||
EMPTY :=
|
|
||||||
SPACE := $(EMPTY) $(EMPTY)
|
|
||||||
HASH := \#
|
|
||||||
define NEWLINE
|
|
||||||
|
|
||||||
|
|
||||||
endef
|
|
||||||
|
|
||||||
# gcc 4.4 generates .eh_frame sections by default, which distort the
|
|
||||||
# output of "size". Inhibit this.
|
|
||||||
#
|
|
||||||
ifeq ($(CCTYPE),gcc)
|
|
||||||
CFI_TEST = $(CC) -fno-dwarf2-cfi-asm -fno-exceptions -fno-unwind-tables \
|
|
||||||
-fno-asynchronous-unwind-tables -x c -c /dev/null \
|
|
||||||
-o /dev/null >/dev/null 2>&1
|
|
||||||
CFI_FLAGS := $(shell $(CFI_TEST) && \
|
|
||||||
$(ECHO) '-fno-dwarf2-cfi-asm -fno-exceptions ' \
|
|
||||||
'-fno-unwind-tables -fno-asynchronous-unwind-tables')
|
|
||||||
WORKAROUND_CFLAGS += $(CFI_FLAGS)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# gcc 4.6 generates spurious warnings if -Waddress is in force.
|
|
||||||
# Inhibit this.
|
|
||||||
#
|
|
||||||
ifeq ($(CCTYPE),gcc)
|
|
||||||
WNA_TEST = $(CC) -Waddress -x c -c /dev/null -o /dev/null >/dev/null 2>&1
|
|
||||||
WNA_FLAGS := $(shell $(WNA_TEST) && $(ECHO) '-Wno-address')
|
|
||||||
WORKAROUND_CFLAGS += $(WNA_FLAGS)
|
|
||||||
|
|
||||||
# gcc 8.0 generates warnings for certain suspect string operations. Our
|
|
||||||
# sources have been vetted for correct usage. Turn off these warnings.
|
|
||||||
#
|
|
||||||
WNST_TEST = $(CC) -Wstringop-truncation -x c -c /dev/null -o /dev/null \
|
|
||||||
>/dev/null 2>&1
|
|
||||||
WNST_FLAGS := $(shell $(WNST_TEST) && $(ECHO) '-Wno-stringop-truncation')
|
|
||||||
WORKAROUND_CFLAGS += $(WNST_FLAGS)
|
|
||||||
|
|
||||||
# gcc 9.1 generates warnings for taking address of packed member which
|
|
||||||
# may result in an unaligned pointer value. Inhibit the warnings.
|
|
||||||
#
|
|
||||||
WNAPM_TEST = $(CC) -Wno-address-of-packed-member -x c -c /dev/null \
|
|
||||||
-o /dev/null >/dev/null 2>&1
|
|
||||||
WNAPM_FLAGS := $(shell $(WNAPM_TEST) && \
|
|
||||||
$(ECHO) '-Wno-address-of-packed-member')
|
|
||||||
WORKAROUND_CFLAGS += $(WNAPM_FLAGS)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Some versions of gas choke on division operators, treating them as
|
|
||||||
# comment markers. Specifying --divide will work around this problem,
|
|
||||||
# but isn't available on older gas versions.
|
|
||||||
#
|
|
||||||
DIVIDE_TEST = $(AS) --divide /dev/null -o /dev/null 2>/dev/null
|
|
||||||
DIVIDE_FLAGS := $(shell $(DIVIDE_TEST) && $(ECHO) '--divide')
|
|
||||||
WORKAROUND_ASFLAGS += $(DIVIDE_FLAGS)
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# Build verbosity
|
# Build verbosity
|
||||||
|
@ -367,9 +263,124 @@ CFLAGS += -DSECUREBOOT=$(SECUREBOOT)
|
||||||
secureboot :
|
secureboot :
|
||||||
@$(ECHO) $(SECUREBOOT)
|
@$(ECHO) $(SECUREBOOT)
|
||||||
|
|
||||||
|
# Set cross-compilation prefix automatically if not specified
|
||||||
|
ifeq ($(CROSS_COMPILE),)
|
||||||
|
CROSS_COMPILE := $(CROSS_COMPILE_$(ARCH))
|
||||||
|
endif
|
||||||
|
|
||||||
endif # defined(BIN)
|
endif # defined(BIN)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# Determine compiler
|
||||||
|
|
||||||
|
CCDEFS := $(shell $(CC) -E -x c -c /dev/null -dM | cut -d" " -f2)
|
||||||
|
ccdefs:
|
||||||
|
@$(ECHO) $(CCDEFS)
|
||||||
|
|
||||||
|
ifeq ($(filter __GNUC__,$(CCDEFS)),__GNUC__)
|
||||||
|
CCTYPE := gcc
|
||||||
|
endif
|
||||||
|
cctype:
|
||||||
|
@$(ECHO) $(CCTYPE)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# Check for tools that can cause failed builds
|
||||||
|
#
|
||||||
|
|
||||||
|
ifeq ($(CCTYPE),gcc)
|
||||||
|
GCC_2_96_BANNER := $(shell $(CC) -v 2>&1 | grep -is 'gcc version 2\.96')
|
||||||
|
ifneq ($(GCC_2_96_BANNER),)
|
||||||
|
$(warning gcc 2.96 is unsuitable for compiling iPXE)
|
||||||
|
$(warning Use gcc 2.95 or a newer version instead)
|
||||||
|
$(error Unsuitable build environment found)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
PERL_UNICODE_CHECK := $(shell $(PERL) -e 'use bytes; print chr(255)' | wc -c)
|
||||||
|
ifeq ($(PERL_UNICODE_CHECK),2)
|
||||||
|
$(warning Your Perl version has a Unicode handling bug)
|
||||||
|
$(warning Execute this command before building iPXE:)
|
||||||
|
$(warning export LANG=$${LANG%.UTF-8})
|
||||||
|
$(error Unsuitable build environment found)
|
||||||
|
endif
|
||||||
|
|
||||||
|
LD_GOLD_BANNER := $(shell $(LD) -v 2>&1 | grep 'GNU gold')
|
||||||
|
ifneq ($(LD_GOLD_BANNER),)
|
||||||
|
$(warning GNU gold is unsuitable for building iPXE)
|
||||||
|
$(warning Use GNU ld instead)
|
||||||
|
$(error Unsuitable build environment found)
|
||||||
|
endif
|
||||||
|
|
||||||
|
OBJCOPY_ETC_BANNER := $(shell $(OBJCOPY) --version | grep 'elftoolchain')
|
||||||
|
ifneq ($(OBJCOPY_ETC_BANNER),)
|
||||||
|
$(warning The elftoolchain objcopy is unsuitable for building iPXE)
|
||||||
|
$(warning Use binutils objcopy instead)
|
||||||
|
$(error Unsuitable build environment found)
|
||||||
|
endif
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# Check for various tool workarounds
|
||||||
|
#
|
||||||
|
|
||||||
|
WORKAROUND_CFLAGS :=
|
||||||
|
WORKAROUND_ASFLAGS :=
|
||||||
|
WORKAROUND_LDFLAGS :=
|
||||||
|
|
||||||
|
# gcc 4.4 generates .eh_frame sections by default, which distort the
|
||||||
|
# output of "size". Inhibit this.
|
||||||
|
#
|
||||||
|
ifeq ($(CCTYPE),gcc)
|
||||||
|
CFI_TEST = $(CC) -fno-dwarf2-cfi-asm -fno-exceptions -fno-unwind-tables \
|
||||||
|
-fno-asynchronous-unwind-tables -x c -c /dev/null \
|
||||||
|
-o /dev/null >/dev/null 2>&1
|
||||||
|
CFI_FLAGS := $(shell $(CFI_TEST) && \
|
||||||
|
$(ECHO) '-fno-dwarf2-cfi-asm -fno-exceptions ' \
|
||||||
|
'-fno-unwind-tables -fno-asynchronous-unwind-tables')
|
||||||
|
WORKAROUND_CFLAGS += $(CFI_FLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# gcc 4.6 generates spurious warnings if -Waddress is in force.
|
||||||
|
# Inhibit this.
|
||||||
|
#
|
||||||
|
ifeq ($(CCTYPE),gcc)
|
||||||
|
WNA_TEST = $(CC) -Waddress -x c -c /dev/null -o /dev/null >/dev/null 2>&1
|
||||||
|
WNA_FLAGS := $(shell $(WNA_TEST) && $(ECHO) '-Wno-address')
|
||||||
|
WORKAROUND_CFLAGS += $(WNA_FLAGS)
|
||||||
|
|
||||||
|
# gcc 8.0 generates warnings for certain suspect string operations. Our
|
||||||
|
# sources have been vetted for correct usage. Turn off these warnings.
|
||||||
|
#
|
||||||
|
WNST_TEST = $(CC) -Wstringop-truncation -x c -c /dev/null -o /dev/null \
|
||||||
|
>/dev/null 2>&1
|
||||||
|
WNST_FLAGS := $(shell $(WNST_TEST) && $(ECHO) '-Wno-stringop-truncation')
|
||||||
|
WORKAROUND_CFLAGS += $(WNST_FLAGS)
|
||||||
|
|
||||||
|
# gcc 9.1 generates warnings for taking address of packed member which
|
||||||
|
# may result in an unaligned pointer value. Inhibit the warnings.
|
||||||
|
#
|
||||||
|
WNAPM_TEST = $(CC) -Wno-address-of-packed-member -x c -c /dev/null \
|
||||||
|
-o /dev/null >/dev/null 2>&1
|
||||||
|
WNAPM_FLAGS := $(shell $(WNAPM_TEST) && \
|
||||||
|
$(ECHO) '-Wno-address-of-packed-member')
|
||||||
|
WORKAROUND_CFLAGS += $(WNAPM_FLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Some versions of gas choke on division operators, treating them as
|
||||||
|
# comment markers. Specifying --divide will work around this problem,
|
||||||
|
# but isn't available on older gas versions.
|
||||||
|
#
|
||||||
|
DIVIDE_TEST = $(AS) --divide /dev/null -o /dev/null 2>/dev/null
|
||||||
|
DIVIDE_FLAGS := $(shell $(DIVIDE_TEST) && $(ECHO) '--divide')
|
||||||
|
WORKAROUND_ASFLAGS += $(DIVIDE_FLAGS)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
# Include architecture-specific Makefile
|
# Include architecture-specific Makefile
|
||||||
|
#
|
||||||
|
|
||||||
ifdef ARCH
|
ifdef ARCH
|
||||||
MAKEDEPS += arch/$(ARCH)/Makefile
|
MAKEDEPS += arch/$(ARCH)/Makefile
|
||||||
include arch/$(ARCH)/Makefile
|
include arch/$(ARCH)/Makefile
|
||||||
|
|
Loading…
Reference in New Issue