X-Git-Url: https://code.delx.au/refind/blobdiff_plain/a0bab7e95672ae7438f7fdb806b9b167a5b04e07..c63e9bd427f945b881d337b9fd5d3ff8612f103f:/Make.common diff --git a/Make.common b/Make.common index 2cf75b8..1ebce50 100644 --- a/Make.common +++ b/Make.common @@ -3,84 +3,171 @@ # Common make rules for building with gnu-efi # +# This program is licensed under the terms of the GNU GPL, version 3, +# or (at your option) any later version. +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file contains make definitions common to several (or all) of the make +# files in the rEFInd code subdirectories. Some options are specific to +# particular architectures or build systems and others are more universal. + +# +# Environment definitions -- where stuff is and what sort of system is being +# used to compile rEFInd.... +# + EFIINC = /usr/include/efi GNUEFILIB = /usr/lib EFILIB = /usr/lib EFICRT0 = /usr/lib -HOSTARCH = $(shell uname -m | sed s,i[3456789]86,ia32,) -ARCH := $(HOSTARCH) -OS = $(shell uname -s) -CPPFLAGS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I../include -I../refind -I../libeg -DCONFIG_$(ARCH) -D__MAKEWITH_GNUEFI +# Comment out above and uncomment below if using locally-compiled GNU-EFI.... +#EFIINC = /usr/local/include/efi +#GNUEFILIB = /usr/local/lib +#EFILIB = /usr/local/lib +#EFICRT0 = /usr/local/lib -OPTIMFLAGS = -O2 -fno-strict-aliasing -DEBUGFLAGS = -Wall -#CFLAGS = $(ARCH3264) $(OPTIMFLAGS) -fpic -fshort-wchar $(DEBUGFLAGS) -CFLAGS = $(ARCH3264) $(OPTIMFLAGS) -fno-stack-protector -fpic -fshort-wchar -mno-red-zone $(DEBUGFLAGS) -ASFLAGS = $(ARCH3264) -LDFLAGS = -nostdlib -znocombreloc +HOSTARCH = $(shell uname -m | sed s,i[3456789]86,ia32,) +ARCH ?= $(HOSTARCH) +# Note: EDK2BASE is definted in master Makefile and exported +#EDK2BASE = /usr/local/UDK2014/MyWorkSpace +GENFW = $(EDK2BASE)/BaseTools/Source/C/bin/GenFw prefix = /usr/bin/ -CC = $(prefix)gcc -AS = $(prefix)as -LD = $(prefix)ld -AR = $(prefix)ar -RANLIB = $(prefix)ranlib -OBJCOPY = $(prefix)objcopy - -ifeq ($(ARCH),ia64) - # EFI specs allows only lower floating point partition to be used - CFLAGS += -frename-registers -mfixed-range=f32-f127 +ifeq ($(ARCH),aarch64) + CC = $(prefix)aarch64-linux-gnu-gcc + AS = $(prefix)aarch64-linux-gnu-as + LD = $(prefix)aarch64-linux-gnu-ld + AR = $(prefix)aarch64-linux-gnu-ar + RANLIB = $(prefix)aarch64-linux-gnu-ranlib + OBJCOPY = $(prefix)aarch64-linux-gnu-objcopy +else + CC = $(prefix)gcc + AS = $(prefix)as + LD = $(prefix)ld + AR = $(prefix)ar + RANLIB = $(prefix)ranlib + OBJCOPY = $(prefix)objcopy endif -ifeq ($(ARCH),x86_64) - CFLAGS += -DEFI_FUNCTION_WRAPPER - CPPFLAGS += -DEFIX64 +ifeq ($(MAKEWITH),TIANO) +# Below file defines TARGET (RELEASE or DEBUG) and TOOL_CHAIN_TAG (GCC44, GCC45, GCC46, or GCC47) +include $(EDK2BASE)/Conf/target.txt +endif - ifeq ($(HOSTARCH),ia32) - ARCH3264 = -m64 +# +# C compiler flags +# - GNUEFILIB := $(GNUEFILIB)64 - EFILIB := $(EFILIB)64 - EFICRT0 := $(EFICRT0)64 - endif +# ...for both GNU-EFI and TianoCore.... +OPTIMFLAGS = -Os -fno-strict-aliasing +CFLAGS = $(OPTIMFLAGS) -fno-stack-protector -fshort-wchar -Wall + +# ...for GNU-EFI.... +GNUEFI_CFLAGS = -fpic -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I../include -I../refind -I../libeg -I../mok + +# ...and for TianoCore.... +TIANO_INCLUDE_DIRS = -I $(EDK2BASE)/MdePkg \ + -I $(EDK2BASE)/MdePkg/Include \ + -I $(EDK2BASE)/MdeModulePkg/ \ + -I $(EDK2BASE)/MdeModulePkg/Include \ + -I $(EDK2BASE)/IntelFrameworkPkg/Include \ + -I $(EDK2BASE)/MdePkg/Include/$(ARCHDIR) \ + -I .. \ + -I ../refind \ + -I ../libeg \ + -I ../include \ + -I ../mok +# +# Linker flags +# + +# for GNU-EFI.... +SUBSYSTEM_LDFLAG = +GNUEFI_LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds +CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o +GNUEFI_LDFLAGS = -T $(GNUEFI_LDSCRIPT) -shared -Bsymbolic -nostdlib -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS) +GNUEFI_LIBS = -lefi -lgnuefi $(shell $(CC) -print-libgcc-file-name) +#LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name) + +# ...and for TianoCore.... +ENTRYPOINT=efi_main +TIANO_LDSCRIPT = $(EDK2BASE)/BaseTools/Scripts/gcc4.4-ld-script +TIANO_LDFLAGS = -nostdlib -n -q --gc-sections --script=$(EDK2BASE)/BaseTools/Scripts/gcc4.4-ld-script \ + --entry $(ENTRYPOINT) -u $(ENTRYPOINT) -m $(LD_CODE) + +# +# objcopy flags for GNU-EFI +# + +FORMAT = --target=efi-app-$(ARCH) +FORMAT_DRIVER = --target=efi-bsdrv-$(ARCH) + +# +# Modifications on a per-architecture basis.... +# + +ifeq ($(ARCH),x86_64) + GNUEFI_LDFLAGS += -znocombreloc -zdefs + + ARCH_CFLAGS = -DEFIX64 -DEFI_FUNCTION_WRAPPER -m64 -mno-red-zone +ifeq ($(MAKEWITH),TIANO) + ARCH_CFLAGS += -mcmodel=large "-DEFIAPI=__attribute__((ms_abi))" +endif + ARCHDIR = X64 + UC_ARCH = X64 + FILENAME_CODE = x64 + LD_CODE = elf_x86_64 endif ifeq ($(ARCH),ia32) - CPPFLAGS += -DEFI32 -malign-double + GNUEFI_LDFLAGS += -znocombreloc -zdefs + # In practice, cross-compiling filesystem drivers works, but not the main + # rEFInd binary.... ifeq ($(HOSTARCH),x86_64) - ARCH3264 = -m32 - GNUEFILIB := $(GNUEFILIB)32 EFILIB := $(EFILIB)32 EFICRT0 := $(EFICRT0)32 endif -endif - -CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o - -ifneq (,$(findstring FreeBSD,$(OS))) - ifeq ($(ARCH),x86_64) - LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_fbsd_efi.lds - else - LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds - endif -else - LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds + ARCH_CFLAGS = -m32 -DEFI32 -malign-double + ARCHDIR = Ia32 + UC_ARCH = IA32 + FILENAME_CODE = ia32 + LD_CODE = elf_i386 endif -LDFLAGS += -T $(LDSCRIPT) -shared -Bsymbolic -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS) -LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name) -FORMAT = efi-app-$(ARCH) -FORMAT_DRIVER = efi-bsdrv-$(ARCH) +ifeq ($(ARCH), aarch64) + GNUEFI_CFLAGS += -DEFIAARCH64 + FORMAT = -O binary + FORMAT_DRIVER = -O binary + SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xa + LDFLAGS += --warn-common --no-undefined --fatal-warnings + ARCH_CFLAGS = -fno-merge-constants -ffreestanding -DEFIAARCH64 + ifeq ($(MAKEWITH),TIANO) + ARCH_CFLAGS += -mcmodel=large -Wno-address -Wno-missing-braces -Wno-array-bounds -ffunction-sections -fdata-sections + endif + ifeq ($(MAKEWITH),GNUEFI) + ARCH_CFLAGS += -fno-stack-check + endif + ARCHDIR = AArch64 + UC_ARCH = AARCH64 + FILENAME_CODE = aa64 + LD_CODE = aarch64elf +endif -# general rules +# GNU-EFI compilation path uses .o files for compiled object code +%.o: %.c + $(CC) $(CFLAGS) $(ARCH_CFLAGS) $(GNUEFI_CFLAGS) $(LOCAL_GNUEFI_CFLAGS) \ + -D__MAKEWITH_GNUEFI -DREFIND_VERSION=$(REFIND_VERSION) -c $< -o $@ -%.o: %.c - $(CC) $(LOCAL_CPPFLAGS) $(CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) -c $< -o $@ +# TianoCore compilation path uses .obj files for compiled object code +%.obj: %.c + $(CC) $(CFLAGS) $(ARCH_CFLAGS) $(TIANO_INCLUDE_DIRS) -DNO_BUILTIN_VA_FUNCS \ + -D__MAKEWITH_TIANO -DREFIND_VERSION=$(REFIND_VERSION) -c $< -o $@ # rules for EFI applications @@ -88,15 +175,9 @@ ifneq (,$(filter %.efi,$(TARGET))) SHLIB_TARGET = $(subst .efi,.so,$(TARGET)) -$(SHLIB_TARGET): $(OBJS) - $(LD) $(LOCAL_LDFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LOCAL_LIBS) $(LIBS) - -#$(TARGET): $(SHLIB_TARGET) -# $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \ -# -j .rela -j .reloc --target=$(FORMAT) $< $@ - endif + # rules for libraries ifneq (,$(filter %.a,$(TARGET))) @@ -108,7 +189,7 @@ endif # utility rules -clean: - rm -f $(TARGET) *~ *.so $(OBJS) *.efi *.obj refind_*.txt refind_*.dll *.lib +#clean: +# rm -f $(TARGET) *~ *.so $(OBJS) *.efi *.obj refind_*.txt refind_*.dll *.lib # EOF