#
# Copyright (c) 1995-1996 The University of Utah and
# the Computer Systems Laboratory at the University of Utah (CSL).
# All rights reserved.
#
# Permission to use, copy, modify and distribute this software is hereby
# granted provided that (1) source code retains these copyright, permission,
# and disclaimer notices, and (2) redistributions including binaries
# reproduce the notices in supporting documentation, and (3) all advertising
# materials mentioning features or use of this software display the following
# acknowledgement: ``This product includes software developed by the
# Computer Systems Laboratory at the University of Utah.''
#
# THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
# IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
# ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
# CSL requests users of this software to return to csl-dist@cs.utah.edu any
# improvements that they make and grant CSL redistribution rights.
#

# This is a generic set of rules to build DOS executables (.exe files).
# TARGET must be set to the executable filename without the .exe suffix.
# Assumes the build tools support the i386msdos format and emulation.
# Currently also assumes we're using ELF for object files and such.
#
ifndef _oskit_makerules_i386_exe_
_oskit_makerules_i386_exe_ = yes


all: $(TARGET).exe

CLEAN_FILES += $(TARGET) $(TARGET).exe


include $(OSKIT_SRCDIR)/Makerules


# Make sure crt0 gets put is at the very beginning,
# and crtn gets put at the very end.
OBJFILES := i16_crt0.o $(filter-out i16_crt0.o crtn.o,$(OBJFILES)) crtn.o


# First link the program as an ELF executable,
# but with the proper MS-DOS memory layout;
# then use objcopy to transform the result into an MSDOS executable.
# This approach has three advantages:
#	* It avoids some bugs in the MSDOS BFD backend.
#	* It allows some ELF features unsupported
#	  by the MSDOS backend to be used.
#	* It provides with a convenient nm-able and objdump-able
#	  version of the executable, for debugging purposes.

$(TARGET): $(OBJFILES)
	$(LD) $(LDFLAGS) $(OSKIT_LDFLAGS) \
		-m i386msdos -oformat elf32-i386 \
		-o $@ $(OBJFILES) $(LDLIBS)

$(TARGET).exe: $(TARGET)
	$(OBJCOPY) -O msdos $< $@


install: $(INSTALL_BINDIR)/$(TARGET).exe


endif
