
SYS_AS86 = $(_AS86_) -l
AS86 = $(_AS86_) -0 -a
LD86 = $(_LD86_) -0

D=$(REALTOPDIR)/$(THISVERSION)/commands

SRC=exitemu.S vgaoff.S vgaon.S eject.S lredir.c lredir.readme dumpconf.asm \
	bootoff.S booton.S dosdbg.c dosdbg.readme emumouse.c isemu.c \
	emufs.S ems.S cdrom.S chdir.c getcwd.c system.c unix.c fossil.S \
	ecpuon.S ecpuoff.S speed.c emulib.c emulib.h mgarrot.a86 compile.bat
COM=$(D)/exitemu.com $(D)/vgaoff.com $(D)/vgaon.com $(D)/eject.com \
	$(D)/bootoff.com $(D)/booton.com $(D)/fossil.com \
	$(D)/ecpuon.com $(D)/ecpuoff.com
EXE=lredir.com dumpconf.exe dosdbg.com lancheck.exe isemu.com unix.com \
	emumouse.com mgarrot.com isemu.com speed.com \
	chdir.com getcwd.com system.com
SYS=$(D)/emufs.sys $(D)/ems.sys $(D)/cdrom.sys
DOC=README

all: $(COM) $(SYS)

%.s:	%.S detect.h
	$(CC) -E -D__AS86__ --traditional -I../include $<  > $*.s

$(D)/%.sys: %.s
	$(SYS_AS86) -0 -o $*.o $< > $<.out
	$(LD86) -T 0 -s -o $*.tmp $*.o
	dd if=$*.tmp of=$@ bs=1 skip=32
	rm $*.tmp $*.o

$(D)/%.com: %.s
	$(AS86) -0 -o $*.o $<
	$(LD86) -T 0 -s -o $*.tmp $*.o
	dd if=$*.tmp of=$@ bs=1 skip=288
	rm -f $*.tmp $*.o

# The commands above require that you use ".org 0" which doesn't work at all
# if you need absolute addresses. Just use ".org 0x100" and cut the extra
# bytes using dd.
$(D)/fossil.com: fossil.s
	$(AS86) -0 -o $*.o $<
	$(LD86) -T 0 -s -o $*.tmp $*.o
	dd if=$*.tmp of=$@ bs=1 skip=288
	rm -f $*.tmp $*.o

checkin:
	-ci -l $(SRC) $(EXE)

checkout:
	-co -M -l $(SRC) $(EXE)

clean:
	rm -f *.o *.tmp *.out *.s
	rm -f $(COM) $(SYS)

realclean: clean

dist: Makefile $(SRC)
	install -d $(DISTPATH)/commands
	install -m 0644 Makefile $(SRC) $(EXE) $(DOC) $(DISTPATH)/commands

install:
