
# JAM style makefile for libubs 1.0

# This doesn't make the Win64 bit .sys and .dll
# (you need the Server 2003 DDK 64 & 32 bit build enironmantes,
#  and then run  ddk_build.cmd. This will then run
#  build in libusb/os. )

#PREF_CCFLAGS 	= $(CCOPTFLAG) ;		# Turn optimisation on
PREF_CCFLAGS    = $(CCDEBUGFLAG) ;		# Debugging flags
#PREF_CCFLAGS	= $(CCHEAPDEBUG) ;		# Heap Debugging flags
PREF_LINKFLAGS	= $(LINKDEBUGFLAG) ;	# Link debugging flags

BUILD_EXAMPLES = false ;
ENABLE_DEBUG_LOGGING = false ;	# Normaly false
ENABLE_LOGGING = true ;			# Normaly true

#Products
#Libraries = ;
#Executables = ;
#Headers = ;

#Install
#InstallBin  $(DESTDIR)$(PREFIX)/bin : $(Executables) ;
#InstallFile $(DESTDIR)$(PREFIX)/h : $(Headers) ;
#InstallLib  $(DESTDIR)$(PREFIX)/lib : $(Libraries) ;

if [ GLOB $(PATH) : sed sed.exe ] {
	Echo "sed seems to be available" ;
	CREATE_INFS = true ;
} else {
	CREATE_INFS = false ;
}

# List of .inf files needed
# WinUSB driver preference
INFS1 = ColorMunki DTP20 DTP92 DTP94 Huey MonacoOptix
       Spyd3 Spyd4 i1Monitor i1Disp i1D3 ColorHug ;
DRIVERS1  = winusbDrivers ;

# Libusb driver preference
INFS2 = i1Pro Spyd2 HCFR3.1 HCFR4.0 ;
DRIVERS2 = libusbDrivers ;

# Optionally generate all the .inf's from the template_inf
if $(CREATE_INFS) = true {
	local _i _ns _nt _nds _ni ;
	NDepends files : $(INFS1).inf $(INFS2).inf ;

	# Driver 1 arrangement
	for  _i in $(INFS1) {
		_ni  = [ NormPaths $(_i).inf ] ;
		_ns  = [ NormPaths $(_i).sed ] ;
		_nt  = [ NormPaths template_inf ] ;
		_nds = [ NormPaths $(DRIVERS1).sed ] ;
		GenFileNND $(_i).inf : "sed -f $(_ns) < $(_nt) | sed -f $(_nds) > $(_ni)"
		                     : $(_i).sed template_inf $(DRIVERS1).sed ;
		File $(_i).cat     : template_cat ;
		File $(_i)_x64.cat : template_cat ;
		NDepends install : $(_i).inf $(_i).cat $(_i)_x64.cat ;
	}

	# Driver 2 arrangement
	for  _i in $(INFS2) {
		_ni  = [ NormPaths $(_i).inf ] ;
		_ns  = [ NormPaths $(_i).sed ] ;
		_nt  = [ NormPaths template_inf ] ;
		_nds = [ NormPaths $(DRIVERS2).sed ] ;
		GenFileNND $(_i).inf : "sed -f $(_ns) < $(_nt) | sed -f $(_nds) > $(_ni)"
		                      : $(_i).sed template_inf $(DRIVERS2).sed ;
		File $(_i).cat     : template_cat ;
		File $(_i)_x64.cat : pttemplate_cat ;
		NDepends install : $(_i).inf $(_i).cat $(_i)_x64.cat ;
	}
}

SubInclude libusb ;

if $(BUILD_EXAMPLES) = true {
	SubInclude examples ;
}

# Get the user mode library compiled using Jam
File libusb.h : libusb/libusb.h ;
if $(LIBUSB_IS_DLL) = true {
	File $(LIBUSB1NAME)$(SUFSHLIB) : libusb/$(LIBUSB1NAME)$(SUFSHLIB) ;
	File $(LIBUSB1NAME)$(SUFIMPLIB) : libusb/$(LIBUSB1NAME)$(SUFIMPLIB) ;
	InstallFile ../bin : $(LIBUSB1NAME)$(SUFSHLIB) ;
} else {
	File $(LIBUSB1NAME)$(SUFLIB) : libusb/$(LIBUSB1NAME)$(SUFLIB) ;
}


if $(NT) {

	NDepends install : $(LIBUSB1NAME)_x64.lib $(LIBUSB1NAME)_x64.dll
	                   libusb0.sys libusb0_x64.sys ;

	# To build the library and/or driver using the DDK, a build window needs to
	# be started, navigate to libusb1 and run "ddk_build.cmd".
	# This needs to be done for 32 & 64 bit.

	# copy the 32 bit .dll library compiled using the DDK
#	NoCare [ NormIDstTargets libusb/os/objfre_wnet_x86/i386/$(LIBUSB1NAME).lib ] ;
#	FileNoClean libusb-X.X.lib : libusb/os/objfre_wnet_x86/i386/libusb-X.X.lib ;
#	FileNoClean $(LIBUSB1NAME).lib : libusb-X.X.lib ;
#	if $(LIBUSB_IS_DLL) = true {
#		NoCare [ NormIDstTargets libusb/os/objfre_wnet_x86/i386/libusb-X.X.dll ] ;
#		FileNoClean libusb-X.X.dll : libusb/os/objfre_wnet_x86/i386/libusb-X.X.dll ;
#		FileNoClean $(LIBUSB1NAME).dll : libusb-X.X.dll ;
#	}

	# copy the 64 bit .dll library compiled using the DDK
	NoCare [ NormIDstTargets libusb/os/objfre_wnet_amd64/amd64/libusb-X.X.lib ] ;
	FileNoClean libusb-X.X_x64.lib : libusb/os/objfre_wnet_amd64/amd64/libusb-X.X.lib ;
	File $(LIBUSB1NAME)_x64.lib : libusb-X.X_x64.lib ;
	if $(LIBUSB_IS_DLL) = true {
		NoCare [ NormIDstTargets libusb/os/objfre_wnet_amd64/amd64/libusb-X.X.dll ] ;
		FileNoClean libusb-X.X_x64.dll : libusb/os/objfre_wnet_amd64/amd64/libusb-X.X.dll ;
		FileNoClean $(LIBUSB1NAME)_x64.dll : libusb-X.X_x64.dll ;
	}

	# copy the libusb0.sys files compiled using the DDK
	NoCare [ NormIDstTargets libusb/os/driver/objfre_wnet_x86/i386/libusb0.sys ] ;
	FileNoClean libusb0.sys : libusb/os/driver/objfre_wnet_x86/i386/libusb0.sys ;

	# copy the 64 bit libusb0.sys files compiled using the DDK
	NoCare [ NormIDstTargets libusb/os/driver/objfre_wnet_amd64/amd64/libusb0.sys ] ;
	FileNoClean libusb0_x64.sys : libusb/os/driver/objfre_wnet_amd64/amd64/libusb0.sys ;
}

# Create a config.h

NDepends config.h : Jamfile ;

CatToFile config.h ;
CatToFile config.h : "#ifndef LIBUSB_CONFIG_H" ;
CatToFile config.h : "/* config.h generated by Jamfile */" ;
if $(ENABLE_DEBUG_LOGGING) = true {
	CatToFile config.h : "/* Debug message logging */" : "#define ENABLE_DEBUG_LOGGING 1" ;
} else {
	CatToFile config.h : "/* Debug message logging */" : "/* #undef ENABLE_DEBUG_LOGGING */" ;
}
if $(ENABLE_LOGGING) = true {
	CatToFile config.h : "/* Message logging */" : "#define ENABLE_LOGGING 1" ;
} else {
	CatToFile config.h : "/* Message logging */" : "/* #undef ENABLE_LOGGING */" ;
}

if $(NT) {
	CatToFile config.h : "/* Default visibility */" : "#define API_EXPORTED /**/" ;
	CatToFile config.h : "/* Windows backend */" : "#define OS_WINDOWS /**/" ;
	CatToFile config.h : "/* Define to 1 if you have the ANSI C header files. */" : "#define STDC_HEADERS 1" ;
	CatToFile config.h : "/* Backend doesn't handle timeout */" : "/* #undef USBI_OS_HANDLES_TIMEOUT */" ;
	if [ GLOB /usr/include/sys : timerfd.h ] {
Echo "timerfd headers available" ;
		CatToFile config.h : "/* timerfd headers available */" : "#define USBI_TIMERFD_AVAILABLE /**/" ;
	} else {
Echo "timerfd headers NOT available" ;
		CatToFile config.h : "/* timerfd headers available */" : "/* #undef USBI_TIMERFD_AVAILABLE */" ;
	}
}

if $(UNIX) {
	if $(OS) != MACOSX {
		CatToFile config.h : "/* Default visibility */" : "#define API_EXPORTED /**/" ;
		CatToFile config.h : "/* Linux backend */" : "#define OS_LINUX /**/" ;
		CatToFile config.h : "/* Define to 1 if you have the ANSI C header files. */" : "#define STDC_HEADERS 1" ;
		CatToFile config.h : "/* Backend doesn't handles timeout */" : "/* #undef USBI_OS_HANDLES_TIMEOUT */" ;
		CatToFile config.h : "/* timerfd headers available */" : "/* #undef USBI_TIMERFD_AVAILABLE */" ;
	} else {
		CatToFile config.h : "/* Default visibility */" : "#define API_EXPORTED /**/" ;
		CatToFile config.h : "/* OS X Darwin backend */" : "#define OS_DARWIN /**/" ;
		CatToFile config.h : "/* Define to 1 if you have the ANSI C header files. */" : "#define STDC_HEADERS 1" ;
		CatToFile config.h : "/* Backend doesn't handle timeout */" : "/* #undef USBI_OS_HANDLES_TIMEOUT */" ;
		if [ GLOB /usr/include/sys : timerfd.h ] {
			CatToFile config.h : "/* timerfd headers available */" : "#define USBI_TIMERFD_AVAILABLE /**/" ;
		} else {
			CatToFile config.h : "/* timerfd headers available */" : "/* #undef USBI_TIMERFD_AVAILABLE */" ;
		CatToFile config.h : "/* patchs for OS X 10.3 */" ;
		CatToFile config.h : "#include <poll.h>" : "#ifdef _POLL_EMUL_H_" :
		                     "	typedef unsigned int nfds_t;" : "#endif" ;
		CatToFile config.h : "#ifndef IO_OBJECT_NULL" : "# define IO_OBJECT_NULL ((io_object_t) 0)" : "#endif" ;
		}
	}
}
CatToFile config.h : "#define LIBUSB_CONFIG_H" : "#endif /* !LIBUSB_CONFIG_H */ " ;












