[syslinux:wip.makefixes] WIP: more cleanup for EFI to build cleaner

syslinux-bot for H. Peter Anvin hpa at zytor.com
Thu Feb 28 23:12:06 PST 2019


Commit-ID:  0731d3d3947d6a47cf2d837b81bc72de26160ca3
Gitweb:     https://www.syslinux.org/commit/0731d3d3947d6a47cf2d837b81bc72de26160ca3
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Thu, 28 Feb 2019 23:09:34 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Thu, 28 Feb 2019 23:09:34 -0800

WIP: more cleanup for EFI to build cleaner

Something is wrong with the linking of the EFI core, though...

---
 .gitmodules                                  |   2 +-
 Makefile                                     |  42 +++----
 com32/Makefile                               |  24 ++--
 com32/efi/Makefile                           |  59 ++++++++++
 gnu-efi => com32/efi/gnu-efi                 |   0
 core/Makefile                                | 169 +++++++--------------------
 core/Makefile.bios                           |  90 ++++++++++++++
 core/Makefile.efi                            |  50 ++++++++
 core/bios/isolinux-debug.asm                 |   2 -
 core/bios/{ => main}/isolinux-c.c            |   0
 core/bios/{ => main}/isolinux-debug-c.c      |   0
 core/bios/main/isolinux-debug.asm            |   2 +
 core/bios/{ => main}/isolinux.asm            |   0
 core/bios/{ => main}/ldlinux-c.c             |   0
 core/bios/{ => main}/ldlinux.asm             |   0
 core/bios/{ => main}/lpxelinux-c.c           |   0
 core/bios/{ => main}/lpxelinux.asm           |   0
 core/bios/{ => main}/pxelinux-c.c            |   0
 core/bios/{ => main}/pxelinux.asm            |   0
 core/{ => common}/cleanup.c                  |   0
 core/{ => common}/conio.c                    |   0
 core/{ => common}/console.c                  |   0
 core/{ => common}/debug.c                    |   0
 core/{ => common}/dmi.c                      |   0
 core/{ => common}/errno.c                    |   0
 core/{ => common}/idle.c                     |   0
 core/{ => common}/init.c                     |   0
 core/{ => common}/path.c                     |   0
 core/{ => common}/pmapi.c                    |   0
 core/{ => common}/sysappend.c                |   0
 core/{ => common}/writehex.c                 |   0
 core/{ => common}/writestr.c                 |   0
 {efi => core/efi}/adv.c                      |   0
 {efi => core/efi}/adv.h                      |   0
 {efi => core/efi}/console.c                  |   0
 {efi => core/efi}/cp865_8x16.h               |   0
 {efi => core/efi}/derivative.c               |   0
 {efi => core/efi}/diskio.c                   |   0
 {efi => core/efi}/efi.h                      |   0
 {efi => core/efi}/fio.c                      |   0
 {efi => core/efi}/fio.h                      |   0
 {efi => core/efi}/i386/linux.S               |   0
 {efi => core/efi}/i386/syslinux.ld           |   0
 {efi => core/efi}/main.c                     |   7 +-
 {efi => core/efi}/mem.c                      |   0
 {efi => core/efi}/pxe.c                      |   0
 {efi => core/efi}/syslinux.ld                |   0
 {efi => core/efi}/tcp.c                      |   0
 {efi => core/efi}/udp.c                      |   0
 {efi => core/efi}/vesa.c                     |   0
 {efi => core/efi}/x86_64/linux.S             |   0
 {efi => core/efi}/x86_64/syslinux.ld         |   0
 core/{ => fs/fat}/codepage.S                 |   2 +-
 core/fs/ntfs/ntfs.c                          |   1 -
 core/fs/pxe/dhcp_option.c                    |   2 +-
 core/fs/pxe/ftp.c                            |   1 -
 core/fs/pxe/http.c                           |   2 +-
 core/fs/xfs/xfs.c                            |   1 -
 core/include/net.h                           |   8 ++
 efi/Makefile                                 |  97 ---------------
 efi/build-gnu-efi.sh                         |  45 -------
 efi/check-gnu-efi.sh                         |  38 ------
 efi/clean-gnu-efi.sh                         |  37 ------
 mk/bios.mk                                   |   1 +
 mk/build.mk                                  |  22 ++--
 mk/efi.mk                                    |  58 +++------
 mk/elf.mk                                    |  32 +++--
 mk/syslinux.mk                               |   2 +
 {lzo => prepcore/bios}/.gitignore            |   0
 {lzo => prepcore/bios}/Makefile              |   8 +-
 {lzo => prepcore/bios}/doc/LZO.TXT           |   0
 {lzo => prepcore/bios}/include/lzo/lzo1.h    |   0
 {lzo => prepcore/bios}/include/lzo/lzo1a.h   |   0
 {lzo => prepcore/bios}/include/lzo/lzo1b.h   |   0
 {lzo => prepcore/bios}/include/lzo/lzo1c.h   |   0
 {lzo => prepcore/bios}/include/lzo/lzo1f.h   |   0
 {lzo => prepcore/bios}/include/lzo/lzo1x.h   |   0
 {lzo => prepcore/bios}/include/lzo/lzo1y.h   |   0
 {lzo => prepcore/bios}/include/lzo/lzo1z.h   |   0
 {lzo => prepcore/bios}/include/lzo/lzo2a.h   |   0
 {lzo => prepcore/bios}/include/lzo/lzo_asm.h |   0
 {lzo => prepcore/bios}/include/lzo/lzoconf.h |   0
 {lzo => prepcore/bios}/include/lzo/lzodefs.h |   0
 {lzo => prepcore/bios}/include/lzo/lzoutil.h |   0
 {lzo => prepcore/bios}/prepcore.c            |   0
 {lzo => prepcore/bios}/src/compr1b.h         |   0
 {lzo => prepcore/bios}/src/compr1c.h         |   0
 {lzo => prepcore/bios}/src/config1x.h        |   0
 {lzo => prepcore/bios}/src/lzo1_d.ch         |   0
 {lzo => prepcore/bios}/src/lzo1x_1.c         |   0
 {lzo => prepcore/bios}/src/lzo1x_1k.c        |   0
 {lzo => prepcore/bios}/src/lzo1x_1l.c        |   0
 {lzo => prepcore/bios}/src/lzo1x_1o.c        |   0
 {lzo => prepcore/bios}/src/lzo1x_9x.c        |   0
 {lzo => prepcore/bios}/src/lzo1x_c.ch        |   0
 {lzo => prepcore/bios}/src/lzo1x_d.ch        |   0
 {lzo => prepcore/bios}/src/lzo1x_d1.c        |   0
 {lzo => prepcore/bios}/src/lzo1x_d2.c        |   0
 {lzo => prepcore/bios}/src/lzo1x_d3.c        |   0
 {lzo => prepcore/bios}/src/lzo1x_o.c         |   0
 {lzo => prepcore/bios}/src/lzo1x_oo.ch       |   0
 {lzo => prepcore/bios}/src/lzo_conf.h        |   0
 {lzo => prepcore/bios}/src/lzo_crc.c         |   0
 {lzo => prepcore/bios}/src/lzo_dict.h        |   0
 {lzo => prepcore/bios}/src/lzo_dll.ch        |   0
 {lzo => prepcore/bios}/src/lzo_func.h        |   0
 {lzo => prepcore/bios}/src/lzo_init.c        |   0
 {lzo => prepcore/bios}/src/lzo_mchw.ch       |   0
 {lzo => prepcore/bios}/src/lzo_ptr.c         |   0
 {lzo => prepcore/bios}/src/lzo_ptr.h         |   0
 {lzo => prepcore/bios}/src/lzo_str.c         |   0
 {lzo => prepcore/bios}/src/lzo_supp.h        |   0
 {lzo => prepcore/bios}/src/lzo_swd.ch        |   0
 {lzo => prepcore/bios}/src/lzo_util.c        |   0
 {lzo => prepcore/bios}/src/miniacc.h         |   0
 {lzo => prepcore/bios}/src/stats1a.h         |   0
 {lzo => prepcore/bios}/src/stats1b.h         |   0
 {lzo => prepcore/bios}/src/stats1c.h         |   0
 {com32/tools => prepcore/efi}/Makefile       |  11 +-
 efi/wrapper.c => prepcore/efi/prepcore.c     |  22 +---
 efi/wrapper.h => prepcore/efi/prepcore.h     |   0
 121 files changed, 355 insertions(+), 482 deletions(-)

diff --git a/.gitmodules b/.gitmodules
index 6ce10f45..6a766b88 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
 [submodule "gnu-efi"]
-	path = gnu-efi
+	path = com32/efi/gnu-efi
 	url = git://git.code.sf.net/p/gnu-efi/code
diff --git a/Makefile b/Makefile
index 003dbf4b..ca1abfd1 100644
--- a/Makefile
+++ b/Makefile
@@ -68,7 +68,7 @@ $(if $(cd-output),, \
 #
 
 MAKEDIR = $(topdir)/mk
-export MAKEDIR topdir OBJDIR
+export MAKEDIR topdir
 
 include $(MAKEDIR)/syslinux.mk
 
@@ -151,7 +151,7 @@ MODULES = com32/menu/*.c32 com32/modules/*.c32 com32/mboot/*.c32 \
 	com32/cmenu/libmenu/*.c32 ldlinux/$(LDLINUX)
 endif
 
-export FIRMWARE FWCLASS ARCH BITS
+export FIRMWARE firmware FWCLASS fwclass ARCH BITS
 
 # List of module objects that should be installed for all derivatives
 INSTALLABLE_MODULES = $(MODULES)
@@ -174,34 +174,36 @@ BOBJECTS = \
 # files that depend only on the B phase, but may have to be regenerated
 # for "make installer".
 
-ifeq ($(FWCLASS),EFI)
-
-BSUBDIRS = codepage lzo core ldlinux com32 mbr sample efi txt
+BSUBDIRS = codepage prepcore/$(fwclass) core ldlinux com32 mbr sample txt
 ISUBDIRS =
 
-INSTALLSUBDIRS = efi
+INSTALL_AUX = $(INSTALLABLE_MODULES)
 
-NETINSTALLABLE = efi/syslinux.efi $(INSTALLABLE_MODULES)
+# Things to install in /tftpboot
+NETINSTALLABLE = $(INSTALLABLE_MODULES)
 
-else
+ifeq ($(FWCLASS),EFI)
+INSTALL_AUX    += core/syslinux.efi
+NETINSTALLABLE += core/syslinux.efi
+endif
+ifeq ($(FWCLASS),BIOS)
 
-BSUBDIRS = codepage lzo core ldlinux com32 memdisk mbr sample \
-	   diag libinstaller dos win32 win64 dosutil txt
+BSUBDIRS += libinstaller dos win32 win64 dosutil
 
 IOBJECTS = utils/gethostip utils/isohybrid utils/mkdiskimage \
 	mtools/syslinux linux/syslinux extlinux/extlinux
 ISUBDIRS = libinstaller mtools linux extlinux utils
 
 # Things to install in /usr/bin
-INSTALL_BIN   =	mtools/syslinux
+INSTALL_BIN   += mtools/syslinux
 # Things to install in /sbin
-INSTALL_SBIN  = extlinux/extlinux
+INSTALL_SBIN  += extlinux/extlinux
 # Things to install in /usr/lib/syslinux
-INSTALL_AUX   =	core/pxelinux.0 \
+INSTALL_AUX   += core/pxelinux.0 \
 		core/isolinux.bin core/isolinux-debug.bin \
 		dos/syslinux.com core/lpxelinux.0 \
-		mbr/*.bin $(INSTALLABLE_MODULES)
-INSTALL_AUX_OPT = win32/syslinux.exe win64/syslinux64.exe
+		mbr/*.bin
+INSTALL_AUX_OPT += win32/syslinux.exe win64/syslinux64.exe
 INSTALL_DIAG  =	diag/mbr/handoff.bin \
 		diag/geodsp/geodsp1s.img.xz diag/geodsp/geodspms.img.xz
 
@@ -211,9 +213,7 @@ INSTALLSUBDIRS = com32 utils dosutil
 # Things to install in /boot/extlinux
 EXTBOOTINSTALL = $(INSTALLABLE_MODULES)
 
-# Things to install in /tftpboot
-NETINSTALLABLE = core/pxelinux.0 core/lpxelinux.0 \
-		 $(INSTALLABLE_MODULES)
+NETINSTALLABLE += core/pxelinux.0 core/lpxelinux.0
 
 endif # ifeq ($(FWCLASS),EFI)
 
@@ -252,7 +252,7 @@ bios:
 	@mkdir -p $(OBJ)/bios
 	$(MAKE) -C $(OBJ)/bios -f $(SRC)/Makefile SRC="$(SRC)" \
 		objdir=$(OBJ)/bios OBJ=$(OBJ)/bios \
-		FIRMWARE=BIOS FWCLASS=BIOS \
+		FIRMWARE=BIOS firmware=bios FWCLASS=BIOS fwclass=bios \
 		ARCH=i386 LDLINUX=ldlinux.c32 $(MAKECMDGOALS)
 
 efi32:
@@ -260,7 +260,7 @@ efi32:
 	$(MAKE) -C $(OBJ)/efi32 -f $(SRC)/Makefile SRC="$(SRC)" \
 		objdir=$(OBJ)/efi32 OBJ=$(OBJ)/efi32 \
 		ARCH=i386 BITS=32 LDLINUX=ldlinux.e32 \
-		FIRMWARE=EFI32 FWCLASS=EFI \
+		FIRMWARE=EFI32 firmware=efi32 FWCLASS=EFI fwclass=efi \
 		$(MAKECMDGOALS)
 
 efi64:
@@ -268,7 +268,7 @@ efi64:
 	$(MAKE) -C $(OBJ)/efi64 -f $(SRC)/Makefile SRC="$(SRC)" \
 		objdir=$(OBJ)/efi64 OBJ=$(OBJ)/efi64 \
 		ARCH=x86_64 BITS=64 LDLINUX=ldlinux.e64 \
-		FIRMWARE=EFI64 FWCLASS=EFI \
+		FIRMWARE=EFI64 firmware=efi64 FWCLASS=EFI fwclass=efi \
 		$(MAKECMDGOALS)
 
 else # FIRMWARE
diff --git a/com32/Makefile b/com32/Makefile
index c2650307..412ad8df 100644
--- a/com32/Makefile
+++ b/com32/Makefile
@@ -1,13 +1,16 @@
-ifdef PRECORE
-SUBDIRS = tools lib
-else
-SUBDIRS = tools lib libutil gpllib libupload modules mboot \
-	  menu samples elflink rosh cmenu lua/src
+PRECOREDIRS       := tools lib
+PRECOREDIRS_EFI   := efi
+PRECOREDIRS_BIOS  :=
 
-ifneq ($(FWCLASS),EFI)
+POSTCOREDIRS      := libutil gpllib libupload modules mboot \
+	  	    menu samples elflink rosh cmenu lua/src
+POSTCOREDIRS_EFI  :=
 # These tools are no applicable to EFI, or need serious porting
-SUBDIRS += hdt sysdump chain
-endif
+POSTCOREDIRS_BIOS = hdt sysdump chain
+
+SUBDIRS  = $(PRECOREDIRS) $(PRECOREDIRS_$(FWCLASS))
+ifndef PRECORE
+SUBDIRS += $(POSTCOREDIRS) $(POSTCOREDIRS_$(FWCLASS))
 endif
 
 all tidy dist clean spotless install: subdirs
@@ -19,8 +22,9 @@ $(SUBDIRS):
 	$(MAKE) -C $(OBJ)/$@ SRC='$(SRC)/$@' OBJ='$(OBJ)/$@' \
 		-f '$(SRC)/$@/Makefile' $(MAKECMDGOALS)
 
-# Parallel dependencies 
-lib: tools
+# Parallel dependencies
+LIBDEP_EFI := efi
+lib: tools $(LIBDEP_$(FWCLASS))
 
 gpllib libupload libutil: lib
 cmenu: lib libutil
diff --git a/com32/efi/Makefile b/com32/efi/Makefile
new file mode 100644
index 00000000..d5ccd86f
--- /dev/null
+++ b/com32/efi/Makefile
@@ -0,0 +1,59 @@
+## -----------------------------------------------------------------------
+##
+##   Copyright 2011 Intel Corporation; author: Matt Fleming
+##
+##   This program is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+##   Boston MA 02111-1307, USA; either version 2 of the License, or
+##   (at your option) any later version; incorporated herein by reference.
+##
+## -----------------------------------------------------------------------
+
+include $(MAKEDIR)/elf.mk
+
+# The targets to build in this directory
+all: libefi
+
+EFISRC  = $(SRC)/gnu-efi
+EFIOBJ  = $(OBJ)/gnu-efi
+
+# This is a hack due to missing rules in gnu-efi/Make.rules
+# Also note make rather than $(MAKE) below.
+unexport MAKEFLAGS
+
+EFIMAKE = make -C '$(EFIOBJ)' \
+	  SRCDIR='$(EFISRC)' \
+	  HOSTCC='$(CC_FOR_BUILD)' \
+	  ARCH='$(EFI_SUBARCH)' PREFIX='$(OBJ)' \
+	  -f '$(EFISRC)/Makefile'
+
+libefi: include/efi/$(EFI_SUBARCH)/efibind.h \
+	lib/libefi.a lib/libgnuefi.a
+
+include/%/$(EFI_SUBARCH)/efibind.h lib/lib%.a lib/libgnu%.a: 
+	@echo Building gnu-efi for $(EFI_SUBARCH)
+	if [ -f $(topdir)/.gitmodule ]; then \
+		( cd $(topdir) && git submodule update --init ); \
+	fi
+	mkdir -p $(EFIOBJ)
+	$(EFIMAKE)
+	$(EFIMAKE) install
+
+install:
+
+strip:
+
+tidy dist:
+	rm -f *.so *.o wrapper
+	find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \
+		xargs -0r rm -f
+	if [ -d gnu-efi ]; then $(EFIMAKE) clean; fi
+
+clean: clean-efi tidy
+
+clean-efi:
+	rm -rf gnu-efi
+
+spotless: clean
+	rm -rf lib include
diff --git a/gnu-efi b/com32/efi/gnu-efi
similarity index 100%
rename from gnu-efi
rename to com32/efi/gnu-efi
diff --git a/core/Makefile b/core/Makefile
index 6b79d877..b6d74166 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -1,7 +1,7 @@
 ## -----------------------------------------------------------------------
 ##
 ##   Copyright 1998-2009 H. Peter Anvin - All Rights Reserved
-##   Copyright 2009-2016 Intel Corporation; author: H. Peter Anvin
+##   Copyright 2009-2019 Intel Corporation; author: H. Peter Anvin
 ##
 ##   This program is free software; you can redistribute it and/or modify
 ##   it under the terms of the GNU General Public License as published by
@@ -12,78 +12,56 @@
 ## -----------------------------------------------------------------------
 
 #
-# Makefile for the SYSLINUX core
+# General Makefile for the Syslinux core
 #
 
 include $(MAKEDIR)/elf.mk
 -include $(objdir)/version.mk
 
-INCLUDE  += -I$(SRC)/include -I$(com32)/lib \
-	    -I$(SRC)/bios/lwip/src/include \
-	    -I$(SRC)/bios/lwip/src/include/ipv4 -I$(SRC)/fs/pxe
+INCLUDE  += -I$(SRC)/include -I$(com32)/lib -I$(SRC)/fs/pxe
 
 # This is very similar to cp437; technically it's for Norway and Denmark,
 # but it's unlikely the characters that are different will be used in
 # filenames by other users.
 CODEPAGE = cp865
 
-# The targets to build in this directory...
-BTARGET  = ldlinux.bss ldlinux.sys \
-	   isolinux.bin isolinux-debug.bin pxelinux.0 lpxelinux.0
-
-# The corresponding ELF files
-ETARGET  = $(patsubst $(SRC)/%-c.c,%.elf,$(wildcard $(SRC)/bios/*-c.c))
+# Directories to actually build from
+SRCDIRS := common elflink fs mem include $(fwclass)
 
 # Export library files
 LIBCORE_FILES = libcore.so libcore.weak
 
-# All primary source files for the main syslinux files
-NASMSRC	 := $(sort $(shell find $(SRC) -name '*.asm' -print))
-NASMHDR	 := $(sort $(shell find $(SRC) -name '*.inc' -print))
-CSRC	 := $(sort $(shell find $(SRC) -name '*.c' -print))
-SSRC	 := $(sort $(shell find $(SRC) -name '*.S' -print))
-CHDR	 := $(sort $(shell find $(SRC) -name '*.h' -print))
-OTHERSRC :=
-ALLSRC    = $(NASMSRC) $(NASMHDR) $(CSRC) $(SSRC) $(CHDR) $(OTHERSRC)
-
-COBJ	 := $(subst $(SRC)/,,$(patsubst %.c,%.o,$(CSRC)))
-SOBJ	 := $(subst $(SRC)/,,$(patsubst %.S,%.o,$(SSRC)))
-
-# To make this compatible with the following $(filter-out), make sure
-# we prefix everything with $(SRC)
-CORE_PXE_DIRS  = $(SRC)/bios/pxe
-LPXELINUX_DIRS = $(SRC)/bios/lwip
-PXELINUX_DIRS  = $(SRC)/bios/legacynet
-
-CORE_PXE_CSRC  = $(sort $(shell find $(CORE_PXE_DIRS)  -name '*.c' -print))
-CORE_PXE_SSRC  = $(sort $(shell find $(CORE_PXE_DIRS)  -name '*.S' -print))
-LPXELINUX_CSRC = $(sort $(shell find $(LPXELINUX_DIRS) -name '*.c' -print))
-LPXELINUX_SSRC = $(sort $(shell find $(LPXELINUX_DIRS) -name '*.S' -print))
-PXELINUX_CSRC  = $(sort $(shell find $(PXELINUX_DIRS)  -name '*.c' -print))
-PXELINUX_SSRC  = $(sort $(shell find $(PXELINUX_DIRS)  -name '*.S' -print))
-
-CORE_PXE_OBJS  = $(subst $(SRC)/,,$(CORE_PXE_CSRC:%.c=%.o)  $(CORE_PXE_SSRC:%.S=%.o))
-LPXELINUX_OBJS = $(subst $(SRC)/,,$(LPXELINUX_CSRC:%.c=%.o) $(LPXELINUX_SSRC:%.S=%.o))
-PXELINUX_OBJS  = $(subst $(SRC)/,,$(PXELINUX_CSRC:%.c=%.o)  $(PXELINUX_SSRC:%.S=%.o))
-
-UNITTEST_DIRS = $(sort $(shell find $(SRC) -type d -name tests))
-
-# Don't include network stack specific objects or unit tests
-FILTER_DIRS = $(UNITTEST_DIRS) $(CORE_PXE_DIRS) \
-	      $(PXELINUX_DIRS) $(LPXELINUX_DIRS)
-ifeq ($(FWCLASS),EFI)
-FILTER_DIRS += $(SRC)/bios
-endif
-FILTER_OBJS = $(patsubst $(SRC)/%,%/%,$(FILTER_DIRS))
+# Libraries to link with the core
+CORE_LIBS = $(objdir)/com32/lib/libcom32.a
 
-COBJS	 = $(filter-out $(FILTER_OBJS),$(COBJ))
-SOBJS	 = $(filter-out $(FILTER_OBJS),$(SOBJ))
+# Core preparation program
+PREPCORE  = $(objdir)/prepcore/$(fwclass)/prepcore
 
-CORE_LIB	= bios/libsyslinux.a
-CORE_LIBS	= $(CORE_LIB) $(objdir)/com32/lib/libcom32.a
-CORE_LIBOBJS	 = $(COBJS) $(SOBJS)
+# All primary source files for the main syslinux files
+SRCFILES  := $(sort $(shell find $(SRCDIRS:%=$(SRC)/%) \
+	      -name tests -prune -o -type f -print))
+NASMSRC	  := $(filter %.asm,$(SRCFILES))
+NASMHDR	  := $(filter %.inc,$(SRCFILES))
+CSRC	  := $(filter %.c  ,$(SRCFILES))
+SSRC	  := $(filter %.S  ,$(SRCFILES))
+CHDR	  := $(filter %.h  ,$(SRCFILES))
+ALLSRC    := $(NASMSRC) $(NASMHDR) $(CSRC) $(SSRC) $(CHDR)
+
+COBJ	  := $(CSRC:$(SRC)/%.c=%.o)
+SOBJ	  := $(SSRC:$(SRC)/%.S=%.o)
+NASMOBJ   := $(NASMSRC:$(SRC)/%.asm=%.o)
+ALLOBJ    := $(COBJ) $(SOBJ) $(NASMOBJ)
+
+DATE_DEFS = -DDATE_STR='"$(DATE)"' -DHEXDATE="$(HEXDATE)"
+
+%.a:
+	rm -f $@
+	$(AR) cq $@ $^
+	$(RANLIB) $@
 
-PREPCORE = $(OBJ)/../lzo/prepcore
+include $(SRC)/Makefile.$(fwclass)
+
+CORE_LIBOBJS ?= $(ALLOBJ)
 
 # This makes the core quite a bit smaller, but requires that the proper
 # __export tags are in place. It would be very good to add the same things
@@ -102,70 +80,16 @@ ifndef DATE
 DATE    := $(shell sh $(SRC)/../gen-id.sh $(VERSION) $(HEXDATE))
 endif
 
-ifeq ($(FWCLASS),EFI)
-all: makeoutputdirs $(COBJS) $(SOBJS) codepage.o $(LIBCORE_FILES)
-else
-all: makeoutputdirs $(BTARGET) $(LIBCORE_FILES)
-endif
-
-makeoutputdirs:
-	@mkdir -p $(sort $(dir $(COBJ) $(SOBJ)))
-
-ifeq ($(FWCLASS),BIOS)
-
-%.raw: %.elf
-	$(OBJCOPY) -O binary -S $< $@
+CORELDSCRIPT ?= $(SRC)/$(fwclass)/syslinux.ld
 
-%.bin: %.raw $(PREPCORE)
-	$(PREPCORE) $< $@
-
-NASMFLAGS += -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" -I$(SRC)/bios/ -I$(objdir)/ -I$(OBJ)/
-
-%.o: %.asm kwdhash.gen $(objdir)/version.gen
-
-AUXLIBS = bios/libpxelinux.a bios/liblpxelinux.a
-CORELDSCRIPT = $(SRC)/bios/syslinux.ld
-CORELDFLAGS = $(MAIN_LDFLAGS) -pie --no-dynamic-linker \
+CORELDFLAGS += $(MAIN_LDFLAGS) -pie --no-dynamic-linker \
 	--unresolved-symbols=report-all \
 	-E -M -T $(CORELDSCRIPT)
 
-# Assembly file to force certain symbols to be exported even if
-# they are not used by the core.
-EXPORT = bios/export.o
-
-$(ETARGET): %.elf: %.o %-c.o $(EXPORT) %.a $(CORE_LIBS) $(CORELDSCRIPT)
-	$(LD) $(CORELDFLAGS) -o $@ $< $*-c.o $(EXPORT) \
-		--start-group $*.a $(CORE_LIBS) --end-group \
-		> $*.map
-	if [ `$(NM) -D -u $@ | wc -l` -ne 0 ]; then \
-		$(NM) -D -u $@ 1>&2; rm -f $@; false; fi
-	$(OBJDUMP) -h $@ > $*.sec
-	$(PERL) $(SRC)/lstadjust.pl $*.lsr $*.sec $*.lst
-
-# Legacy network stack
-bios/pxelinux.a: $(CORE_PXE_OBJS) $(PXELINUX_OBJS)
-
-# LwIP network stack
-bios/lpxelinux.a: $(CORE_PXE_OBJS) $(LPXELINUX_OBJS)
-
-# Otherwise, no special library needed, a null library will be created
-
-bios/%.a:
-	rm -f $@
-	$(AR) cq $@ $^
-	$(RANLIB) $@
-
-%.0: bios/%.bin
-	cp -f $< $@
-
-%.bin: bios/%.bin
-	cp -f $< $@
-
-ldlinux.bss: bios/ldlinux.bin
-	dd if=$< of=$@ bs=512 count=1
+all: makeoutputdirs $(BTARGET) $(LIBCORE_FILES)
 
-ldlinux.sys: bios/ldlinux.bin
-	dd if=$< of=$@ bs=512 skip=2
+makeoutputdirs:
+	@mkdir -p $(sort $(dir $(ALLOBJ)))
 
 libcore.S: $(ETARGET) $(SRC)/export.pl
 	$(PERL) '$(SRC)/export.pl' libcore.S libcore.weak $(ETARGET)
@@ -173,21 +97,12 @@ libcore.S: $(ETARGET) $(SRC)/export.pl
 libcore.weak: libcore.S
 	: $@ generated by side effect from $<
 
-# Don't use $(SHARED) here: we don't want a SONAME on libcore.so
 libcore.so: libcore.o
 	$(LD) $(LDFLAGS) -shared -o $@ $<
 
-endif # BIOS
-
 $(CORE_LIB): $(CORE_LIBOBJS)
-	rm -f $@
-	$(AR) cq $@ $^
-	$(RANLIB) $@
-
-codepage.cp: $(OBJ)/../codepage/$(CODEPAGE).cp
-	cp -f $< $@
 
-codepage.o: codepage.S codepage.cp
+fs/fat/codepage.o: SFLAGS += -DCODEPAGE=\"$(objdir)/codepage/$(CODEPAGE).cp\"
 
 install: installer
 
@@ -201,7 +116,7 @@ tidy dist:
 	for d in $(find . -type d -print) ; do \
 	( cd "$$d" ; \
 	  rm -f *.o *.a .*.d *.lst \
-	        codepage.cp *.elf stupid.* patch.offset .depend \
+	        *.elf stupid.* patch.offset .depend \
 	        *.elf.tmp *.sym \
 	        *.lsr *.map *.sec *.raw \
 	); done
@@ -212,5 +127,5 @@ clean: tidy
 spotless: clean
 	rm -f $(BTARGET) *.bin *_bin.c
 
-# Include dependencies file
--include $(shell find $(OBJ) -name '.*.d' -print)
+# Include dependencies files
+-include $(shell find $(OBJ) -name '.*.d' -type f -print)
diff --git a/core/Makefile.bios b/core/Makefile.bios
new file mode 100644
index 00000000..ea33f9cc
--- /dev/null
+++ b/core/Makefile.bios
@@ -0,0 +1,90 @@
+## -*- makefile-gmake -*- -------------------------------------------------
+##
+##   Copyright 1998-2009 H. Peter Anvin - All Rights Reserved
+##   Copyright 2009-2019 Intel Corporation; author: H. Peter Anvin
+##
+##   This program is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+##   Boston MA 02111-1307, USA; either version 2 of the License, or
+##   (at your option) any later version; incorporated herein by reference.
+##
+## -----------------------------------------------------------------------
+
+#
+# BIOS-specific Makefile for the Syslinux core
+#
+
+INCLUDE  += -I$(SRC)/bios/lwip/src/include \
+	    -I$(SRC)/bios/lwip/src/include/ipv4
+
+# The targets to build in this directory...
+BTARGET  := ldlinux.bss ldlinux.sys \
+	   isolinux.bin isolinux-debug.bin pxelinux.0 lpxelinux.0
+
+# The corresponding ELF files
+ETARGET  := $(patsubst $(SRC)/bios/main/%.asm,bios/%.elf,\
+	    $(wildcard $(SRC)/bios/main/*.asm))
+
+CORE_PXE_DIRS   := bios/pxe fs/pxe
+LPXELINUX_DIRS  := bios/lwip
+PXELINUX_DIRS   := bios/legacynet
+MAIN_DIRS       := bios/main
+FILTER_DIRS     := $(CORE_PXE_DIRS) $(LPXELINUX_DIRS) \
+		   $(PXELINUX_DIRS) $(MAIN_DIRS)
+
+CORE_PXE_OBJS   := $(filter $(CORE_PXE_DIRS:%=%/%.o),$(ALLOBJ))
+LPXELINUX_OBJS  := $(filter $(LPXELINUX_DIRS:%=%/%.o),$(ALLOBJ))
+PXELINUX_OBJS   := $(filter $(PXELINUX_DIRS:%=%/%.o),$(ALLOBJ))
+MAIN_OBJS       := $(filter $(MAIN_DIRS:%=%/%.o),$(ALLOBJ))
+
+CORE_LIBOBJS    := $(filter-out $(FILTER_DIRS:%=%/%.o),$(ALLOBJ))
+
+AUXLIBS      	:= bios/pxelinux.a bios/lpxelinux.a
+CORELDSCRIPT	:= $(SRC)/bios/syslinux.ld
+
+CORE_LIB	:= bios/libsyslinux.a
+
+%.raw: %.elf
+	$(OBJCOPY) -O binary -S $< $@
+
+%.bin: %.raw $(PREPCORE)
+	$(PREPCORE) $< $@
+
+NASMFLAGS += $(DATE_DEFS) -I$(SRC)/bios/ -I$(objdir)/ -I$(OBJ)/
+
+%.o: %.asm $(objdir)/version.gen
+
+# Assembly file to force certain symbols to be exported even if
+# they are not used by the core.
+EXPORT = bios/export.o
+
+$(ETARGET): bios/%.elf: bios/main/%.o bios/main/%-c.o $(EXPORT) bios/%.a \
+	$(CORE_LIB) $(CORE_LIBS) $(CORELDSCRIPT)
+	$(LD) $(CORELDFLAGS) -o $@ $(filter %.o,$^) \
+		--start-group $(filter %.a,$^) --end-group \
+		> bios/$*.map
+	if [ `$(NM) -D -u $@ | wc -l` -ne 0 ]; then \
+		$(NM) -D -u $@ 1>&2; rm -f $@; false; fi
+	$(OBJDUMP) -h $@ > bios/$*.sec
+	$(PERL) $(SRC)/lstadjust.pl bios/main/$*.lsr bios/$*.sec bios/$*.lst
+
+# Legacy network stack
+bios/pxelinux.a: $(CORE_PXE_OBJS) $(PXELINUX_OBJS)
+
+# LwIP network stack
+bios/lpxelinux.a: $(CORE_PXE_OBJS) $(LPXELINUX_OBJS) 
+
+# Otherwise, no special library needed, a null library will be created
+
+%.0: bios/%.bin
+	cp -f $< $@
+
+%.bin: bios/%.bin
+	cp -f $< $@
+
+ldlinux.bss: bios/ldlinux.bin
+	dd if=$< of=$@ bs=512 count=1
+
+ldlinux.sys: bios/ldlinux.bin
+	dd if=$< of=$@ bs=512 skip=2
diff --git a/core/Makefile.efi b/core/Makefile.efi
new file mode 100644
index 00000000..dce513ed
--- /dev/null
+++ b/core/Makefile.efi
@@ -0,0 +1,50 @@
+## -*- makefile -*- ------------------------------------------------------
+##
+##   Copyright 1998-2009 H. Peter Anvin - All Rights Reserved
+##   Copyright 2009-2019 Intel Corporation; author: H. Peter Anvin
+##
+##   This program is free software; you can redistribute it and/or modify
+##   it under the terms of the GNU General Public License as published by
+##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+##   Boston MA 02111-1307, USA; either version 2 of the License, or
+##   (at your option) any later version; incorporated herein by reference.
+##
+## -----------------------------------------------------------------------
+
+#
+# EFI-specific Makefile for the Syslinux core
+#
+
+# The targets to build in this directory...
+BTARGET  = syslinux.efi
+
+# The corresponding ELF files
+ETARGET  = efi/syslinux.elf
+
+# Export library files
+LIBCORE_FILES = libcore.so libcore.weak
+
+CORE_LIBOBJS  = $(ALLOBJ)
+
+CORELDFLAGS =
+CORE_LIB	= efi/libsyslinux.a
+
+INCLUDE += -I$(SRC)/efi
+CFLAGS  += $(DATE_DEFS)
+
+# Build the wrapper app and wrap our .so to produce a .efi
+syslinux.efi: efi/syslinux.elf $(PREPCORE)
+	$(PREPCORE) $< $@
+
+wrapper: wrapper.c wrapper.h
+	$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) -o $@ $< $(LIBS_FOR_BUILD)
+
+CORELDSCRIPT = $(LDSCRIPT)
+
+# Assembly file to force certain symbols to be exported even if
+# they are not used by the core.
+EXPORT = export.o
+
+$(ETARGET): $(CORE_LIB)
+	$(LD) $(CORELDFLAGS) --strip-debug -o $@ $^ \
+		-L$(objdir)/com32/efi/lib -lgnuefi -lefi
diff --git a/core/bios/isolinux-debug.asm b/core/bios/isolinux-debug.asm
deleted file mode 100644
index 9c74b7cd..00000000
--- a/core/bios/isolinux-debug.asm
+++ /dev/null
@@ -1,2 +0,0 @@
-%define DEBUG_MESSAGES 1
-%include "isolinux.asm"
diff --git a/core/bios/isolinux-c.c b/core/bios/main/isolinux-c.c
similarity index 100%
rename from core/bios/isolinux-c.c
rename to core/bios/main/isolinux-c.c
diff --git a/core/bios/isolinux-debug-c.c b/core/bios/main/isolinux-debug-c.c
similarity index 100%
rename from core/bios/isolinux-debug-c.c
rename to core/bios/main/isolinux-debug-c.c
diff --git a/core/bios/main/isolinux-debug.asm b/core/bios/main/isolinux-debug.asm
new file mode 100644
index 00000000..571b3fad
--- /dev/null
+++ b/core/bios/main/isolinux-debug.asm
@@ -0,0 +1,2 @@
+%define DEBUG_MESSAGES 1
+%include "main/isolinux.asm"
diff --git a/core/bios/isolinux.asm b/core/bios/main/isolinux.asm
similarity index 100%
rename from core/bios/isolinux.asm
rename to core/bios/main/isolinux.asm
diff --git a/core/bios/ldlinux-c.c b/core/bios/main/ldlinux-c.c
similarity index 100%
rename from core/bios/ldlinux-c.c
rename to core/bios/main/ldlinux-c.c
diff --git a/core/bios/ldlinux.asm b/core/bios/main/ldlinux.asm
similarity index 100%
rename from core/bios/ldlinux.asm
rename to core/bios/main/ldlinux.asm
diff --git a/core/bios/lpxelinux-c.c b/core/bios/main/lpxelinux-c.c
similarity index 100%
rename from core/bios/lpxelinux-c.c
rename to core/bios/main/lpxelinux-c.c
diff --git a/core/bios/lpxelinux.asm b/core/bios/main/lpxelinux.asm
similarity index 100%
rename from core/bios/lpxelinux.asm
rename to core/bios/main/lpxelinux.asm
diff --git a/core/bios/pxelinux-c.c b/core/bios/main/pxelinux-c.c
similarity index 100%
rename from core/bios/pxelinux-c.c
rename to core/bios/main/pxelinux-c.c
diff --git a/core/bios/pxelinux.asm b/core/bios/main/pxelinux.asm
similarity index 100%
rename from core/bios/pxelinux.asm
rename to core/bios/main/pxelinux.asm
diff --git a/core/cleanup.c b/core/common/cleanup.c
similarity index 100%
rename from core/cleanup.c
rename to core/common/cleanup.c
diff --git a/core/conio.c b/core/common/conio.c
similarity index 100%
rename from core/conio.c
rename to core/common/conio.c
diff --git a/core/console.c b/core/common/console.c
similarity index 100%
rename from core/console.c
rename to core/common/console.c
diff --git a/core/debug.c b/core/common/debug.c
similarity index 100%
rename from core/debug.c
rename to core/common/debug.c
diff --git a/core/dmi.c b/core/common/dmi.c
similarity index 100%
rename from core/dmi.c
rename to core/common/dmi.c
diff --git a/core/errno.c b/core/common/errno.c
similarity index 100%
rename from core/errno.c
rename to core/common/errno.c
diff --git a/core/idle.c b/core/common/idle.c
similarity index 100%
rename from core/idle.c
rename to core/common/idle.c
diff --git a/core/init.c b/core/common/init.c
similarity index 100%
rename from core/init.c
rename to core/common/init.c
diff --git a/core/path.c b/core/common/path.c
similarity index 100%
rename from core/path.c
rename to core/common/path.c
diff --git a/core/pmapi.c b/core/common/pmapi.c
similarity index 100%
rename from core/pmapi.c
rename to core/common/pmapi.c
diff --git a/core/sysappend.c b/core/common/sysappend.c
similarity index 100%
rename from core/sysappend.c
rename to core/common/sysappend.c
diff --git a/core/writehex.c b/core/common/writehex.c
similarity index 100%
rename from core/writehex.c
rename to core/common/writehex.c
diff --git a/core/writestr.c b/core/common/writestr.c
similarity index 100%
rename from core/writestr.c
rename to core/common/writestr.c
diff --git a/efi/adv.c b/core/efi/adv.c
similarity index 100%
rename from efi/adv.c
rename to core/efi/adv.c
diff --git a/efi/adv.h b/core/efi/adv.h
similarity index 100%
rename from efi/adv.h
rename to core/efi/adv.h
diff --git a/efi/console.c b/core/efi/console.c
similarity index 100%
rename from efi/console.c
rename to core/efi/console.c
diff --git a/efi/cp865_8x16.h b/core/efi/cp865_8x16.h
similarity index 100%
rename from efi/cp865_8x16.h
rename to core/efi/cp865_8x16.h
diff --git a/efi/derivative.c b/core/efi/derivative.c
similarity index 100%
rename from efi/derivative.c
rename to core/efi/derivative.c
diff --git a/efi/diskio.c b/core/efi/diskio.c
similarity index 100%
rename from efi/diskio.c
rename to core/efi/diskio.c
diff --git a/efi/efi.h b/core/efi/efi.h
similarity index 100%
rename from efi/efi.h
rename to core/efi/efi.h
diff --git a/efi/fio.c b/core/efi/fio.c
similarity index 100%
rename from efi/fio.c
rename to core/efi/fio.c
diff --git a/efi/fio.h b/core/efi/fio.h
similarity index 100%
rename from efi/fio.h
rename to core/efi/fio.h
diff --git a/efi/i386/linux.S b/core/efi/i386/linux.S
similarity index 100%
rename from efi/i386/linux.S
rename to core/efi/i386/linux.S
diff --git a/efi/i386/syslinux.ld b/core/efi/i386/syslinux.ld
similarity index 100%
rename from efi/i386/syslinux.ld
rename to core/efi/i386/syslinux.ld
diff --git a/efi/main.c b/core/efi/main.c
similarity index 99%
rename from efi/main.c
rename to core/efi/main.c
index 5c302744..74e692c2 100644
--- a/efi/main.c
+++ b/core/efi/main.c
@@ -17,11 +17,10 @@
 #include "efi_pxe.h"
 
 __export uint16_t PXERetry;
-__export char copyright_str[] = "Copyright (C) 2011-" YEAR_STR "\n";
+__export const char copyright_str[] = "Copyright (C) 2011-" YEAR_STR "\n";
 uint8_t SerialNotice = 1;
-__export char syslinux_banner[] = "Syslinux " VERSION_STR " (EFI; " DATE_STR ")\n";
+__export const char syslinux_banner[] = "Syslinux " VERSION_STR " (EFI; " DATE_STR ")\n";
 char CurrentDirName[CURRENTDIR_MAX];
-struct com32_sys_args __com32;
 
 uint32_t _IdleTimer = 0;
 char __lowmem_heap[32];
@@ -1280,7 +1279,7 @@ extern char __bss_end[];
 
 static void efi_setcwd(CHAR16 *dp)
 {
-	CHAR16 *c16;
+	const CHAR16 *c16;
 	char *c8;
 	int i, j;
 
diff --git a/efi/mem.c b/core/efi/mem.c
similarity index 100%
rename from efi/mem.c
rename to core/efi/mem.c
diff --git a/efi/pxe.c b/core/efi/pxe.c
similarity index 100%
rename from efi/pxe.c
rename to core/efi/pxe.c
diff --git a/efi/syslinux.ld b/core/efi/syslinux.ld
similarity index 100%
rename from efi/syslinux.ld
rename to core/efi/syslinux.ld
diff --git a/efi/tcp.c b/core/efi/tcp.c
similarity index 100%
rename from efi/tcp.c
rename to core/efi/tcp.c
diff --git a/efi/udp.c b/core/efi/udp.c
similarity index 100%
rename from efi/udp.c
rename to core/efi/udp.c
diff --git a/efi/vesa.c b/core/efi/vesa.c
similarity index 100%
rename from efi/vesa.c
rename to core/efi/vesa.c
diff --git a/efi/x86_64/linux.S b/core/efi/x86_64/linux.S
similarity index 100%
rename from efi/x86_64/linux.S
rename to core/efi/x86_64/linux.S
diff --git a/efi/x86_64/syslinux.ld b/core/efi/x86_64/syslinux.ld
similarity index 100%
rename from efi/x86_64/syslinux.ld
rename to core/efi/x86_64/syslinux.ld
diff --git a/core/codepage.S b/core/fs/fat/codepage.S
similarity index 80%
rename from core/codepage.S
rename to core/fs/fat/codepage.S
index 6fb046f6..8ddd628b 100644
--- a/core/codepage.S
+++ b/core/fs/fat/codepage.S
@@ -2,5 +2,5 @@
 	.globl	codepage
 	.hidden	codepage
 codepage:
-	.incbin "codepage.cp"
+	.incbin CODEPAGE
 	.size	codepage, .-codepage
diff --git a/core/fs/ntfs/ntfs.c b/core/fs/ntfs/ntfs.c
index 54213668..df10c08b 100644
--- a/core/fs/ntfs/ntfs.c
+++ b/core/fs/ntfs/ntfs.c
@@ -31,7 +31,6 @@
 #include <klibc/compiler.h>
 #include <ctype.h>
 
-#include "codepage.h"
 #include "ntfs.h"
 #include "runlist.h"
 
diff --git a/core/fs/pxe/dhcp_option.c b/core/fs/pxe/dhcp_option.c
index 88102cbe..374fe48c 100644
--- a/core/fs/pxe/dhcp_option.c
+++ b/core/fs/pxe/dhcp_option.c
@@ -2,9 +2,9 @@
 #include <string.h>
 #include <core.h>
 #include <x86/cpu.h>
-#include <lwip/opt.h>		/* DNS_MAX_SERVERS */
 #include <dprintf.h>
 #include "core_pxe.h"
+#include "net.h"
 
 char LocalDomain[256];
 
diff --git a/core/fs/pxe/ftp.c b/core/fs/pxe/ftp.c
index 6893e540..b1bca41f 100644
--- a/core/fs/pxe/ftp.c
+++ b/core/fs/pxe/ftp.c
@@ -20,7 +20,6 @@
 #include <minmax.h>
 #include <x86/cpu.h>
 #include <netinet/in.h>
-#include <lwip/api.h>
 #include "core.h"
 #include "fs.h"
 #include "core_pxe.h"
diff --git a/core/fs/pxe/http.c b/core/fs/pxe/http.c
index 5b8fce11..2a03bb1d 100644
--- a/core/fs/pxe/http.c
+++ b/core/fs/pxe/http.c
@@ -1,6 +1,6 @@
 #include <syslinux/sysappend.h>
 #include <ctype.h>
-#include <lwip/api.h>
+#include <limits.h>
 #include "core_pxe.h"
 #include "version.h"
 #include "url.h"
diff --git a/core/fs/xfs/xfs.c b/core/fs/xfs/xfs.c
index 6f459737..0db261d2 100644
--- a/core/fs/xfs/xfs.c
+++ b/core/fs/xfs/xfs.c
@@ -27,7 +27,6 @@
 #include <klibc/compiler.h>
 #include <ctype.h>
 
-#include "codepage.h"
 #include "xfs_types.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
diff --git a/core/include/net.h b/core/include/net.h
index c64191d8..fa8554e5 100644
--- a/core/include/net.h
+++ b/core/include/net.h
@@ -5,6 +5,14 @@
 #include <stdbool.h>
 #include <stddef.h>
 
+#ifdef __FIRMWARE_BIOS__
+# include <lwip/opt.h>
+# include <lwip/api.h>
+#else
+# define DNS_MAX_SERVERS 4
+typedef int err_t;
+#endif
+
 void net_core_init(void);
 void net_parse_dhcp(void);
 
diff --git a/efi/Makefile b/efi/Makefile
deleted file mode 100644
index 780ff18d..00000000
--- a/efi/Makefile
+++ /dev/null
@@ -1,97 +0,0 @@
-## -----------------------------------------------------------------------
-##
-##   Copyright 2011 Intel Corporation; author: Matt Fleming
-##
-##   This program is free software; you can redistribute it and/or modify
-##   it under the terms of the GNU General Public License as published by
-##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
-##   Boston MA 02111-1307, USA; either version 2 of the License, or
-##   (at your option) any later version; incorporated herein by reference.
-##
-## -----------------------------------------------------------------------
-
-VPATH = $(SRC)
-include $(MAKEDIR)/elf.mk
-include $(MAKEDIR)/efi.mk
-
-CC_FOR_BUILD ?= $(CC)
-
-# Upstream gnu-efi has old-style function definitions.
-CFLAGS += -Wno-strict-prototypes
-
-CORE_CSRC := $(sort $(shell find '$(core)' -name '*.c' -print))
-CORE_COBJ := $(subst $(core),$(OBJ)/../core,$(patsubst %.c,%.o,$(CORE_CSRC)))
-
-# We don't want to include any of the networking stack or the thread
-# code since it will be implemented completely differently for EFI.
-FILTERED_OBJS := $(OBJ)/../core/bios/% \
-		 $(patsubst $(core)/%,$(OBJ)/../core/%/%,\
-			$(shell find '$(core)' -type d -name tests))
-
-CORE_OBJS = $(filter-out $(FILTERED_OBJS),$(CORE_COBJ))
-
-LIB_OBJS = $(addprefix $(objdir)/com32/lib/,$(CORELIBOBJS)) \
-	$(LIBEFI)
-
-CSRC = $(sort $(wildcard $(SRC)/*.c))
-OBJS = $(subst $(SRC)/,,$(filter-out %wrapper.o, $(patsubst %.c,%.o,$(CSRC))))
-
-OBJS += $(objdir)/core/codepage.o $(ARCH)/linux.o
-
-# The DATE is set on the make command line when building binaries for
-# official release.  Otherwise, substitute a hex string that is pretty much
-# guaranteed to be unique to be unique from build to build.
-ifndef HEXDATE
-HEXDATE := $(shell $(PERL) $(SRC)/../now.pl $(SRCS))
-endif
-ifndef DATE
-DATE    := $(shell sh $(SRC)/../gen-id.sh $(VERSION) $(HEXDATE))
-endif
-CFLAGS		+= -DDATE_STR='"$(DATE)"'
-
-$(OBJ)/$(ARCH):
-	mkdir -p $@
-
-$(OBJS): | $(OBJ)/$(ARCH)
-
-# The targets to build in this directory
-BTARGET  = syslinux.efi
-
-syslinux.so: $(OBJS) $(CORE_OBJS) $(LIB_OBJS)
-	$(LD) $(LDFLAGS) --strip-debug -o $@ $^ -lgnuefi -lefi
-
-# We need to rename the .hash section because the EFI firmware
-# linker really doesn't like it.
-# $(OBJCOPY) --rename-section .gnu.hash=.sdata,load,data,alloc $^ $@
-#syslinux.so: syslinux1.so
-#	cp $^ $@
-
-wrapper: wrapper.c
-	$(CC_FOR_BUILD) $^ -o $@
-
-#
-# Build the wrapper app and wrap our .so to produce a .efi
-syslinux.efi: syslinux.so wrapper
-	$(OBJ)/wrapper syslinux.so $@
-
-all: $(BTARGET)
-
-codepage.o: ../codepage/cp865.cp
-	cp $(objdir)/../codepage/cp865.cp codepage.cp
-	$(CC) $(SFLAGS) -c -o $@ $(core)/codepage.S
-
-install:
-	install -m 755 $(BTARGET) $(INSTALLROOT)$(AUXDIR)
-
-strip:
-
-tidy dist:
-	rm -f *.so *.o wrapper
-	find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \
-		xargs -0r rm -f
-	$(topdir)/efi/clean-gnu-efi.sh $(EFI_SUBARCH) $(objdir)
-
-clean: tidy
-
-spotless: clean
-	rm -f $(BTARGET)
diff --git a/efi/build-gnu-efi.sh b/efi/build-gnu-efi.sh
deleted file mode 100755
index 63460b69..00000000
--- a/efi/build-gnu-efi.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/sh
-
-set -e
-
-# Initialise the gnu-efi submodule and ensure the source is up-to-date.
-# Then build and install it for the given architecture.
-
-if [ $# -lt 2 ]; then
-cat <<EOF
-Usage: $0: <arch> <objdir>
-
-Build the <arch> gnu-efi libs and header files and install in <objdir>.
-
-  <arch>   - A gnu-efi \$ARCH argument, i.e. ia32, x86_64
-  <objdir> - The Syslinux object directory
-
-EOF
-    exit 1
-fi
-
-ARCH="$1"
-objdir="$(readlink -f $2)"
-
-if [ ! -e ../version.h ]; then
-    printf "build-gnu-efi.sh: Cannot be run outside Syslinux object tree\n"
-    pwd
-    exit 1
-fi
-
-(
-	cd ../..
-	if [ -d .git ]; then
-	    git submodule update --init
-	fi
-)
-
-mkdir -p "$objdir/gnu-efi"
-cd "$objdir/gnu-efi"
-
-EFIDIR="$(readlink -f "$objdir/../gnu-efi")"
-
-make SRCDIR="$EFIDIR" TOPDIR="$EFIDIR" -f "$EFIDIR/Makefile" ARCH=$ARCH
-make SRCDIR="$EFIDIR" TOPDIR="$EFIDIR" -f "$EFIDIR/Makefile" ARCH=$ARCH PREFIX="$objdir" install
-
-cd "$objdir/efi"
diff --git a/efi/check-gnu-efi.sh b/efi/check-gnu-efi.sh
deleted file mode 100755
index 7d99e9ab..00000000
--- a/efi/check-gnu-efi.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/sh
-
-# Verify that gnu-efi is installed in the object directory for our
-# firmware. If it isn't, build it.
-
-if [ $# -lt 2 ]; then
-cat <<EOF
-Usage: $0: <arch> <objdir>
-
-Check for gnu-efi libraries and header files in <objdir> and, if none
-exist, build and install them.
-
-  <arch>   - A gnu-efi \$ARCH argument, i.e. ia32, x86_64
-  <objdir> - The Syslinux object directory
-
-EOF
-    exit 1
-fi
-
-ARCH=$1
-objdir=$2
-
-if [ ! \( -f "$objdir/include/efi/$ARCH/efibind.h" -a -f "$objdir/lib/libefi.a" -a -f "$objdir/lib/libgnuefi.a" \) ]; then
-    # Build the external project with a clean make environment, as
-    # Syslinux disables built-in implicit rules.
-    export MAKEFLAGS=
-
-    ../../efi/build-gnu-efi.sh $ARCH "$objdir"
-    if [ $? -ne 0 ]; then
-	printf "Failed to build gnu-efi. "
-	printf "Execute the following command for full details: \n\n"
-	printf "build-gnu-efi.sh $ARCH $objdir\n\n"
-
-	exit 1
-    fi
-else
-    printf "skip gnu-efi build/install\n"
-fi
diff --git a/efi/clean-gnu-efi.sh b/efi/clean-gnu-efi.sh
deleted file mode 100755
index bc950261..00000000
--- a/efi/clean-gnu-efi.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-
-set -e
-
-# Initialise the gnu-efi submodule and ensure the source is up-to-date.
-# Then build and install it for the given architecture.
-
-if [ $# -lt 2 ]; then
-cat <<EOF
-Usage: $0: <arch> <objdir>
-
-Build the <arch> gnu-efi libs and header files and install in <objdir>.
-
-  <arch>   - A gnu-efi \$ARCH argument, i.e. ia32, x86_64
-  <objdir> - The Syslinux object directory
-
-EOF
-    exit 1
-fi
-
-ARCH="$1"
-objdir=$(readlink -f "$2")
-
-(
-	cd ../..
-	if [ -d .git ]; then
-	    git submodule update --init
-	fi
-)
-
-if [ -d "$objdir/gnu-efi" ];then
-	cd "$objdir/gnu-efi"
-	EFIDIR="$(readlink -f "$objdir/../gnu-efi")"
-	make SRCDIR="$EFIDIR" TOPDIR="$EFIDIR" -f "$EFIDIR/Makefile" ARCH=$ARCH clean
-fi
-
-cd "$objdir/efi"
diff --git a/mk/bios.mk b/mk/bios.mk
new file mode 100644
index 00000000..89d8f00d
--- /dev/null
+++ b/mk/bios.mk
@@ -0,0 +1 @@
+GCCOPT += -mregparm=3 -DREGPARM=3
diff --git a/mk/build.mk b/mk/build.mk
index 9becd412..de0e90d8 100644
--- a/mk/build.mk
+++ b/mk/build.mk
@@ -16,18 +16,22 @@
 ##
 include $(MAKEDIR)/syslinux.mk
 
-OPTFLAGS   = -g -Os
-INCLUDES   =
-CFLAGS     = $(WARNFLAGS) -D_FILE_OFFSET_BITS=64 \
-             $(OPTFLAGS) $(INCLUDES)
-LDFLAGS    =
-LIBS	   =
+OPTFLAGS   = -g -O2
+INCLUDES   = -I$(SRC)/include
+CFLAGS_FOR_BUILD ?= $(WARNFLAGS) -D_FILE_OFFSET_BITS=64  $(OPTFLAGS)
+CFLAGS_FOR_BUILD += $(INCLUDES)
+LDFLAGS_FOR_BUILD =
+LIBS_FOR_BUILD   =
 
 .SUFFIXES: .c .o .S .s .i .elf .com .bin .asm .lst .c32 .lss
 
 %.o: %.c
-	$(CC) $(UMAKEDEPS) $(CFLAGS) -c -o $@ $<
+	$(CC_FOR_BUILD) $(UMAKEDEPS) $(CFLAGS_FOR_BUILD) -c -o $@ $<
 %.i: %.c
-	$(CC) $(UMAKEDEPS) $(CFLAGS) -E -o $@ $<
+	$(CC_FOR_BUILD) $(UMAKEDEPS) $(CFLAGS_FOR_BUILD) -E -o $@ $<
 %.s: %.c
-	$(CC) $(UMAKEDEPS) $(CFLAGS) -S -o $@ $<
+	$(CC_FOR_BUILD) $(UMAKEDEPS) $(CFLAGS_FOR_BUILD) -S -o $@ $<
+%: %.o
+	$(CC_FOR_BUILD) $(UMAKEDEPS) $(CFLAGS_FOR_BUILD) \
+		$(LDFLAGS_FOR_BUILD) -o $@ $^ $(LIBS_FOR_BUILD)
+
diff --git a/mk/efi.mk b/mk/efi.mk
index 18346b44..78a17b3d 100644
--- a/mk/efi.mk
+++ b/mk/efi.mk
@@ -1,54 +1,32 @@
-include $(MAKEDIR)/syslinux.mk
-
-com32 = $(topdir)/com32
-core = $(topdir)/core
-
 # Support IA32 and x86_64 platforms with one build
 # Set up architecture specifics; for cross compilation, set ARCH as apt
 # gnuefi sets up architecture specifics in ia32 or x86_64 sub directories
 # set up the LIBDIR and EFIINC for building for the appropriate architecture
-GCCOPT := $(call gcc_ok,-fno-stack-protector,)
-EFIINC = $(objdir)/include/efi
-LIBDIR  = $(objdir)/lib
+GCCOPT += -DEFI_FUNCTION_WRAPPER
+GCCOPT += -mno-red-zone
+GCCOPT += -fshort-wchar
+
+FWFLAGS = -Wno-unused-parameter -Wno-strict-prototypes
 
-ifeq ($(ARCH),i386)
-	ARCHOPT = -m32 -march=i386
-	EFI_SUBARCH = ia32
-endif
-ifeq ($(ARCH),x86_64)
-	ARCHOPT = -m64 -march=x86-64
-	EFI_SUBARCH = $(ARCH)
-endif
+FWLIBS  = 
 
-#LIBDIR=/usr/lib
+EFIINCDIR  = $(objdir)/com32/efi/include/efi
+EFILIBDIR  = $(objdir)/com32/efi/lib
+
+EFI_SUBARCH := $(ARCH:i386=ia32)
 FORMAT=efi-app-$(EFI_SUBARCH)
 
-CFLAGS = -I$(EFIINC) -I$(EFIINC)/$(EFI_SUBARCH) \
-		-DEFI_FUNCTION_WRAPPER -fPIC -fshort-wchar -ffreestanding \
-		-Wall -I$(com32)/include -I$(com32)/include/sys \
-		-I$(core)/include -I$(core)/ $(ARCHOPT) \
-		-I$(com32)/lib/ -I$(com32)/libutil/include -std=gnu99 \
-		-DELF_DEBUG -DSYSLINUX_EFI -I$(objdir) \
-		$(GCCWARN) -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ -mno-red-zone \
-		-DLDLINUX=\"$(LDLINUX)\" -fvisibility=hidden \
-		-Wno-unused-parameter $(GCCOPT)
+INCLUDE += -I$(EFIINCDIR) -I$(EFIINCDIR)/$(EFI_SUBARCH)
 
-CRT0 := $(LIBDIR)/crt0-efi-$(EFI_SUBARCH).o
-LDSCRIPT := $(LIBDIR)/elf_$(EFI_SUBARCH)_efi.lds
+CRT0     = $(LIBDIR)/crt0-efi-$(EFI_SUBARCH).o
+LDSCRIPT = $(LIBDIR)/elf_$(EFI_SUBARCH)_efi.lds
 
-LDFLAGS = -T $(SRC)/$(ARCH)/syslinux.ld -Bsymbolic -pie -nostdlib -znocombreloc \
+MAIN_LDFLAGS += -T $(EFILIBSRC)/$(ARCH)/syslinux.ld -Bsymbolic -pie -nostdlib -znocombreloc \
 		-L$(LIBDIR) --hash-style=gnu -m elf_$(ARCH) $(CRT0) -E
 
-SFLAGS     = $(GCCOPT) $(GCCWARN) $(ARCHOPT) \
-	     -fomit-frame-pointer -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ \
-	     -nostdinc -iwithprefix include \
-	     -I$(com32)/libutil/include -I$(com32)/include -I$(com32)/include/sys $(GPLINCLUDE)
-
-LIBEFI = $(objdir)/lib/libefi.a
+SFLAGS     = $(CFLAGS) -D__ASSEMBLY__
 
-$(LIBEFI):
-	@echo Building gnu-efi for $(EFI_SUBARCH)
-	$(topdir)/efi/check-gnu-efi.sh $(EFI_SUBARCH) $(objdir)
+LIBEFI = $(com32)/efi/lib/libefi.a
 
 %.o: %.S	# Cancel old rule
 
@@ -59,7 +37,3 @@ $(LIBEFI):
 
 %.o: %.c $(LIBEFI)
 	$(CC) $(CFLAGS) -c -o $@ $<
-
-#%.efi: %.so
-#	$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
-#		-j .rela -j .reloc --target=$(FORMAT) $*.so $@
diff --git a/mk/elf.mk b/mk/elf.mk
index 8e7f4dba..2198a159 100644
--- a/mk/elf.mk
+++ b/mk/elf.mk
@@ -14,22 +14,28 @@
 ## ELF common configurables
 ##
 
+# Needs to start out as null otherwise we get a recursive error
+GCCOPT   :=
+
 include $(MAKEDIR)/syslinux.mk
+include $(MAKEDIR)/$(fwclass).mk
 
 # Support IA32 and x86_64 platforms with one build
 # Set up architecture specifics; for cross compilation, set ARCH as apt
-GCCOPT := $(call gcc_ok,-std=gnu99,)
+GCCOPT += $(call gcc_ok,-std=gnu99,)
 ifeq ($(ARCH),i386)
-	GCCOPT += $(call gcc_ok,-m32,)
-	GCCOPT += $(call gcc_ok,-march=i386)
+	GCCOPT += -m32 -march=i386
 	GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,)
+	NASMFLAGS += -f elf
 endif
 ifeq ($(ARCH),x86_64)
-	GCCOPT += $(call gcc_ok,-m64,)
+	GCCOPT += -m64 -march=x86-64
 	GCCOPT += $(call gcc_ok,-march=x86-64)
-	#let preferred-stack-boundary be default (=4)
+# let preferred-stack-boundary be default (=4)
+	NASMFLAGS += -f elf64
 endif
 GCCOPT += -Os -fomit-frame-pointer
+GCCOPT += $(call gcc_ok,-mtune=generic,)
 GCCOPT += $(call gcc_ok,-fno-stack-protector,)
 GCCOPT += $(call gcc_ok,-fwrapv,)
 GCCOPT += $(call gcc_ok,-freg-struct-return,)
@@ -44,12 +50,6 @@ GCCOPT += $(call gcc_ok,-falign-labels=0,-malign-labels=0)
 GCCOPT += $(call gcc_ok,-falign-loops=0,-malign-loops=0)
 GCCOPT += $(call gcc_ok,-DNO_PLT -fno-plt -fvisibility=protected)
 
-ifeq ($(FWCLASS),EFI)
-GCCOPT += -mno-red-zone
-else
-GCCOPT += -mregparm=3 -DREGPARM=3
-endif
-
 com32 = $(topdir)/com32
 core = $(topdir)/core
 
@@ -70,10 +70,10 @@ LIBLDLINUX = $(objdir)/ldlinux/$(LDLINUX)
 LIBCOM32  = $(objdir)/com32/lib/libcom32.c32
 LIBUTIL   = $(objdir)/com32/libutil/libutil.c32
 
-INCLUDE =  -nostdinc -iwithprefix include -I$(SRC) \
+INCLUDE += -nostdinc -iwithprefix include -I$(SRC) \
 	     -I$(com32)/libutil/include -I$(com32)/include \
-	     -I$(com32)/include/sys $(GPLINCLUDE) -I$(core)/include \
-	     -I$(objdir)
+	     -I$(com32)/include/sys $(GPLINCLUDE) \
+	     -I$(core)/include -I$(core)/$(fwclass)/include -I$(objdir)
 
 OPTFLAGS  = -Os -march=$(ARCH) -falign-functions=0 -falign-jumps=0 \
 	    -falign-labels=0 -ffast-math -fomit-frame-pointer
@@ -83,7 +83,7 @@ WARNFLAGS = $(GCCWARN) -Wpointer-arith -Wwrite-strings \
 REQFLAGS  = $(GCCOPT) -g -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ \
 	     -DLDLINUX=\"$(LDLINUX)\" $(INCLUDE)
 
-CFLAGS     = $(REQFLAGS) $(OPTFLAGS) $(WARNFLAGS)
+CFLAGS     = $(REQFLAGS) $(OPTFLAGS) $(WARNFLAGS) $(FWFLAGS)
 
 SFLAGS     = $(REQFLAGS) -D__ASSEMBLY__
 LDSCRIPT   	= $(com32)/lib/$(ARCH)/elf.ld
@@ -94,9 +94,7 @@ MAIN_LDFLAGS	= -m elf_$(ARCH) -Bsymbolic --hash-style=gnu \
 LDFLAGS    = $(MAIN_LDFLAGS) -T $(LDSCRIPT)
 
 ifeq ($(ARCH),i386)
-NASMFLAGS += -f elf
 else
-NASMFLAGS += -f elf64
 endif
 NASMDEBUG  = -g -F dwarf
 NASMFLAGS += $(NASMDEBUG) -D__$(ARCH)__ -I$(SRC)/ $(filter -D%,$(CFLAGS))
diff --git a/mk/syslinux.mk b/mk/syslinux.mk
index 7154ceb4..bf0c4310 100644
--- a/mk/syslinux.mk
+++ b/mk/syslinux.mk
@@ -75,6 +75,8 @@ MKISOFS  = mkisofs
 SED	 = sed
 WGET	 = wget
 
+CC_FOR_BUILD ?= $(CC)
+
 com32    = $(topdir)/com32
 
 # Architecture definition
diff --git a/lzo/.gitignore b/prepcore/bios/.gitignore
similarity index 100%
rename from lzo/.gitignore
rename to prepcore/bios/.gitignore
diff --git a/lzo/Makefile b/prepcore/bios/Makefile
similarity index 83%
rename from lzo/Makefile
rename to prepcore/bios/Makefile
index 29f1fa62..7175bc03 100644
--- a/lzo/Makefile
+++ b/prepcore/bios/Makefile
@@ -13,9 +13,8 @@
 VPATH = $(SRC)
 include $(MAKEDIR)/build.mk
 
-INCLUDES += -I$(SRC)/include
-
-LIBOBJS = $(patsubst %.c,%.o,$(subst $(SRC)/,,$(sort $(wildcard $(SRC)/src/*.c))))
+LIBSRCS = $(sort $(wildcard $(SRC)/src/*.c))
+LIBOBJS = $(LIBSRCS:$(SRC)/%.c=%.o)
 LIB     = lzo.a
 BINS    = prepcore
 
@@ -29,8 +28,7 @@ $(LIB) : $(LIBOBJS)
 	$(AR) cq $@ $^
 	$(RANLIB) $@
 
-prepcore : prepcore.o $(LIB)
-	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+prepcore: prepcore.o $(LIB)
 
 tidy dist clean spotless:
 	rm -f $(BINS)
diff --git a/lzo/doc/LZO.TXT b/prepcore/bios/doc/LZO.TXT
similarity index 100%
rename from lzo/doc/LZO.TXT
rename to prepcore/bios/doc/LZO.TXT
diff --git a/lzo/include/lzo/lzo1.h b/prepcore/bios/include/lzo/lzo1.h
similarity index 100%
rename from lzo/include/lzo/lzo1.h
rename to prepcore/bios/include/lzo/lzo1.h
diff --git a/lzo/include/lzo/lzo1a.h b/prepcore/bios/include/lzo/lzo1a.h
similarity index 100%
rename from lzo/include/lzo/lzo1a.h
rename to prepcore/bios/include/lzo/lzo1a.h
diff --git a/lzo/include/lzo/lzo1b.h b/prepcore/bios/include/lzo/lzo1b.h
similarity index 100%
rename from lzo/include/lzo/lzo1b.h
rename to prepcore/bios/include/lzo/lzo1b.h
diff --git a/lzo/include/lzo/lzo1c.h b/prepcore/bios/include/lzo/lzo1c.h
similarity index 100%
rename from lzo/include/lzo/lzo1c.h
rename to prepcore/bios/include/lzo/lzo1c.h
diff --git a/lzo/include/lzo/lzo1f.h b/prepcore/bios/include/lzo/lzo1f.h
similarity index 100%
rename from lzo/include/lzo/lzo1f.h
rename to prepcore/bios/include/lzo/lzo1f.h
diff --git a/lzo/include/lzo/lzo1x.h b/prepcore/bios/include/lzo/lzo1x.h
similarity index 100%
rename from lzo/include/lzo/lzo1x.h
rename to prepcore/bios/include/lzo/lzo1x.h
diff --git a/lzo/include/lzo/lzo1y.h b/prepcore/bios/include/lzo/lzo1y.h
similarity index 100%
rename from lzo/include/lzo/lzo1y.h
rename to prepcore/bios/include/lzo/lzo1y.h
diff --git a/lzo/include/lzo/lzo1z.h b/prepcore/bios/include/lzo/lzo1z.h
similarity index 100%
rename from lzo/include/lzo/lzo1z.h
rename to prepcore/bios/include/lzo/lzo1z.h
diff --git a/lzo/include/lzo/lzo2a.h b/prepcore/bios/include/lzo/lzo2a.h
similarity index 100%
rename from lzo/include/lzo/lzo2a.h
rename to prepcore/bios/include/lzo/lzo2a.h
diff --git a/lzo/include/lzo/lzo_asm.h b/prepcore/bios/include/lzo/lzo_asm.h
similarity index 100%
rename from lzo/include/lzo/lzo_asm.h
rename to prepcore/bios/include/lzo/lzo_asm.h
diff --git a/lzo/include/lzo/lzoconf.h b/prepcore/bios/include/lzo/lzoconf.h
similarity index 100%
rename from lzo/include/lzo/lzoconf.h
rename to prepcore/bios/include/lzo/lzoconf.h
diff --git a/lzo/include/lzo/lzodefs.h b/prepcore/bios/include/lzo/lzodefs.h
similarity index 100%
rename from lzo/include/lzo/lzodefs.h
rename to prepcore/bios/include/lzo/lzodefs.h
diff --git a/lzo/include/lzo/lzoutil.h b/prepcore/bios/include/lzo/lzoutil.h
similarity index 100%
rename from lzo/include/lzo/lzoutil.h
rename to prepcore/bios/include/lzo/lzoutil.h
diff --git a/lzo/prepcore.c b/prepcore/bios/prepcore.c
similarity index 100%
rename from lzo/prepcore.c
rename to prepcore/bios/prepcore.c
diff --git a/lzo/src/compr1b.h b/prepcore/bios/src/compr1b.h
similarity index 100%
rename from lzo/src/compr1b.h
rename to prepcore/bios/src/compr1b.h
diff --git a/lzo/src/compr1c.h b/prepcore/bios/src/compr1c.h
similarity index 100%
rename from lzo/src/compr1c.h
rename to prepcore/bios/src/compr1c.h
diff --git a/lzo/src/config1x.h b/prepcore/bios/src/config1x.h
similarity index 100%
rename from lzo/src/config1x.h
rename to prepcore/bios/src/config1x.h
diff --git a/lzo/src/lzo1_d.ch b/prepcore/bios/src/lzo1_d.ch
similarity index 100%
rename from lzo/src/lzo1_d.ch
rename to prepcore/bios/src/lzo1_d.ch
diff --git a/lzo/src/lzo1x_1.c b/prepcore/bios/src/lzo1x_1.c
similarity index 100%
rename from lzo/src/lzo1x_1.c
rename to prepcore/bios/src/lzo1x_1.c
diff --git a/lzo/src/lzo1x_1k.c b/prepcore/bios/src/lzo1x_1k.c
similarity index 100%
rename from lzo/src/lzo1x_1k.c
rename to prepcore/bios/src/lzo1x_1k.c
diff --git a/lzo/src/lzo1x_1l.c b/prepcore/bios/src/lzo1x_1l.c
similarity index 100%
rename from lzo/src/lzo1x_1l.c
rename to prepcore/bios/src/lzo1x_1l.c
diff --git a/lzo/src/lzo1x_1o.c b/prepcore/bios/src/lzo1x_1o.c
similarity index 100%
rename from lzo/src/lzo1x_1o.c
rename to prepcore/bios/src/lzo1x_1o.c
diff --git a/lzo/src/lzo1x_9x.c b/prepcore/bios/src/lzo1x_9x.c
similarity index 100%
rename from lzo/src/lzo1x_9x.c
rename to prepcore/bios/src/lzo1x_9x.c
diff --git a/lzo/src/lzo1x_c.ch b/prepcore/bios/src/lzo1x_c.ch
similarity index 100%
rename from lzo/src/lzo1x_c.ch
rename to prepcore/bios/src/lzo1x_c.ch
diff --git a/lzo/src/lzo1x_d.ch b/prepcore/bios/src/lzo1x_d.ch
similarity index 100%
rename from lzo/src/lzo1x_d.ch
rename to prepcore/bios/src/lzo1x_d.ch
diff --git a/lzo/src/lzo1x_d1.c b/prepcore/bios/src/lzo1x_d1.c
similarity index 100%
rename from lzo/src/lzo1x_d1.c
rename to prepcore/bios/src/lzo1x_d1.c
diff --git a/lzo/src/lzo1x_d2.c b/prepcore/bios/src/lzo1x_d2.c
similarity index 100%
rename from lzo/src/lzo1x_d2.c
rename to prepcore/bios/src/lzo1x_d2.c
diff --git a/lzo/src/lzo1x_d3.c b/prepcore/bios/src/lzo1x_d3.c
similarity index 100%
rename from lzo/src/lzo1x_d3.c
rename to prepcore/bios/src/lzo1x_d3.c
diff --git a/lzo/src/lzo1x_o.c b/prepcore/bios/src/lzo1x_o.c
similarity index 100%
rename from lzo/src/lzo1x_o.c
rename to prepcore/bios/src/lzo1x_o.c
diff --git a/lzo/src/lzo1x_oo.ch b/prepcore/bios/src/lzo1x_oo.ch
similarity index 100%
rename from lzo/src/lzo1x_oo.ch
rename to prepcore/bios/src/lzo1x_oo.ch
diff --git a/lzo/src/lzo_conf.h b/prepcore/bios/src/lzo_conf.h
similarity index 100%
rename from lzo/src/lzo_conf.h
rename to prepcore/bios/src/lzo_conf.h
diff --git a/lzo/src/lzo_crc.c b/prepcore/bios/src/lzo_crc.c
similarity index 100%
rename from lzo/src/lzo_crc.c
rename to prepcore/bios/src/lzo_crc.c
diff --git a/lzo/src/lzo_dict.h b/prepcore/bios/src/lzo_dict.h
similarity index 100%
rename from lzo/src/lzo_dict.h
rename to prepcore/bios/src/lzo_dict.h
diff --git a/lzo/src/lzo_dll.ch b/prepcore/bios/src/lzo_dll.ch
similarity index 100%
rename from lzo/src/lzo_dll.ch
rename to prepcore/bios/src/lzo_dll.ch
diff --git a/lzo/src/lzo_func.h b/prepcore/bios/src/lzo_func.h
similarity index 100%
rename from lzo/src/lzo_func.h
rename to prepcore/bios/src/lzo_func.h
diff --git a/lzo/src/lzo_init.c b/prepcore/bios/src/lzo_init.c
similarity index 100%
rename from lzo/src/lzo_init.c
rename to prepcore/bios/src/lzo_init.c
diff --git a/lzo/src/lzo_mchw.ch b/prepcore/bios/src/lzo_mchw.ch
similarity index 100%
rename from lzo/src/lzo_mchw.ch
rename to prepcore/bios/src/lzo_mchw.ch
diff --git a/lzo/src/lzo_ptr.c b/prepcore/bios/src/lzo_ptr.c
similarity index 100%
rename from lzo/src/lzo_ptr.c
rename to prepcore/bios/src/lzo_ptr.c
diff --git a/lzo/src/lzo_ptr.h b/prepcore/bios/src/lzo_ptr.h
similarity index 100%
rename from lzo/src/lzo_ptr.h
rename to prepcore/bios/src/lzo_ptr.h
diff --git a/lzo/src/lzo_str.c b/prepcore/bios/src/lzo_str.c
similarity index 100%
rename from lzo/src/lzo_str.c
rename to prepcore/bios/src/lzo_str.c
diff --git a/lzo/src/lzo_supp.h b/prepcore/bios/src/lzo_supp.h
similarity index 100%
rename from lzo/src/lzo_supp.h
rename to prepcore/bios/src/lzo_supp.h
diff --git a/lzo/src/lzo_swd.ch b/prepcore/bios/src/lzo_swd.ch
similarity index 100%
rename from lzo/src/lzo_swd.ch
rename to prepcore/bios/src/lzo_swd.ch
diff --git a/lzo/src/lzo_util.c b/prepcore/bios/src/lzo_util.c
similarity index 100%
rename from lzo/src/lzo_util.c
rename to prepcore/bios/src/lzo_util.c
diff --git a/lzo/src/miniacc.h b/prepcore/bios/src/miniacc.h
similarity index 100%
rename from lzo/src/miniacc.h
rename to prepcore/bios/src/miniacc.h
diff --git a/lzo/src/stats1a.h b/prepcore/bios/src/stats1a.h
similarity index 100%
rename from lzo/src/stats1a.h
rename to prepcore/bios/src/stats1a.h
diff --git a/lzo/src/stats1b.h b/prepcore/bios/src/stats1b.h
similarity index 100%
rename from lzo/src/stats1b.h
rename to prepcore/bios/src/stats1b.h
diff --git a/lzo/src/stats1c.h b/prepcore/bios/src/stats1c.h
similarity index 100%
rename from lzo/src/stats1c.h
rename to prepcore/bios/src/stats1c.h
diff --git a/com32/tools/Makefile b/prepcore/efi/Makefile
similarity index 86%
copy from com32/tools/Makefile
copy to prepcore/efi/Makefile
index d64fc1d9..bfce0c4b 100644
--- a/com32/tools/Makefile
+++ b/prepcore/efi/Makefile
@@ -1,6 +1,6 @@
 ## -*- makefile -*- ------------------------------------------------------
 ##
-##   Copyright 2001-2016 H. Peter Anvin - All Rights Reserved
+##   Copyright 2019 Intel Corporation; author: H. Peter Anvin
 ##
 ##   This program is free software; you can redistribute it and/or modify
 ##   it under the terms of the GNU General Public License as published by
@@ -10,13 +10,12 @@
 ##
 ## -----------------------------------------------------------------------
 
-VPATH = $(SRC)
 include $(MAKEDIR)/build.mk
 
-BINS    =
-
 INCLUDES += -I$(SRC)/include
 
+BINS    = prepcore
+
 all : $(BINS)
 
 tidy dist clean spotless:
@@ -24,6 +23,8 @@ tidy dist clean spotless:
 	rm -f *.o *.a .*.d
 	rm -f */*.o */*.a */.*.d
 
-install installer:
+installer:
+
+prepcore: prepcore.o
 
 -include .*.d */.*.d
diff --git a/efi/wrapper.c b/prepcore/efi/prepcore.c
similarity index 95%
rename from efi/wrapper.c
rename to prepcore/efi/prepcore.c
index 19881248..04033464 100644
--- a/efi/wrapper.c
+++ b/prepcore/efi/prepcore.c
@@ -14,7 +14,7 @@
  * point. Once the Syslinux ELF shared object has control we can do
  * whatever we want.
  */
-#include <linux/elf.h>
+#include <elf.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
@@ -22,17 +22,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "wrapper.h"
-
-#if __SIZEOF_POINTER__ == 4
-typedef Elf32_Ehdr Elf_Ehdr;
-typedef Elf32_Addr Elf_Addr;
-#elif __SIZEOF_POINTER__ == 8
-typedef Elf64_Ehdr Elf_Ehdr;
-typedef Elf64_Addr Elf_Addr;
-#else
-#error "unsupported architecture"
-#endif
+#include "prepcore.h"
 
 /*
  * 'so_memsz' is the size of the ELF shared object once loaded.
@@ -163,10 +153,10 @@ int main(int argc, char **argv)
 {
 	Elf32_Ehdr e32_hdr;
 	Elf64_Ehdr e64_hdr;
-	__uint32_t entry;
-	__uint8_t class;
-	__uint64_t phoff = 0;
-	__uint16_t phnum = 0, phentsize = 0;
+	uint32_t entry;
+	uint8_t class;
+	uint64_t phoff = 0;
+	uint16_t phnum = 0, phentsize = 0;
 	unsigned char *id;
 	FILE *f_in, *f_out;
 	void *buf;
diff --git a/efi/wrapper.h b/prepcore/efi/prepcore.h
similarity index 100%
rename from efi/wrapper.h
rename to prepcore/efi/prepcore.h


More information about the Syslinux-commits mailing list