{
	'variables': {
		'platform'       : '<(OS)',
		'opengl_root'    : '<!(node -e "console.log(require(\'node-deps-opengl-raub\').root)")',
		'opengl_include' : '<(opengl_root)/include',
		'opengl_bin'     : '<!(node -e "console.log(require(\'node-deps-opengl-raub\').bin)")',
		'cuda_root'      : '$(CUDA_PATH)',
	},
	
	'conditions': [
		['platform == "mac"', { 'variables': { 'platform': 'darwin' } }],
		['platform == "win"', {
			'variables': { 'platform': 'win32'  },
			'conditions': [
				['target_arch=="x64"',
					{
						'variables': { 'arch': 'x64' }
					}, {
						'variables': { 'arch': 'Win32' }
					}
				],
			],
		}],
	],
	"targets": [
		{
			"target_name": "cuda",
			'include_dirs': [ '<(opengl_include)' ],
			'library_dirs': [ '<(opengl_bin)'     ],
			"sources": [
				"src/bindings.cpp",
				"src/ctx.cpp",
				"src/device.cpp",
				"src/function.cpp",
				"src/mem.cpp",
				"src/module.cpp",
				"src/thrust_func.cu"
			],
			'rules': [{
				'extension': 'cu',
				'inputs': ['<(RULE_INPUT_PATH)'],
				'outputs':[ '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj'],
				'conditions': [
					[
						'OS=="win"',
						{
							'rule_name': 'cuda on windows',
							'message': "compile cuda file on windows",
							'process_outputs_as_sources': 0,
							'action': [
								'nvcc --cl-version 2013 --machine 32',
								'--use_fast_math',
								'-c', '-o', '<@(_outputs)',
								'<@(_inputs)'
							],
						},
						{
							'rule_name': 'cuda on linux',
							'message': "compile cuda file on linux",
							'process_outputs_as_sources': 1,
							'action': [
								'nvcc',
								'-Xcompiler',
								'-fpic',
								'-c',
								'--machine', '64',
								'-lcuda',
								'-lcudart',
								'-I/usr/local/cuda-7.0/targets/x86_64-linux/include',
								'-I/usr/include/x86_64-linux-gnu',
								'<@(_inputs)',
								'-o','<@(_outputs)'
							],
						}
					]
				]
			}],
			'conditions': [
				[ 'OS=="mac"', {
					'libraries': ['-framework CUDA'],
					'include_dirs': ['/usr/local/include'],
					'library_dirs': ['/usr/local/lib']
				}],
				[ 'OS=="linux"', {
					'libraries': ['-lcuda'],
					'include_dirs': ['/usr/local/include'],
					'library_dirs': ['/usr/local/lib']
				}],
				[ 'OS=="win"', {
					'defines' : [
						'WIN32_LEAN_AND_MEAN',
						'VC_EXTRALEAN'
					],
					'msvs_version'	: '2013',
					'msvs_settings' : {
					
						'VCCLCompilerTool' : {
							'AdditionalOptions' : [
								'/O2','/Oy','/GL','/GF','/Gm-',
								'/EHsc','/MT','/GS','/Gy','/GR-','/Gd',
							]
						},
						'VCLinkerTool' : {
							'AdditionalOptions' : ['/OPT:REF','/OPT:ICF','/LTCG']
						},
					},
					'libraries': [
						'-l<(cuda_root)/lib/<(arch)/cuda.lib',
						'-l<(cuda_root)/lib/<(arch)/cudart.lib',
					],
					"include_dirs": [
						"<(cuda_root)/include",
					],
				}, {
					"include_dirs": [
						"/usr/local/cuda-5.0/include",
						"/usr/local/cuda/include"
					],
				}]
			]
		},
		
		{
			'target_name'  : 'copy_binary',
			'type'         : 'none',
			'dependencies' : ['cuda'],
			'message'      : 'Copying the addon into the platform-specific directory.',
			'copies'       : [
				{
					'destination' : '<(module_root_dir)/bin_<(platform)',
					'conditions'  : [
						[
							'OS=="linux"',
							{ 'files' : [] }
						],
						[
							'OS=="mac"',
							{ 'files' : [] }
						],
						[
							'OS=="win"',
							{ 'files' : [ '<(module_root_dir)/build/Release/cuda.node' ] },
						],
					]
				}
			],
		},
		
		{
			'target_name'  : 'remove_temporaries',
			'type'         : 'none',
			'dependencies' : ['copy_binary'],
			'message'      : 'Removing temporary files.',
			'actions'      : [
				{
					'action_name' : 'action_remove1',
					'inputs'      : ['build/Release/cuda.*'],
					'outputs'     : ['build'],
					'conditions'  : [
						[ 'OS=="linux"', { 'action' : [ 'rm -rf <@(_inputs)' ] } ],
						[ 'OS=="mac"'  , { 'action' : [ 'rm -rf <@(_inputs)' ] } ],
						[ 'OS=="win"'  , { 'action' : [ '<(module_root_dir)/_del', '<@(_inputs)' ] } ],
					],
				},
				{
					'action_name' : 'action_remove2',
					'inputs'      : ['build/Release/obj/cuda/*.obj'],
					'outputs'     : ['build'],
					'conditions'  : [
						[ 'OS=="linux"', { 'action' : [ 'rm -rf <@(_inputs)' ] } ],
						[ 'OS=="mac"'  , { 'action' : [ 'rm -rf <@(_inputs)' ] } ],
						[ 'OS=="win"'  , { 'action' : [ '<(module_root_dir)/_del', '<@(_inputs)' ] } ],
					],
				},
				{
					'action_name' : 'action_remove3',
					'inputs'      : ['build/Release/obj/cuda/*.pdb'],
					'outputs'     : ['build'],
					'conditions'  : [
						[ 'OS=="linux"', { 'action' : [ 'rm -rf <@(_inputs)' ] } ],
						[ 'OS=="mac"'  , { 'action' : [ 'rm -rf <@(_inputs)' ] } ],
						[ 'OS=="win"'  , { 'action' : [ '<(module_root_dir)/_del', '<@(_inputs)' ] } ],
					],
				},
			],
		},
		
	]
}
