#$Header: /sys/rt/stand/RCS/samakefile,v 1.5 1994/05/22 13:06:13 roger Exp $
#$ACIS:samakefile 12.0$
#$Source: /sys/rt/stand/RCS/samakefile,v $
#
# generic makefile for generating standalone code
#
# following flags are expected to overriden by the user
#

# kernel source tree is located via $S relative to the compilation directory
S=	../..

FLAGS=
HOST=ws
# override CRT0 to get relsrt0
CRT0=srt0
RELOC = 100000		# relocation address
# START=_start
START=start
# use LDFLAGS for loader flags
XFLAG=-x
LDFLAGS = -N $(XFLAG) -e $(START)
#
#
.SUFFIXES: .ws .out .o .b .s .c .i
# home of most everything
PREFIX=
STANDIR=/usr/src/sys/rtstand
HDIR=$(.CURDIR)/${S}
# use flags for extra compile time flags (-g etc.)
INCLUDES = -I$(.CURDIR) -I${STANDIR} -I${HDIR} -I${HDIR}/sys
CFLAGS = ${INCLUDES} -I${HDIR}/sys $(FLAGS) -DTRACE -DNOINT
# AFLAGS is for CPP on .s files
CPP=/usr/bin/cpp
AFLAGS= ${INCLUDES}
LIBSA=libsa.a
LIBC=-lc
LIBS=$(LIB) $(LIBSA) $(LIBC)
LD=ld

.c.o:
	$(CC) -c $(CFLAGS) $(.CURDIR)/$*.c

.c.i:
	$(CC) -E $(CFLAGS) $(.CURDIR)/$*.c >$*.i

.s.o:
	$(CPP) $(AFLAGS) $(FLAGS) $(.CURDIR)/$*.s >$*.S
	$(AS) -o $*.o $*.S
	rm -f $*.S

.c.s:
	$(CC) -S -xl $(CFLAGS) $(.CURDIR)/$*.c

.o.out:
	$(LD) $(LDFLAGS) -T $(RELOC) $(STANDIR)/$(CRT0).o $*.o -o $*.out $(LIBS)

.c.out:
	$(CC) -c $(CFLAGS) $*.c
	$(LD) $(LDFLAGS) -T $(RELOC) $(STANDIR)/$(CRT0).o $*.o -o $*.out $(LIBS)

.out.ws:
		cp $*.out $*.ws

all:
	@echo "to make a program whose source is in prog.c do"
	@echo "	samake prog.out"
	@echo "and if that suceeds then do"
	@echo "	samake prog.ws"

clean:
	rm -f *.lis *.b
