# makes the SYSTEM-Unit for Linux
#
# Copyright (c) 1996 by Michael Van Canneyt

# AOUT should be defined in main  makefile.
# But you can set it here too.
# AOUT = -DAOUT

# set the directory where to install the units.
# This one is defined here as a default, 
# but should be overridden from the main makefile

ifndef LIBINSTALLDIR
LIBINSTALLDIR=/usr/lib/ppc/0.9.1
# LIBINSTALLDIR=/usr/lib/ppc/aout/0.9.1
endif 

# Do you want to link to the C library ?
# Standard it is no.
ifndef LINK_TO_C
LINK_TO_C=NO
endif

OBJECTS=dos.ppu objects.ppu syslinux.ppu
ifeq ($(LINK_TO_C),NO)
OBJECTS:=  $(OBJECTS) syscalls.ppu linux.ppu prt0.o 
endif

# determine on what syslinux should depend.
SYSLINUXDEPS = syslinux.pp system.inc systemh.inc mathh.inc math.inc \
		real2str.inc set.inc heaph.inc heap.inc innr.inc

ifeq ($(LINK_TO_C),YES)
SYSLINUXDEPS:=$(SYSLINUXDEPS) lprt.o
else
SYSLINUXDEPS:=$(SYSLINUXDEPS) syscalls.pp 
endif

# Determine on what dos unit should depend.
DOSDEPS = dos.pp syslinux.ppu strings.ppu
ifeq ($(LINK_TO_C),YES)
DOSDEPS:=$(DOSDEPS) lprt.o
else
DOSDEPS:=$(DOSDEPS) syscalls.ppu
endif

# Which prt to use ?
ifdef AOUT
PRT=prt0.S
else
PRT=prt1.S
endif

# What compiler to use ?
PP=ppc386  -a -Fr../../compiler/errorE.msg -TLINUX
# for aout.
# PP=ppc386 -e/usr/i486-linuxaout/bin -w- -a -TLINUX
# for testing a new version
# PP=../../compiler/ppc386 -Fr../../compiler/errorE.msg -a -TLINUX

ifneq ($(LINK_TO_C),YES)
PP:=$(PP) -dNATIVELINUX
endif

all : $(OBJECTS)

syslinux.ppu : $(SYSLINUXDEPS)
	$(PP)  -Us -Un -Sg syslinux

dos.ppu : $(DOSDEPS)
	$(PP) dos

lprt.o : lprt.c
	gcc $(AOUT) -c lprt.c -o lprt.o

strings.ppu : strings.pp
	$(PP) strings

objects.ppu : objects.pp
	$(PP) objects

syscalls.ppu : syscalls.pp sysnr.inc errno.inc
	$(PP) syscalls

linux.ppu : linux.pp syscalls.ppu
	$(PP) linux

prt0.o : $(PRT)
	as $(PRT) -o prt0.o

install : all
	install -m 775 -d $(LIBINSTALLDIR)/linuxunits
	install -m 644 *.ppu *.o $(LIBINSTALLDIR)/linuxunits

clean :
	-rm -f *.o
	-rm -f *.s
	-rm -f *.ppu
