Actually make the apps build with MinGW

To builds the apps with MinGW, the CRT0 library must be ignored because
it is ELF specific and we don't need to go through ELF relocations.
We also apply the GNU_EFI_USE_MS_ABI (since we have it), remove the -z
flags, that are invalid in MinGW, and clean up the apps Makefile.

Note that setjump and debughook are excluded from MinGW builds as they
use constructs that are not available there.

Signed-off-by: Pete Batard <pete@akeo.ie>
This commit is contained in:
Pete Batard 2024-05-16 17:42:09 +01:00
parent ccfe18558c
commit 625bdb6368
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
5 changed files with 40 additions and 16 deletions

View File

@ -28,4 +28,4 @@ jobs:
run: sudo apt install ${{ matrix.pkg }} run: sudo apt install ${{ matrix.pkg }}
- name: Build - name: Build
run: make ARCH=${{ matrix.arch }} CROSS_COMPILE=${{ matrix.tuple }} lib run: make ARCH=${{ matrix.arch }} CROSS_COMPILE=${{ matrix.tuple }}

View File

@ -39,4 +39,4 @@ jobs:
submodules: recursive submodules: recursive
- name: Build - name: Build
run: make lib run: make

View File

@ -189,8 +189,11 @@ INCDIR += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \
# Only enable -fPIE for non MinGW compilers (unneeded on MinGW) # Only enable -fPIE for non MinGW compilers (unneeded on MinGW)
GCCMACHINE := $(shell $(CC) -dumpmachine) GCCMACHINE := $(shell $(CC) -dumpmachine)
ifneq (mingw32,$(findstring mingw32, $(GCCMACHINE))) IS_MINGW32 := $(findstring mingw32, $(GCCMACHINE))
ifeq ($(IS_MINGW32),)
CFLAGS += -fPIE CFLAGS += -fPIE
else
CFLAGS += -DGNU_EFI_USE_MS_ABI
endif endif
ifeq (FreeBSD, $(findstring FreeBSD, $(OS))) ifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
@ -207,7 +210,10 @@ endif
ARFLAGS := rDv ARFLAGS := rDv
ASFLAGS += $(ARCH3264) ASFLAGS += $(ARCH3264)
LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \ LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \
--build-id=sha1 -z nocombreloc -z norelro --build-id=sha1
ifeq ($(IS_MINGW32),)
LDFLAGS += -z nocombreloc -z norelro
endif
ifneq ($(ARCH),arm) ifneq ($(ARCH),arm)
export LIBGCC=$(shell $(CC) $(CFLAGS) $(ARCH3264) -print-libgcc-file-name) export LIBGCC=$(shell $(CC) $(CFLAGS) $(ARCH3264) -print-libgcc-file-name)

View File

@ -43,12 +43,19 @@ VPATH = $(SRCDIR)
include $(SRCDIR)/Make.defaults include $(SRCDIR)/Make.defaults
SUBDIRS = lib gnuefi inc apps SUBDIRS = lib inc apps
ifeq ($(IS_MINGW32),)
SUBDIRS += gnuefi
endif
all: check_gcc $(SUBDIRS) all: check_gcc $(SUBDIRS)
ifeq ($(IS_MINGW32),)
gnuefi: lib gnuefi: lib
apps: gnuefi apps: gnuefi
else
apps: lib
endif
mkvars: mkvars:
@echo AR=$(AR) @echo AR=$(AR)

View File

@ -44,25 +44,36 @@ include $(SRCDIR)/../Make.defaults
LINUX_HEADERS = /usr/src/sys/build LINUX_HEADERS = /usr/src/sys/build
APPSDIR = $(LIBDIR)/gnuefi/apps APPSDIR = $(LIBDIR)/gnuefi/apps
CPPFLAGS += -D__KERNEL__ -I$(LINUX_HEADERS)/include CPPFLAGS += -D__KERNEL__ -I$(LINUX_HEADERS)/include
ifeq ($(IS_MINGW32),)
# The CRT0 libs are only needed for non MinGW platforms
CRT0_LIBS = -lgnuefi
endif
ifneq ($(CRT0_LIBS),)
CRTOBJS = $(TOPDIR)/$(ARCH)/gnuefi/crt0-efi-$(ARCH).o CRTOBJS = $(TOPDIR)/$(ARCH)/gnuefi/crt0-efi-$(ARCH).o
LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_efi.lds LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_efi.lds
ifneq (,$(findstring FreeBSD,$(OS))) ifneq (,$(findstring FreeBSD,$(OS)))
LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds
endif endif
LDFLAGS += -L$(TOPDIR)/$(ARCH)/lib -L$(TOPDIR)/$(ARCH)/gnuefi $(CRTOBJS)
LDFLAGS += -shared -Bsymbolic -L$(TOPDIR)/$(ARCH)/lib -L$(TOPDIR)/$(ARCH)/gnuefi $(CRTOBJS)
LOADLIBES += -lefi -lgnuefi
LOADLIBES += $(LIBGCC)
LOADLIBES += -T $(LDSCRIPT) LOADLIBES += -T $(LDSCRIPT)
endif
LDFLAGS += -shared -Bsymbolic -L$(TOPDIR)/$(ARCH)/lib
LOADLIBES += -lefi $(CRT0_LIBS)
LOADLIBES += $(LIBGCC)
TARGET_APPS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi t7.efi t8.efi \
tcc.efi printenv.efi modelist.efi route80h.efi route80h.efi \
drv0_use.efi AllocPages.efi exit.efi FreePages.efi bltgrid.efi \
lfbgrid.efi setdbg.efi unsetdbg.efi ctors_test.efi \
ctors_dtors_priority_test.efi
ifeq ($(IS_MINGW32),)
TARGET_APPS += setjmp.efi debughook.efi debughook.efi.debug
endif
TARGET_APPS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi \
printenv.efi t7.efi t8.efi tcc.efi modelist.efi \
route80h.efi drv0_use.efi AllocPages.efi exit.efi \
FreePages.efi setjmp.efi debughook.efi debughook.efi.debug \
bltgrid.efi lfbgrid.efi setdbg.efi unsetdbg.efi \
ctors_test.efi ctors_dtors_priority_test.efi
TARGET_BSDRIVERS = drv0.efi TARGET_BSDRIVERS = drv0.efi
TARGET_RTDRIVERS = TARGET_RTDRIVERS =