X-Git-Url: https://code.delx.au/refind/blobdiff_plain/1ecb53a60573127a4cc976980053adda3bb5e089..c63e9bd427f945b881d337b9fd5d3ff8612f103f:/Make.common diff --git a/Make.common b/Make.common index 4f44053..1ebce50 100644 --- a/Make.common +++ b/Make.common @@ -3,6 +3,20 @@ # 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 @@ -15,91 +29,145 @@ EFICRT0 = /usr/lib #EFICRT0 = /usr/local/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 - -OPTIMFLAGS = -O2 -fno-strict-aliasing -DEBUGFLAGS = -Wall -#CFLAGS = $(ARCH3264) $(OPTIMFLAGS) -fpic -fshort-wchar $(DEBUGFLAGS) -CFLAGS = $(ARCH3264) $(OPTIMFLAGS) -fno-stack-protector -fpic -fshort-wchar $(DEBUGFLAGS) -ASFLAGS = $(ARCH3264) -LDFLAGS = -nostdlib -DRV_LDFLAGS = +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 ($(MAKEWITH),TIANO) +# Below file defines TARGET (RELEASE or DEBUG) and TOOL_CHAIN_TAG (GCC44, GCC45, GCC46, or GCC47) +include $(EDK2BASE)/Conf/target.txt endif +# +# C compiler flags +# + +# ...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) -ifeq ($(ARCH),x86_64) - CFLAGS += -DEFI_FUNCTION_WRAPPER -mno-red-zone - CPPFLAGS += -DEFIX64 - LDFLAGS += -znocombreloc -zdefs +# +# Modifications on a per-architecture basis.... +# - ifeq ($(HOSTARCH),ia32) - ARCH3264 = -m64 +ifeq ($(ARCH),x86_64) + GNUEFI_LDFLAGS += -znocombreloc -zdefs - GNUEFILIB := $(GNUEFILIB)64 - EFILIB := $(EFILIB)64 - EFICRT0 := $(EFICRT0)64 - endif + 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 - LDFLAGS += -znocombreloc -zdefs + 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 + + ARCH_CFLAGS = -m32 -DEFI32 -malign-double + ARCHDIR = Ia32 + UC_ARCH = IA32 + FILENAME_CODE = ia32 + LD_CODE = elf_i386 endif ifeq ($(ARCH), aarch64) - CFLAGS += -fno-stack-check -g -fno-merge-constants -ffreestanding -fno-stack-check - CPPFLAGS += -DEFIAARCH64 + GNUEFI_CFLAGS += -DEFIAARCH64 FORMAT = -O binary FORMAT_DRIVER = -O binary - LDFLAGS += --defsym=EFI_SUBSYSTEM=0xa --warn-common --no-undefined --fatal-warnings - DRV_LDFLAGS += --defsym=EFI_SUBSYSTEM=0xb --warn-common --no-undefined --fatal-warnings -endif - -CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o + SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xa + LDFLAGS += --warn-common --no-undefined --fatal-warnings -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 = -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 -LDFLAGS += -T $(LDSCRIPT) -shared -Bsymbolic -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS) -DRV_LDFLAGS += -T $(LDSCRIPT) -shared -Bsymbolic -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS) -LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name) - +# 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 $@ -# general rules - -%.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 @@ -109,6 +177,7 @@ SHLIB_TARGET = $(subst .efi,.so,$(TARGET)) endif + # rules for libraries ifneq (,$(filter %.a,$(TARGET))) @@ -120,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