# Copyright (C) 2012-2014  The Bochs Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

# Makefile for the iodev/usb component of bochs


.SUFFIXES: .cc

prefix          = /usr/local
exec_prefix     = $(prefix)
srcdir          = .

bindir          = $(exec_prefix)/bin
libdir          = $(exec_prefix)/lib
datarootdir     = $(prefix)/share
mandir          = $(datarootdir)/man
man1dir         = $(mandir)/man1
man5dir         = $(mandir)/man5
docdir          = $(datarootdir)/doc/bochs
sharedir        = $(datarootdir)/bochs
top_builddir    = ..
top_srcdir      = ../..

SHELL = /bin/sh



CXX = cl
CXXFLAGS = $(BX_INCDIRS) /nologo /MT /W3 /DNDEBUG /DWIN32 /D_WINDOWS /D_CRT_SECURE_NO_WARNINGS /O2 /Gr /EHs-c- 

LDFLAGS = 
LIBS = 
RANLIB = echo
PLUGIN_PATH=$(exec_prefix)/lib
top_builddir    = ../..
LIBTOOL=
WIN32_DLL_IMPORT_LIBRARY=../../

USBDEV_OBJS = usb_hid.o usb_hub.o usb_msd.o usb_printer.o
SCSI_OBJS = scsi_device.o

BX_INCDIRS = -I.. -I../.. -I$(srcdir)/.. -I$(srcdir)/../.. -I../../instrument/stubs -I$(srcdir)/../../instrument/stubs
LOCAL_CXXFLAGS = $(MCH_CFLAGS)

OBJS_THAT_CAN_BE_PLUGINS = \
  usb_uhci.o usb_ohci.o usb_xhci.o \
  usb_common.o

OBJS_THAT_SUPPORT_OTHER_PLUGINS = \
  $(USBDEV_OBJS) \
  $(SCSI_OBJS)

NONPLUGIN_OBJS = $(OBJS_THAT_CANNOT_BE_PLUGINS) $(OBJS_THAT_CAN_BE_PLUGINS) $(OBJS_THAT_SUPPORT_OTHER_PLUGINS)
PLUGIN_OBJS = 
USBHC_DLL_TARGETS = bx_usb_uhci.dll bx_usb_ohci.dll bx_usb_xhci.dll

all: libusb.a

plugins: 

plugins_gcc: $(PLUGIN_OBJS:%.o=libbx_%.la)

plugins_msvc: bx_usb_common.dll $(USBHC_DLL_TARGETS)

libusb.a: $(NONPLUGIN_OBJS)
	-del libusb.a
	lib /nologo /subsystem:console,"5.01" /verbose /out:$@ $(NONPLUGIN_OBJS)
	$(RANLIB) libusb.a

# standard compile rule for C++ files
.cc.o:
	$(CXX) /c  $(CXXFLAGS) $(LOCAL_CXXFLAGS) /Tp$< /Fo$@

##### building plugins with libtool
%.lo: %.cc
	$(LIBTOOL) --mode=compile --tag CXX $(CXX) -c $(CXXFLAGS) $(LOCAL_CXXFLAGS) $< -o $@

libbx_%.la: %.lo
	$(LIBTOOL) --mode=link --tag CXX $(CXX) -module $< -o $@ -rpath $(PLUGIN_PATH)

# special link rules for plugins that require more than one object file
libbx_usb_common.la: usb_common.lo $(USBDEV_OBJS:.o=.lo) scsi_device.lo
	$(LIBTOOL) --mode=link --tag CXX $(CXX) -module usb_common.lo $(USBDEV_OBJS:.o=.lo) scsi_device.lo -o libbx_usb_common.la -rpath $(PLUGIN_PATH)

#### building DLLs for win32 (Cygwin and MinGW/MSYS)
bx_%.dll: %.o
	$(CXX) $(CXXFLAGS) -shared -o $@ $< $(WIN32_DLL_IMPORT_LIBRARY)

# special link rules for plugins with Cygwin, MinGW/MSYS and MSVC nmake
bx_usb_common.dll: usb_common.o $(USBDEV_OBJS) scsi_device.o
	 usb_common.o $(USBDEV_OBJS) scsi_device.o $(WIN32_DLL_IMPORT_LIBRARY)

bx_usb_uhci.dll: usb_uhci.o
	 usb_uhci.o $(WIN32_DLL_IMPORT_LIBRARY)

bx_usb_ohci.dll: usb_ohci.o
	 usb_ohci.o $(WIN32_DLL_IMPORT_LIBRARY)

bx_usb_xhci.dll: usb_xhci.o
	 usb_xhci.o $(WIN32_DLL_IMPORT_LIBRARY)

##### end DLL section

clean:
	-del -rf .libs *.lo *.o *.la *.a *.dll *.exp *.lib

dist-clean: clean
	-del Makefile

###########################################
# dependencies generated by
#  gcc -MM -I.. -I../.. -I../../instrument/stubs *.cc | sed -e 's/\.cc/.cc/g'
#  gcc -MM -I.. -I../.. -I../../instrument/stubs *.cc | \
#     sed -e 's/\.cc/.cc/g' -e 's/\.o:/.lo:/g'
#
# This means that every source file is listed twice, once with a .o rule
# and then again with an identical .lo rule.  The .lo rules are used when
# building plugins.
###########################################
scsi_device.o: scsi_device.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h ../hdimage/hdimage.h ../hdimage/cdrom.h \
 scsi_device.h
usb_common.o: usb_common.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h usb_hid.h usb_hub.h usb_msd.h \
 usb_printer.h
usb_hid.o: usb_hid.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h usb_hid.h
usb_hub.o: usb_hub.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h usb_hub.h
usb_msd.o: usb_msd.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h ../hdimage/cdrom.h ../hdimage/hdimage.h \
 scsi_device.h usb_msd.h
usb_ohci.o: usb_ohci.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h ../pci.h usb_common.h usb_ohci.h
usb_printer.o: usb_printer.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h usb_printer.h
usb_uhci.o: usb_uhci.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h ../pci.h usb_common.h usb_uhci.h
usb_xhci.o: usb_xhci.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h ../pci.h usb_common.h usb_xhci.h
scsi_device.lo: scsi_device.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h ../hdimage/hdimage.h ../hdimage/cdrom.h \
 scsi_device.h
usb_common.lo: usb_common.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h usb_hid.h usb_hub.h usb_msd.h \
 usb_printer.h
usb_hid.lo: usb_hid.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h usb_hid.h
usb_hub.lo: usb_hub.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h usb_hub.h
usb_msd.lo: usb_msd.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h ../hdimage/cdrom.h ../hdimage/hdimage.h \
 scsi_device.h usb_msd.h
usb_ohci.lo: usb_ohci.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h ../pci.h usb_common.h usb_ohci.h
usb_printer.lo: usb_printer.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h usb_common.h usb_printer.h
usb_uhci.lo: usb_uhci.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h ../pci.h usb_common.h usb_uhci.h
usb_xhci.lo: usb_xhci.cc ../iodev.h ../../bochs.h ../../config.h \
 ../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
 ../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
 ../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
 ../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
 ../../param_names.h ../pci.h usb_common.h usb_xhci.h
