#
# filesystems/Make.gnuefi
# Build control file for the EFI drivers, as built 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 <http://www.gnu.org/licenses/>.

SRCDIR = .

VPATH = $(SRCDIR)
HOSTARCH        = $(shell uname -m | sed s,i[3456789]86,ia32,)

LOCAL_GNUEFI_CFLAGS   = -DFSTYPE=$(DRIVERNAME) -I$(SRCDIR) 
ifeq ($(HOSTARCH),x86_64)
  LOCAL_GNUEFI_CFLAGS += "-DEFIAPI=__attribute__((ms_abi))" 
endif

OBJS            = fsw_core.o fsw_efi.o fsw_efi_lib.o fsw_lib.o fsw_$(DRIVERNAME).o
TARGET          = $(DRIVERNAME)_$(FILENAME_CODE).efi

include $(SRCDIR)/../Make.common

all: $(TARGET)

ifeq ($(HOSTARCH),aarch64)
  # Set symbol for driver
  SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xb
endif

$(SHLIB_TARGET): $(OBJS)
	$(LD) $(GNUEFI_LDFLAGS) $(SUBSYSTEM_LDFLAG) $(OBJS) -o $@ $(LOCAL_LIBS) $(GNUEFI_LIBS)

$(TARGET): $(SHLIB_TARGET)
	$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
	           -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \
		   -j .reloc $(FORMAT_DRIVER) $< $@
	chmod a-x $(TARGET)
	mkdir -p ../drivers_$(FILENAME_CODE)
	cp $(TARGET) ../drivers_$(FILENAME_CODE)

# EOF
