target = 'System'

files = Split("""
	Source/Buffers.c
	Source/Plugin.c
	Source/System.c
""")

libs = Split("""
	kernel32
	user32
	ole32
""")

examples = Split("""
	Resource.dll
	System.nsi
	System.nsh
	SysFunc.nsh
""")

docs = Split("""
	System.html
	WhatsNew.txt
""")

Import('BuildPlugin env')

defs = ['SYSTEM_EXPORTS']
msvc = 'msvc' in env['TOOLS'] or 'mstoolkit' in env['TOOLS']

srcsuff = ''
if env['TARGET_ARCH'] != 'x86':
	srcsuff = '-' + env['TARGET_ARCH']
	defs += ['SYSTEM_NOCALLBACKS'] # BUGBUG: Remove this when CallBack() is implemented
filename = 'Call' + srcsuff

src_ascpp = """
	#if 0 /* a C style comment */
	ERROR: assembler-with-cpp required!
	#else
	.end
	#endif
"""
conf = env.Configure()
if conf.TryCompile('END', '.S'):
	files += ['Source/'+filename+'.S']
elif (not msvc) and conf.TryCompile(src_ascpp, '.S'):
	files += ['Source/'+filename+'CPP.S']
elif (not msvc) and conf.TryCompile(src_ascpp, '.sx'):
	files += ['Source/'+filename+'CPP.sx']
else:
	print('WARNING: System.dll: unable to find assembler for '+filename+'.S')
conf.Finish()

BuildPlugin(
	target,
	files,
	libs,
	examples,
	docs,
	nodeflib = False,
	defines = defs
)

res = 'Resource/Resource.rc'
res_obj = 'Resource/Resource-rc.o'
res_target = env.RES(res_obj, res)

res_main = env.Object('Resource/Main.c')

resources = Split("""
	Resource/Icon.ico
	Resource/Resource.h
""")

env.Depends(res_target, resources)

env.SharedLibrary('Resource', res_target + res_main)
