#############################################################
# Copyright (C) 1998-2000 VMware, Inc.
# All Rights Reserved
# $Id: Makefile.dist,v 1.2 2000/01/15 01:02:40 chuckr Exp $
#############################################################
####
####  VMWare vmmon Makefile to be distributed externally
####

####
####  If you have an SMP kernel, you _must_ uncomment the line below.  If
#### you don't, and you're lucky, the driver won't compile.  Otherwise
#### it'll compile but just be potentially rather broken.
####
#SUPPORT_SMP=1

# Header directory for the running kernel
HEADER_DIR = /usr/src/linux/include

####
#### TOPDIR _must_ be a relative path.
####
TOPDIR = .

####
####  DESTDIR is where the module, object files, and dependencies are built
####
DESTDIR = driver-`uname -r`

####
####  DRIVERNAME should be untouched unless you have a good reason to change 
#### it.  The form below is how the scripts expect it.
####
ifdef SUPPORT_SMP
DRIVERNAME = vmmon-smp-`uname -r`
else
DRIVERNAME = vmmon-up-`uname -r`
endif

CC = gcc

ifdef QUIET
ECHO = @true
else
ECHO = @echo
endif

####
#### You must compile with at least -O level of optimization
#### or the module won't load.
#### If desparate, I think that bringing in <linux/bitops.h> might
#### suffice.
####
CC_WARNINGS = -Wall -Wstrict-prototypes 
CC_KFLAGS = -D__KERNEL__ -fno-strength-reduce -pipe -m486 -malign-loops=2 \
            -malign-jumps=2 -malign-functions=2 -fno-omit-frame-pointer \
	    -DCPU=586
CC_OPTS = -O2 -DMODULE $(GLOBAL_DEFS) $(CC_KFLAGS) $(CC_WARNINGS) 

ifdef SUPPORT_SMP
CC_OPTS += -DSUPPORT_SMP
endif

ifeq ($(shell grep 'FIX_IO_APIC_BASE_0' $(HEADER_DIR)/asm/fixmap.h 2>/dev/null),)
CC_OPTS += -DVMWARE__FIX_IO_APIC_BASE=FIX_IO_APIC_BASE
else
CC_OPTS += -DVMWARE__FIX_IO_APIC_BASE=FIX_IO_APIC_BASE_0
endif

INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/common -I$(TOPDIR)/linux -I$(TOPDIR)/export/include -I$(HEADER_DIR)

C_TARGETS_LINUX  = driver.o hostif.o
C_TARGETS_COMMON = vmx86.o task.o memtrack.o phystrack.o 
C_TARGETS_LINUX_D = ${C_TARGETS_LINUX:.o=.d}
C_TARGETS_COMMON_D = ${C_TARGETS_COMMON:.o=.d}
C_TARGETS =  $(C_TARGETS_LINUX) $(C_TARGETS_COMMON)

####
#### Make Targets are beneath here.
####

driver: setup deps
	$(MAKE) -C $(DESTDIR) -f ../Makefile TOPDIR=../$(TOPDIR) vmmon INCLUDE_DEPS=1

setup:
	@if [ -d $(DESTDIR) ] ; then true ; else mkdir $(DESTDIR); chmod 755 $(DESTDIR) ; fi

vmmon: $(C_TARGETS)
	$(ECHO) "Building $(DRIVERNAME)"   
	ld -r -o $(DRIVERNAME) $(C_TARGETS)

auto-build: 
	$(MAKE) driver QUIET=1
	cp -f $(DESTDIR)/$(DRIVERNAME) $(TOPDIR)/../vmmon.o

$(C_TARGETS_LINUX): %.o: $(TOPDIR)/linux/%.c
	$(ECHO) "Compiling  linux/$(<F)"
	$(CC) $(CC_OPTS) $(INCLUDE) -c $<

$(C_TARGETS_COMMON): %.o: $(TOPDIR)/common/%.c
	$(ECHO) "Compiling  common/$(<F)"
	$(CC) $(CC_OPTS) $(INCLUDE) -c $<

clean:
	rm -rf $(DESTDIR)/

$(C_TARGETS_COMMON_D): %.d: $(TOPDIR)/common/%.c
	$(ECHO) "Dependencies for $(<F)"
	$(CC) -MM $(CC_OPTS) $(INCLUDE) $< > $@

$(C_TARGETS_LINUX_D): %.d: $(TOPDIR)/linux/%.c
	$(ECHO) "Dependencies for $(<F)"
	$(CC) -MM $(CC_OPTS) $(INCLUDE) $< > $@

deps: setup 
	$(MAKE) -C $(DESTDIR) -f ../Makefile TOPDIR=../$(TOPDIR) driver_deps 

driver_deps: ${C_TARGETS:.o=.d}

ifdef INCLUDE_DEPS
include ${C_TARGETS:.o=.d}
endif

.SILENT:
