#
# 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1987,1988
# LICENSED MATERIALS - PROPERTY OF IBM
# REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
#
# $Header:makefile 12.2$ 
# $ACIS:makefile 12.2$ 
# $Source: /ibm/acis/usr/sys/pc_code/RCS/makefile,v $ 
#
DEBUG=-DDEBUG
O=obj
LIB=lib
#cv=/codeview
cv=
#
# override the following with C=IBM_C_1 or C=MS_CL_5
# we use unifdef on the makefile before sending it to DOS
# to get rid of the "wrong" compilation definitions.
C=IBM_C_2
#ifdef MS_CL_5
# for Microsoft Version 5.0 use the following:
CC=cl -c
# 	link with /codeview for debugging
LINK=link $(CV) /map /stack:4096
CFLAGS= -Gs -AS -Zi -G2 -Ze -Zp $(DEBUG) -DPC_CODE -DMS_CL_5
# -Gs	no stack checking (we switch stacks on interrupts)
# -AS	small model (with selected far declarations)
# -Zi	generate codeview symbolic information
# -G2	use 286 instructions
# -Ze	enable extentions (far etc)
# -Zp	pack structures (needed?)
CLIB=
#endif

#ifdef IBM_C_2
# for IBM C/2 
CC=cl -c
# 	link with /codeview for debugging
LINK=link $(CV) /map /stack:4096
CFLAGS= -Gs -AS -Zi -G2 -Ze -Zp $(DEBUG) -DPC_CODE -DIBM_C_2
# -Gs	no stack checking (we switch stacks on interrupts)
# -AS	small model (with selected far declarations)
# -Zi	generate codeview symbolic information
# -G2	use 286 instructions
# -Ze	enable extentions (far etc)
# -Zp	pack structures (needed?)
CLIB=+slibcer
#endif

#ifdef IBM_C_1
# following CC and LINK are for IBM C compiler version 1.0
CC=cc
LINK=CLINK /stack:4096
CLIB=
CFLAGS= -G2 -Ze -Zp -Ox $(DEBUG) -DPC_CODE
# -Gs	no stack checking (we switch stacks on interrupts)
# -AS	small model (with selected far declarations)
# -G2	use 286 instructions
# -Ze	enable extentions (far etc)
# -Zp	pack structures (needed?)
#endif

RBLIB=unix
SOURCE=
BASE=
# to make unix.exe in another directory copy this makefile there and
# specify 
#S=../pc_code
#
S=
# following are for the all dependancy
CSOURCE= $(S)badblock.c $(S)biosreq.c $(S)clock.c $(S)dio.c $(S)ih.c \
$(S)loadboot.c $(S)mouse.c $(S)pcifmove.c $(S)pckbd.c $(S)printf.c \
$(S)rbinit.c $(S)rbutils.c $(S)rdump.c $(S)rompint.c $(S)speaker.c $(S)pos.c \
$(S)strategy.c $(S)ub.c $(S)unix.c $(S)wconfig.c $(S)opdio.c $(S)abios_in.c \
$(S)abios_hd.c $(S)abios_fd.c $(S)asy.c $(S)vga.c $(S)tapeio.c $(S)mc.c
CHEADER= $(S)aout.h $(S)bios.h $(S)cbcbbios.h $(S)dio.h $(S)fun_dcl.h \
$(S)loadall.h $(S)pckbd.h $(S)pcparam.h $(S)rb.h $(S)tape.h $(S)mc.h \
$(S)cbcb.h $(S)trace.h $(S)abios_st.h $(S)asy.h $(S)vga.h $(S)vars.h
ASOURCE=$(S)as.asm
AHEADER=$(S)asmrouts.equ
OBJECTS= badblock.$(O) biosreq.$(O) clock.$(O) dio.$(O) ih.$(O) \
loadboot.$(O) mouse.$(O) pcifmove.$(O) pckbd.$(O) printf.$(O) \
rbinit.$(O) rbutils.$(O) rdump.$(O) rompint.$(O) speaker.$(O) \
strategy.$(O) ub.$(O) unix.$(O) wconfig.$(O) opdio.$(O) abios_in.$(O) \
abios_hd.$(O) abios_fd.$(O) asy.$(O) vga.$(O) tapeio.$(O) mc.$(O) pos.$(O) \
as.$(O) version.$(O)

# following is to allow unix to automatically build under
# dos. We arrange to have 'all' set so that DOS never
# attempts to do the following; if files are edited under
# DOS the file "all" may need to be touched.
all: $(CSOURCE) $(CHEADER) $(ASOURCE) $(AHEADER) Makefile sh.bat
	sh ./make.dos unix.exe $?
	echo > all

#ifdef unix
# following goes away for DOS makefile
Makefile: makefile
	test "$C" = IBM_C_1 -o "$C" = IBM_C_2 -o "$C" = MS_CL_5
	rm -f Makefile
	echo "# Note: this file has been processed by unifdef under unix" > Makefile
	echo "#	to configure this DOS makefile for $(C)."  >>Makefile
	-unifdef -Uunix -D$(C) -UIBM_C_1 -UIBM_C_2 -UMS_CL_5 <makefile | \
	sed -e "s;.(DEBUG);$(DEBUG);" -e 's;^C=.*;C=$(C);' >>Makefile

# this doesn't really cross-compile, it just tests to see there are syntax
# errors etc.

DOSINCL=/sys/pc.h
clean:
	rm -f *.o Makefile unix.exe unix.map unix.lib

XCC=hc
xcompile:
	make CC='$(XCC) -c' LINK=':' LIB=':' O=o 'CFLAGS=$(INCL) -I$(DOSINCL) -DDEBUG -DPC_CODE -Dfar= -Dnear= -Dhuge= -Dpascal= -Dint=short ' unix.exe

#endif 
	
all.h: $(S)pcparam.h $(S)fun_dcl.h $(S)vars.h
	echo > all.h

$(RBLIB): $(OBJECTS)

abios_fd.$(O): $(S)abios_st.h all.h $(S)abios_fd.c
	$(CC) $(CFLAGS) $(S)abios_fd.c ;
	$(LIB) $(RBLIB) -+ abios_fd ;

abios_hd.$(O): $(S)abios_st.h all.h $(S)abios_hd.c
	$(CC) $(CFLAGS) $(S)abios_hd.c ;
	$(LIB) $(RBLIB) -+ abios_hd ;

abios_in.$(O): $(S)abios_st.h $(S)abios_in.c
	$(CC) $(CFLAGS) $(S)abios_in.c ;
	$(LIB) $(RBLIB) -+ abios_in ;

speaker.$(O): $(S)speaker.c all.h $(S)rb.h $(S)cbcb.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)speaker.c ;
	$(LIB) $(RBLIB) -+ speaker ;

mouse.$(O): $(S)mouse.c all.h $(S)rb.h $(S)cbcb.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)mouse.c ;
	$(LIB) $(RBLIB) -+ mouse ;

clock.$(O): $(S)clock.c all.h $(S)rb.h $(S)cbcb.h
	$(CC) $(CFLAGS) $(S)clock.c ;
	$(LIB) $(RBLIB) -+ clock ;

vga.$(O): $(S)vga.c all.h $(S)rb.h $(S)cbcb.h $(S)vga.h
	$(CC) $(CFLAGS) $(S)vga.c ;
	$(LIB) $(RBLIB) -+ vga ;

pos.$(O): $(S)pos.c $(S)rb.h
	$(CC) $(CFLAGS) $(S)pos.c ;
	$(LIB) $(RBLIB) -+ pos ;

biosreq.$(O): $(S)biosreq.c all.h $(S)rb.h $(S)cbcb.h
	$(CC) $(CFLAGS) $(S)biosreq.c ;
	$(LIB) $(RBLIB) -+ biosreq ;


badblock.$(O): $(S)badblock.c all.h $(S)rb.h $(S)cbcb.h $(S)dio.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)badblock.c ;
	$(LIB) $(RBLIB) -+ badblock ;


pcifmove.$(O): $(S)pcifmove.c all.h $(S)rb.h $(S)cbcb.h $(S)bios.h $(S)loadall.h
	$(CC) $(CFLAGS) $(S)pcifmove.c ;
	$(LIB) $(RBLIB) -+ pcifmove ;

wconfig.$(O): $(S)wconfig.c all.h $(S)dio.h $(S)rb.h $(S)cbcb.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)wconfig.c ;
	$(LIB) $(RBLIB) -+ wconfig ;

rbinit.$(O): $(S)rbinit.c all.h $(S)dio.h $(S)rb.h $(S)cbcb.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)rbinit.c ;
	$(LIB) $(RBLIB) -+ rbinit ;

rbutils.$(O): $(S)rbutils.c all.h $(S)dio.h $(S)rb.h $(S)cbcb.h $(S)bios.h \
	$(S)pckbd.h
	$(CC) $(CFLAGS) $(S)rbutils.c ;
	$(LIB) $(RBLIB) -+ rbutils ;

pckbd.$(O): $(S)pckbd.c all.h $(S)rb.h $(S)cbcb.h $(S)bios.h $(S)pckbd.h
	$(CC) $(CFLAGS) $(S)pckbd.c ;
	$(LIB) $(RBLIB) -+ pckbd ;

rompint.$(O): $(S)rompint.c all.h $(S)rb.h $(S)cbcb.h
	$(CC) $(CFLAGS) $(S)rompint.c ;
	$(LIB) $(RBLIB) -+ rompint ;

strategy.$(O): $(S)strategy.c all.h $(S)rb.h $(S)cbcb.h $(S)dio.h $(S)bios.h 
	$(CC) $(CFLAGS) $(S)strategy.c ;
	$(LIB) $(RBLIB) -+ strategy ;

loadboot.$(O): $(S)loadboot.c all.h $(S)rb.h $(S)cbcb.h $(S)aout.h $(S)dio.h
	$(CC) $(CFLAGS) $(S)loadboot.c ;
	$(LIB) $(RBLIB) -+ loadboot ;

ih.$(O): $(S)ih.c $(S)rb.h $(S)cbcb.h all.h
	$(CC) $(CFLAGS) $(S)ih.c ;
	$(LIB) $(RBLIB) -+ ih ;

dio.$(O): $(S)dio.c $(S)rb.h $(S)cbcb.h all.h $(S)dio.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)dio.c ;
	$(LIB) $(RBLIB) -+ dio ;

tapeio.$(O): $(S)tapeio.c $(S)rb.h $(S)cbcb.h all.h $(S)dio.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)tapeio.c ;
	$(LIB) $(RBLIB) -+ tapeio ;

opdio.$(O): $(S)opdio.c $(S)rb.h $(S)cbcb.h all.h $(S)dio.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)opdio.c ;
	$(LIB) $(RBLIB) -+ opdio ;

asy.$(O): $(S)asy.c $(S)rb.h $(S)cbcb.h all.h $(S)asy.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)asy.c ;
	$(LIB) $(RBLIB) -+ asy ;

printf.$(O): $(S)printf.c $(S)rb.h $(S)cbcb.h all.h
	$(CC) $(CFLAGS) $(S)printf.c ;
	$(LIB) $(RBLIB) -+ printf ;

rdump.$(O): $(S)rdump.c $(S)rb.h $(S)cbcb.h all.h
	$(CC) $(CFLAGS) $(S)rdump.c ;
	$(LIB) $(RBLIB) -+ rdump ;

as.$(O): $(S)as.asm $(S)asmrouts.equ
	masm $(base)as.asm ;
	$(LIB) $(RBLIB) -+ as ;

ub.$(O): $(S)ub.c $(S)rb.h $(S)cbcb.h  all.h $(S)dio.h $(S)bios.h
	$(CC) $(CFLAGS) $(S)ub.c ;
	$(LIB) $(RBLIB) -+ ub ;

mc.$(O): $(S)mc.c $(S)rb.h $(S)cbcb.h  all.h $(S)dio.h $(S)bios.h $(S)mc.h
	$(CC) $(CFLAGS) $(S)mc.c ;
	$(LIB) $(RBLIB) -+ mc ;

version.$(O): $(S)version.c 
	$(CC) $(CFLAGS) $(S)version.c ;
	$(LIB) $(RBLIB) -+ version ;

unix.$(O): $(S)unix.c $(S)rb.h $(S)cbcb.h all.h $(S)bios.h \
	$(S)loadall.h
	$(CC) $(CFLAGS) $(S)unix.c ;


unix.exe: $(OBJECTS)
	$(LINK) unix,unix,unix,$(RBLIB).lib$(CLIB) ;

