# File        : Makefile
# Author      : Stuart Menefy
# Description : Makefile for boot monitor and build program
# Header      : $Id: Makefile,v 1.8 1994/05/10 16:16:20 stuart Exp $
#
# The will build either the link or disk bootable system, depending on
# the target specified on the command line.
#
# History:
#   19/02/92  SIM  Created
#   04/07/93  SIM  Overhaul for boot monitor version.
#   07/01/94  SIM  Altered to use new features of CC
#   11/04/94  SIM  Shortened filenames for MS-DOS.
#   09/05/94  SIM  Update hosted version to use environment vars properly

# Processor class
PROC = -MT414 -Wall	# Option for cc

# Define where the minix /usr directory is. Normally this is /usr, unless
# cross compiling. Used for:
#   include files   eg $(MINIX_USR)/include/a.out.h
#   libraries       eg $(MINIX_USR)/lib/libc.a
#   kernel source   eg $(MINIX_USR)/src/fs
# MINIX_USR=/usr

# Where to find include files. eg $(INCDIR)/include/...
INC_DIR=$(MINIX_USR)

# Pathname for the standard C library.
LIBC=$(MINIX_USR)/lib/libc.a

# Where to find kernel sources. eg $(SRCDIR)/fs/...
SRC_DIR=$(MINIX_USR)/src

# C compiler for build when compiling boot from link version.
# May be different from CC when cross-compiling.
# BUILD_CC=$(CC) -Wall -DLITTLE_ENDIAN
BUILD_CC=gcc -Wall -DBIG_ENDIAN


all:
		@echo "Need to specify make target:"
		@echo "  disk - boot from disk version (FORMAT=-f if required)"
		@echo "  link - boot from link version"

disk:		buildd bootd secondd monitord
		./buildd $(FORMAT) -vo /dev/rfd0 \
			-ibps bootd -is secondd -i monitord

link:		buildl bootl secondl monitorl
		./buildl -vo boot.btl -ibps bootl -is secondl

###

buildd:	build.c
		$(CC) build.c -o buildd -DMINIX -Wall $(PROC)

buildl:	build.c
		$(BUILD_CC) build.c -o buildl -DHOST -I$(INC_DIR)

###

bootd:	bootstrap.S
		$(CC) -DDISK -nostdlib -o bootd -e bootstrap bootstrap.S

bootl:	bootstrap.S
		$(CC) -DLINK -nostdlib -o bootl -e bootstrap bootstrap.S

###

secondd:	second.o csecond.o secondd.o diskio.o termio.o
		$(CC) $(PROC) -nostdlib -o secondd \
		    second.o csecond.o secondd.o diskio.o termio.o $(LIBC)


secondl:	second.o csecond.o secondl.o linkio.o
		$(CC) $(PROC) -nostdlib -o secondl \
		    second.o csecond.o secondl.o linkio.o $(LIBC)

second.o:	second.S
		$(CC) $(PROC) -c second.S

csecond.o:	csecond.c io.h
		$(CC) $(PROC) -c csecond.c

secondl.o:	secondl.c io.h
		$(CC) $(PROC) -c secondl.c

secondd.o:	secondd.c io.h
		$(CC) $(PROC) -c secondd.c

###

monitord:	monitor.o cmonitor.o monitord.o rawfs.o fileio.o termio.o
		$(CC) monitor.o cmonitor.o monitord.o rawfs.o fileio.o termio.o \
			-e monitor -nostdlib $(PROC) $(LIBC) -o monitord

monitorl:	monitor.o cmonitor.o monitorl.o linkio.o
		$(CC) monitor.o cmonitor.o monitorl.o linkio.o \
			-e monitor -nostdlib $(PROC) $(LIBC) -o monitorl

###

monitor.o:	monitor.S
		$(CC) $(PROC) -c monitor.S

cmonitor.o:	cmonitor.c io.h monitor.h
		$(CC) $(PROC) -c cmonitor.c

monitord.o:	monitord.c rawfs.h io.h monitor.h
		$(CC) $(PROC) -c monitord.c

monitorl.o:	monitorl.c io.h monitor.h
		$(CC) $(PROC) -c monitorl.c

rawfs.o:	rawfs.c rawfs.h
		$(CC) $(PROC) -c rawfs.c -I$(SRC_DIR)

diskio.o:	diskio.c io.h
		$(CC) $(PROC) -c diskio.c

linkio.o:	linkio.c io.h
		$(CC) $(PROC) -c linkio.c

fileio.o:	fileio.c rawfs.h io.h
		$(CC) $(PROC) -c fileio.c

termio.o:	termio.c tpduart.h io.h
		$(CC) $(PROC) -c termio.c

#########

clean:
		rm -f *.o
		rm -f buildd   buildl
		rm -f bootd    bootl
		rm -f secondd  secondl
		rm -f monitord monitorl
		rm -f boot.btl
