# Makefile for i386
# Copyright 1999, 2006 Free Software Foundation, Inc.
#
# Permission to use, copy, modify and distribute this software and its
# documentation is hereby granted, provided that both the copyright
# notice and this permission notice appear in all copies of the
# software, derivative works or modified versions, and any portions
# thereof, and that both notices appear in supporting documentation.
#
# THE FREE SOFTWARE FOUNDATION ALLOWS FREE USE OF THIS SOFTWARE IN ITS
# "AS IS" CONDITION.  THE FREE SOFTWARE FOUNDATION DISCLAIMS ANY
# LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE
# USE OF THIS SOFTWARE.


#
# configure's findings.
#

srcdir = @srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
bootdir = $(exec_prefix)/boot
datadir = @datadir@
includedir = @includedir@
infodir = @infodir@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
oldincludedir = @oldincludedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@

top_srcdir = @srcdir@/..
top_builddir = ../


#
# Default target
#

all:


# Detect if the user wants LPR
ifeq ($(findstring -DMACH_LPR,@DEFS@),-DMACH_LPR)
enable_lpr=yes
else
enable_lpr=no
endif


# i386 Mach makefile fragment
# Copyright 1997, 1999 Free Software Foundation, Inc.
#
# Permission to use, copy, modify and distribute this software and its
# documentation is hereby granted, provided that both the copyright
# notice and this permission notice appear in all copies of the
# software, derivative works or modified versions, and any portions
# thereof, and that both notices appear in supporting documentation.
#
# THE FREE SOFTWARE FOUNDATION ALLOWS FREE USE OF THIS SOFTWARE IN ITS
# "AS IS" CONDITION.  THE FREE SOFTWARE FOUNDATION DISCLAIMS ANY
# LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE
# USE OF THIS SOFTWARE.


# Source files for any i386 kernel
i386at-files = autoconf.c conf.c cons_conf.c rtc.c \
	i386at_ds_routines.c immc.c int_init.c iopl.c kd.c kd_event.c \
	kd_mouse.c kd_queue.c model_dep.c pic_isa.c
i386-files = ast_check.c db_disasm.c db_interface.c db_trace.c debug_i386.c \
	fpe_linkage.c fpu.c gdt.c hardclock.c idt.c io_emulate.c io_map.c \
	iopb.c ktss.c kttd_interface.c ldt.c loose_ends.c mp_desc.c pcb.c \
	phys.c pic.c pit.c seg.c trap.c user_ldt.c
intel-files = pmap.c read_fault.c

# Assembler source
i386at-Sfiles = boothdr.S interrupt.S kdasm.S
i386-Sfiles = cswitch.S debug_trace.S idt_inittab.S locore.S spl.S

# Account for them in the image
objfiles += $(subst .c,.o,$(i386at-files) $(i386-files) $(intel-files)) \
	    $(subst .S,.o,$(i386at-Sfiles) $(i386-Sfiles))
vpath %.c $(srcdir)/i386at $(srcdir)/i386 $(srcdir)/intel
vpath %.S $(srcdir)/i386at $(srcdir)/i386

# Files from the generic source that we want
objfiles += busses.o cirbuf.o
# Hm.
vpath busses.c $(top_srcdir)/chips
vpath cirbuf.c $(top_srcdir)/device

# Mig-generated
objfiles += mach_i386_server.o

servers = $(filter %_server.o,$(objfiles))

# This file is only needed for KDB support.  It'll be discarded at linking time
# if it's not needed.
objfiles += _setjmp.o

# XXX: In i386, com is always enabled.
objfiles += com.o

# This file is only needed for LPR support.
ifeq ($(enable_lpr),yes)
objfiles += lpr.o
endif



# Where to find some things
vpath i386asm.sym $(srcdir)/i386
vpath mach_i386.srv $(srcdir)/i386

# Our include files; they precede the generic ones.
INCLUDES = -I. -I$(srcdir)/i386at -I$(srcdir)/i386 -I$(srcdir)/include	\
  -I$(srcdir)/include/mach/sa -I$(srcdir)

# Static dependencies.

# For building with `no_deps=t'.
boothdr.o: i386asm.h

#
# Rules.
#

all: sysdep.a
	$(MAKE) -C linux $@

# `$($(systype)-objfiles-prepend)' are special, but are nevertheless
# created for the target `sysdep.a'.
sysdep.a: $(objfiles) linux/linux.o
	rm -f $@
	$(AR) cr $@ $(filter-out $($(systype)-objfiles-prepend),$^)
	$(RANLIB) $@

check:
	$(MAKE) -C linux $@

clean:
	$(MAKE) -C linux $@
	rm -f sysdep.a
	rm -f $(objfiles) $(subst .o,.d,$(objfiles))
	rm -f *.symc *.symc.o *_user.c *_server.c *.h *.cli.d *.srv.d

distclean: clean
	$(MAKE) -C linux $@
	rm -f Makefile Makerules
	rm -f config.status config.log

mostlyclean: distclean
	$(MAKE) -C linux $@

maintainer-clean: mostlyclean
	$(MAKE) -C linux $@
	rm -f $(srcdir)/configure

linux/%: FORCE
	$(MAKE) -C linux $(@F)
FORCE:


#
# Installation
#

install:
	$(MAKE) -C linux $@

installed-headers = $(addprefix mach/i386/, \
	asm.h boolean.h disk.h eflags.h exception.h fp_reg.h ioccom.h \
	kern_return.h mach_i386.defs mach_i386_types.h machine_types.defs \
	multiboot.h rpc.h syscall_sw.h thread_status.h trap.h vm_param.h \
	vm_types.h)

installed-headers-names = $(addprefix $(includedir)/,$(installed-headers))
$(installed-headers-names): $(includedir)/%: $(srcdir)/include/%
	$(INSTALL_DATA) $< $@

install-headers: mkheaderdirs $(installed-headers-names)
	ln -sfn $(systype) $(includedir)/mach/machine
	$(MAKE) -C linux $@

install-kernel:
	$(MAKE) -C linux $@

mkheaderdirs:
	mkdir -p $(includedir)/mach/$(systype)


#
# Autoconf support
#

$(srcdir)/configure: configure.in
	cd $(srcdir) && autoconf

Makefile: Makefile.in config.status
	./config.status $@

config.status: configure
	./config.status --recheck

vpath %.in $(srcdir)
vpath configure $(srcdir)


#
# Makerules
#

include $(top_builddir)/Makerules