IDENT=-DMACH -DMACH_KERNEL -DMACH_LOAD
# Copyright (C) 1992 Free Software Foundation, Inc.
# This file is part of the GNU Hurd.
# 
# The GNU Hurd is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# The GNU Hurd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with the GNU Hurd; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# Makefile for the Mach microkernel, used by config to generate the
# actual makefile used in compilation.

# Unlike *other* users of config, we get to use neat bits of
# GNU make which obviate the need for config to output rules for
# every stinking file.  Yippee!  This wouldn't work for device drivers,
# but those need to be fixed for GCC anyway, and then no special 
# Makefile magic is necessary.

default: all
all: mach_kernel

# These are all the dirs which hold source files, relative
# to the top-level mach directory. XXX 386 specific
SOURCE_DIRS = ddb device ipc kern vm \
		chips scsi scsi/adapters \
		ns532 ns532/PC532

# This construction of vpath is wretched.  Roland needs
# to improve make so this isn't necessary.
space:=$(empty) $(empty)
VPATH=$(subst $(space),:,$(strip $(addprefix ../../,$(SOURCE_DIRS)))):mach

MIG = /usr/local/pc532-mach/DIST/bin/mig
CC = gcc32k
LD = ld32k
AR = ar32k
RANLIB = ranlib32k

# CFLAGS exists to be overridden by the person typing `make',
# and should not be modified or defined in this file.
REALCFLAGS= $(CFLAGS) -O -fvolatile

REALCPPFLAGS = $(CPPFLAGS) -nostdinc -I. -I../.. \
		 $(IDENT) -DKERNEL -Dns532 -DPC532

# Flags for the kernel link:
KLDFLAGS=-x -e _pstart -T 18002000

# Rule for compiling C source files:
%.o: %.c
	$(CC) $(REALCFLAGS) $(REALCPPFLAGS) -c -o $@ $<

# Rule for compiling assembler source files.  We have to do this in a
# screwy way because the Mach sources do not use .S for preprocessed
# assembler.
%.o: %.s
	rm -f $*.S
	ln $< $*.S
	$(CC) $(REALCPPFLAGS) -DASSEMBLER $(ASFLAGS) -c -o $@ $*.S

# Rule to generate .o from .b.  This will eventually have to be removed;
# GNU will come with no .b files.
%.o: %.b
	rm -f $@; uudecode $<

# There is total chaos about which MiG files generate which
# source files, what the names of the header files are, and 
# so forth.  Until this can be straightened out, no MiG files
# are listed in any fashion in the config databases, and are
# explicitly included in the link below.

# Until the i386 does real autoconfiguration, we do this.
#ioconf.c:
#	cp /dev/null ioconf.c

genassym: genassym.o
	gcc $(REALCFLAGS) $(REALCPPFLAGS) -o genassym genassym.o
	
genassym.o: genassym.c
	gcc $(REALCFLAGS) $(REALCPPFLAGS) -c -o genassym.o $<

assym.s: genassym
	./genassym > assym.s




cswitch.o interrupt.o locore.o start.o: assym.s	

OBJS=db_access.o db_aout.o db_break.o db_command.o db_cond.o \
	db_examine.o db_expr.o db_ext_symtab.o db_input.o db_lex.o \
	db_macro.o db_output.o db_print.o db_run.o db_sym.o \
	db_task_thread.o db_trap.o db_variables.o db_watch.o \
	db_write_cmd.o ipc_entry.o ipc_hash.o ipc_init.o ipc_kmsg.o \
	ipc_marequest.o ipc_mqueue.o ipc_notify.o ipc_object.o \
	ipc_port.o ipc_pset.o ipc_right.o ipc_space.o ipc_splay.o \
	ipc_table.o ipc_thread.o mach_debug.o mach_msg.o mach_port.o \
	ast.o bootstrap.o counters.o debug.o eventcount.o exception.o \
	host.o ipc_host.o ipc_kobject.o ipc_mig.o ipc_sched.o ipc_tt.o \
	kalloc.o lock.o mach_clock.o mach_factor.o machine.o printf.o \
	priority.o processor.o queue.o sched_prim.o startup.o \
	syscall_emulation.o syscall_subr.o syscall_sw.o task.o thread.o \
	thread_swap.o time_stamp.o timer.o xpr.o zalloc.o \
	memory_object_data_provided.o memory_object_data_unavailable.o \
	memory_object_data_error.o memory_object_set_attributes.o \
	memory_object_data_supply.o memory_object_ready.o \
	memory_object_change_attributes.o mach_host_server.o \
	mach_port_server.o mach_server.o memory_object_default_user.o \
	memory_object_user.o mach_debug_server.o memory_object.o \
	vm_debug.o vm_external.o vm_fault.o vm_init.o vm_kern.o vm_map.o \
	vm_object.o vm_pageout.o vm_resident.o vm_user.o blkio.o \
	chario.o cirbuf.o dev_lookup.o dev_name.o dev_pager.o \
	device_reply_user.o device_server.o device_init.o ds_routines.o \
	net_io.o subrs.o ioconf.o locore.o cswitch.o physical_mode.o \
	bcopy.o bzero.o fpu.o hardclock.o ns532_init.o init.o io_map.o \
	db_disasm.o db_interface.o db_trace.o loose_ends.o ntoh.o pic.o \
	pcb.o phys.o pmap.o spl.o simple_spl.o trap.o setjmp.o pdma.o \
	autoconf.o conf.o setroot.o rtc.o com.o idle.o busses.o \
	scsi_aic6250_hdw.o scsi_dp8490_hdw.o rz.o rz_cpu.o rz_disk.o \
	rz_disk_bbr.o rz_host.o rz_labels.o rz_tape.o scsi.o \
	scsi_alldevs.o scsi_comm.o scsi_cpu.o scsi_disk.o scsi_jukebox.o \
	scsi_optical.o scsi_printer.o scsi_rom.o scsi_scanner.o \
	scsi_tape.o scsi_worm.o 

# We list these explicitly because they aren't known to config.
MIGOBJS = mach_host_server.o mach_port_server.o mach_server.o \
	memory_object_default_user.o memory_object_user.o \
	mach_debug_server.o device_reply_user.o \
	device_server.o

LDOBJS = $(MIGOBJS) $(OBJS)

VERSION_FILES=$(addprefix ../../conf/version.,major minor variant edit patch)
# Increment the version when any dependency of mach_kernel changes.
vers.c: $(LDOBJS)
	/bin/sh ../../conf/newvers.sh ../../conf/copyright \
		`cat $(VERSION_FILES)`

mach_kernel: start.o $(LDOBJS) vers.o libmig.a
	@echo $(LD) -o mach_kernel $(KLDFLAGS) [...]
	@$(LD) -o mach_kernel $(KLDFLAGS) $^
	@size mach_kernel

### 
# What follows is unacceptably ugly, but we're stuck with it for now.
###

# Weird nonsense
dev_pager.o: device_pager_server.c

# More normal nonsense
memory_object.o: memory_object_user.h memory_object_default.h
vm_fault.o: memory_object_user.h
vm_object.o: memory_object_user.h memory_object_default.h
vm_pageout.o: memory_object_user.h memory_object_default.h
ds_routines.o: device_reply.h

# This all makes a nifty library used above...
# These are user-side stubs for some calls in mach.defs that the
# kernel needs.  
MIGUINTS = memory_object_data_provided memory_object_data_unavailable \
	memory_object_data_error memory_object_set_attributes \
	memory_object_data_supply memory_object_ready \
	memory_object_change_attributes

MIGLIBFILES = $(addsuffix .o,$(MIGUINTS))
MIGLIBSRCS = $(patsubst %,mach/%.c,$(MIGUINTS))

$(MIGLIBFILES): $(MIGLIBSRCS)

$(MIGLIBSRCS): ../../mach/mach.defs
	$(MIG) -DKERNEL_USER $(REALCPPFLAGS) \
		-header mach/mach_user_kernel.h \
		-i mach/ \
		-server /dev/null $<

libmig.a: $(MIGLIBFILES)
	rm -f libmig.a
	$(AR) cq libmig.a $(MIGLIBFILES)
	$(RANLIB) libmig.a	

install: mach_kernel
	cp mach_kernel /usr/local/pc532-mach/DIST/libexec

# Guck
mach_host_server.c: ../../mach/mach_host.defs
	$(MIG) -DKERNEL_SERVER $(REALCPPFLAGS) -header /dev/null \
		 -user /dev/null -server $@ $<

mach_port_server.c: ../../mach/mach_port.defs
	$(MIG) -DKERNEL_SERVER $(REALCPPFLAGS) -header /dev/null \
		 -user /dev/null -server $@ $<

mach_server.c: ../../mach/mach.defs
	$(MIG) -DKERNEL_SERVER $(REALCPPFLAGS) -header /dev/null \
		 -user /dev/null -server $@ $<

memory_object_default_user.c memory_object_default.h : \
		 	../../mach/memory_object_default.defs
	$(MIG) -DKERNEL_USER -DSEQNOS $(REALCPPFLAGS) \
		-header memory_object_default.h \
		-user memory_object_default_user.c \
		-server /dev/null $<

memory_object_user.c memory_object_user.h: ../../mach/memory_object.defs
	$(MIG) -DKERNEL_USER -DSEQNOS $(REALCPPFLAGS) \
		-header memory_object_user.h \
		-user memory_object_user.c \
		-server /dev/null $<

mach_debug_server.c: ../../mach_debug/mach_debug.defs
	$(MIG) -DKERNEL_SERVER $(REALCPPFLAGS) -header /dev/null \
		 -user /dev/null -server $@ $<

#mach_i386_server.c: ../../mach/i386/mach_i386.defs
#	$(MIG) -DKERNEL_SERVER $(REALCPPFLAGS) -header /dev/null \
#		 -user /dev/null -server $@ $<

device_server.c: ../../device/device.defs
	$(MIG) -DKERNEL_SERVER $(REALCPPFLAGS) -header /dev/null \
		 -user /dev/null -server $@ $<

device_reply.h device_reply_user.c: ../../device/device_reply.defs
	$(MIG) -DKERNEL_USER $(REALCPPFLAGS) \
		-header device_reply.h \
		-user device_reply_user.c \
		-server /dev/null $<

device_pager_server.c: ../../mach/memory_object.defs
	$(MIG) -DKERNEL_SERVER $(REALCPPFLAGS) -header /dev/null \
		 -user /dev/null -server $@ $<


