Esempio n. 1
0
def generateMakefile(make, ctx, toolchains, output_path):
	api.log('Android makefile: ' + ctx['workspace'], 0)
	api.log('Target directory: ' + output_path, 1)
	api.warning('Build and architecture support with NDK-BUILD is done through Application.mk', 1)

	if not os.path.exists(output_path):
	    os.makedirs(output_path)

	# convert projects
	groups = make.getConfigurationKeyValuesFilterByContext('group', ctx)

	mk_projects = []
	for group in groups:
		group_ctx = ctx.clone({'group': group})
		projects = make.getConfigurationKeyValuesFilterByContext('project', group_ctx)
		for project in projects:
			# filter out any build specific configuration keys, they will be added to Application.mk
			mk_projects.append(generateProject(make, group_ctx.clone({'project': project, 'build': '@Exclude'}), output_path))

	# write Android makefile
	api.log("Output makefile 'Android.mk'", 1)
	f = open(output_path + '/' + 'Android.mk', 'w')
	outputHeader(f)
	f.write('LOCAL_PATH := $(call my-dir)\n\n')
	for project in mk_projects:
		outputProject(f, make, project, mk_projects, output_path)
	f = None

	# write Application makefile
	outputApplicationMk(make, ctx, toolchains, mk_projects, output_path)
Esempio n. 2
0
def outputApplicationMk(make, ctx, toolchains, mk_projects, output_path):
	api.log("Output makefile 'Application.mk'", 1)
	f = open(output_path + '/' + 'Application.mk', 'w')
	outputHeader(f)

	# grab builds
	builds = make.getConfigurationKeyValuesFilterByContext('build', ctx)
	if len(builds) == 0:
		api.warning("No build configuration to make for this application", 1)
		return

	# output build selection
	f.write('# Select the build configuration. Possible values: ')
	first = True
	for build in builds:
		if first == False:
			f.write(', ')
		f.write('"' + build + '"')
		first = False
	f.write('.\n')
	f.write('BUILD = "' + builds[0] + '"\n')

	# output architecture selection (ugh...)
	supported_archs = []
	for toolchain in toolchains:
		if toolchain['target'] == 'android':
			for arch in toolchain['arch']:
				if getArchABI(arch) != None:
					supported_archs.append(arch)

	f.write('# Select the target architecture. Possible values: ')
	first = True
	for arch in supported_archs:
		if first == False:
			f.write(', ')
		f.write('"' + arch + '"')
		first = False
	f.write('.\n')
	f.write('ARCH = "' + supported_archs[0] + '"\n')

	f.write('\n')

	# global settings.
	app_platform = make.get('android_app_platform', ctx)
	if app_platform:
		f.write('APP_PLATFORM := android-' + str(app_platform[0]) + '\n')

	# output build rules
	f.write('\n')

	for build in builds:
		for toolchain in toolchains:
			if toolchain['target'] != 'android':
				continue
			for arch in toolchain['arch']:
				abi = getArchABI(arch)
				if abi == None:
					api.warning('Unsupported architecture: ' + arch + '\n', 1)
					continue

				app_ctx = ctx.clone({'build': build, 'arch': arch, 'project': '@exclude'})	# in this build for this architecture, not specific to a project

				f.write('# Configuration for build ' + build + ' ' + arch + '\n')
				f.write('#------------------------------------------------\n')
				f.write('ifeq (${BUILD}, "' + build + '")\n')
				f.write('  ifeq (${ARCH}, "' + arch + '")\n\n')

				# app cflags
				app_cflags = ''
				defines = make.get('define', app_ctx)
				if defines != None:
					for define in defines:
						app_cflags += '-D' + define + ' '

				cflags = make.get('cflags', app_ctx)
				if cflags != None:
					if 'use-neon' in cflags:
						f.write('LOCAL_ARM_NEON := true\n')

					gflags = convertCFlags(cflags)
					for v in gflags:
						app_cflags += v + ' '

				if app_cflags != '':
					f.write('APP_CFLAGS := ' + app_cflags + '\n')

				f.write('APP_OPTIM := ' + ('debug' if 'debug' in cflags else 'release') +'\n')
				f.write('APP_ABI := ' + abi + '\n')

				if 'use-stlport' in cflags:
					f.write('APP_STL := stlport_static\n')

				f.write('\n  endif\n')
				f.write('endif\n\n')
Esempio n. 3
0
def outputProject(make, project, projects, output_path):
	project_ctx = project['ctx']

	api.log("Output project '" + project['name'] + "'", 1)
	f = open(output_path + '/' + project['name'] + '.vcxproj', 'w')

	f.write('<?xml version="1.0" encoding="utf-8"?>\n')
	f.write('<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\n')

	# configurations
	f.write('  <ItemGroup Label="ProjectConfigurations">\n')
	for cfg in project['configurations']:
		cfg['qualified_name'] = cfg['name'] + '|' + cfg['vsplatform']
		f.write('    <ProjectConfiguration Include="' + cfg['qualified_name'] + '">\n')
		f.write('      <Configuration>' + cfg['name'] + '</Configuration>\n')
		f.write('      <Platform>' + cfg['vsplatform'] + '</Platform>\n')
		f.write('    </ProjectConfiguration>\n')
	f.write('  </ItemGroup>\n')

	# global properties
	f.write('  <PropertyGroup Label="Globals">\n')
	f.write('    <ProjectGuid>{' + project['guid'] + '}</ProjectGuid>\n')
	f.write('    <RootNamespace>' + project['name'] + '</RootNamespace>\n')
	f.write('    <Keyword>' + getProjectKeyword(make, project_ctx) + '</Keyword>\n')
	f.write('  </PropertyGroup>\n')

	# store a few commonly used values directly in the configuration
	for cfg in project['configurations']:
		cfg['deps'] = make.getDependencies(cfg['ctx'])
		cfg['links'] = make.getLinksAcrossDependencies(cfg['deps'], cfg['ctx'])
		cfg['type'] = make.getBestMatch('type', cfg['ctx'])
		cfg['cflags'] = make.get('cflags', cfg['ctx'])
		cfg['pflags'] = make.get('pflags', cfg['ctx'])

	# build the project link list across all configurations (we'll disable unused ones on a per project basis in the solution)
	project['all_link'] = None
	for cfg in project['configurations']:
		project['all_link'] = api.appendToList(project['all_link'], cfg['links'])
	if project['all_link'] != None:
		project['all_link'] = list(set(project['all_link']))

	# cpp default properties
	f.write('  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\n')

	# general project properties
	for cfg in project['configurations']:
		f.write('  <PropertyGroup ' + getCondition(cfg) + ' Label="Configuration">\n')
		outputGeneralProjectProperty(f, make, project, cfg)
		f.write('  </PropertyGroup>\n')

	# cpp extension settings
	f.write('  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\n')
	f.write('  <ImportGroup Label="ExtensionSettings">\n')
	f.write('  </ImportGroup>\n')

	# default props
	for cfg in project['configurations']:
		f.write('  <ImportGroup Label="PropertySheets" ' + getCondition(cfg) + '>\n')
		f.write('    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists(\'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props\')" Label="LocalAppDataPlatform" />\n')
		f.write('  </ImportGroup>\n')

	# user macros
	f.write('  <PropertyGroup Label="UserMacros" />\n')

	# binary output
	for cfg in project['configurations']:
		f.write('  <PropertyGroup ' + getCondition(cfg) + '>\n')
		f.write('    <OutDir>' + getBinaryPath(make, cfg) + '</OutDir>\n')
		f.write('    <IntDir>' + getIntermediatePath(make, cfg) + '</IntDir>\n')

		target_name = make.getBestMatch('target_name', cfg['ctx'])
		if not target_name:
			target_name = getBinaryName(project['name'], cfg['type'], cfg['ctx']['target'])

		suffix = make.getBestMatch('bin_suffix', cfg['ctx'])
		if suffix:
			target_name += suffix

		target_ext = make.getBestMatch('bin_ext', cfg['ctx'])
		if not target_ext:
			target_ext = getBinaryExt(cfg['type'], cfg['ctx']['target'])

		f.write('    <TargetName>' + target_name + '</TargetName>\n')
		f.write('    <TargetExt>' + target_ext + '</TargetExt>\n')
		f.write('  </PropertyGroup>\n')

	# compiler / linker properties
	for cfg in project['configurations']:
		ctx = cfg['ctx']
		suffix = make.get('bin_suffix', ctx)

		f.write('  <ItemDefinitionGroup ' + getCondition(cfg) + '>\n')

		# compiler
		cflags = cfg['cflags']

		outDir = '$(OutDir)' if 'debug' in cfg['cflags'] else '$(IntDir)'

		f.write('    <ClCompile>\n')
		f.write('      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n')
		f.write('      <WarningLevel>' + getWarningLevel(cflags) + '</WarningLevel>\n')
		f.write('      <PreprocessorDefinitions>' + getDefines(make, cfg) + '</PreprocessorDefinitions>\n')
		f.write('      <AdditionalIncludeDirectories>' + getAdditionalIncludes(make, cfg, output_path) + '</AdditionalIncludeDirectories>\n')
		f.write('      <DebugInformationFormat>' + getDebugInformation(cflags) + '</DebugInformationFormat>\n')
		f.write('      <ProgramDataBaseFileName>'+ outDir + getPDBName(project['name'], suffix) + '.pdb</ProgramDataBaseFileName>\n')
		f.write('      <Optimization>' + getOptimization(cflags) + '</Optimization>\n')
		f.write('      <ExceptionHandling>' + getUseExceptions(cflags) + '</ExceptionHandling>\n')
		f.write('      <RuntimeTypeInfo>' + getUseRTTI(cflags) + '</RuntimeTypeInfo>\n')
		f.write('      <FloatingPointModel>' + getFloatingPointModel(cflags) + '</FloatingPointModel>\n')
		
		if 'omit-frame-pointers' in cflags:
			f.write('      <OmitFramePointers>true</OmitFramePointers>\n')

		f.write('      <RuntimeLibrary>' + getRuntimeLibrary(make, cfg) + '</RuntimeLibrary>\n')

		f.write('      <MultiProcessorCompilation>' + getMultiProcessorCompilation(cflags) + '</MultiProcessorCompilation>\n')
		f.write('      <MinimalRebuild>' + getMinimalRebuild(cflags) + '</MinimalRebuild>\n')

		additionalClOptions = getAdditionalClOptions(make, cfg)
		if additionalClOptions != None:
			f.write('      <AdditionalOptions>' + additionalClOptions + ' %(AdditionalOptions)</AdditionalOptions>\n')

		align_dict = {'struct-member-align-1': 1, 'struct-member-align-2': 2, 'struct-member-align-4': 4, 'struct-member-align-8': 8, 'struct-member-align-16': 16}
		for key in align_dict.keys():
			if key in cflags:
				f.write('      <StructMemberAlignment>' + str(align_dict[key]) + 'Bytes</StructMemberAlignment>\n')
				break

		if 'x64' not in ctx['arch'] and 'use-sse2' in cflags:
			f.write('      <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>\n')

		outputPrecompiledHeaderTags(f, make, cfg)
		f.write('    </ClCompile>\n')

		f.write('    <Link>\n')
		f.write('      <SubSystem>' + getSubSystem(make, cfg) + '</SubSystem>\n')
		f.write('      <AdditionalDependencies>' + getAdditionalDependencies(make, cfg, projects) + '</AdditionalDependencies>\n')
		f.write('      <AdditionalLibraryDirectories>' + getAdditionalLibraryDirectories(make, cfg, output_path) +'</AdditionalLibraryDirectories>\n')
		f.write('      <GenerateDebugInformation>' + ('True' if ('debug' in cfg['cflags'] or 'debug-info' in cfg['cflags']) else 'False') + '</GenerateDebugInformation>\n')

		ModuleDefFile = getModuleDefinitionFile(make, cfg);
		if (ModuleDefFile != None):
			f.write('      <ModuleDefinitionFile>' + ModuleDefFile + '</ModuleDefinitionFile>\n')

		additionalLinkOptions = getAdditionalLinkOptions(make, cfg)
		if additionalLinkOptions != None:
			f.write('      <AdditionalOptions>' + additionalLinkOptions + ' %(AdditionalOptions)</AdditionalOptions>\n')

		UACExecutionLevel = getUACExecutionLevel(make, cfg)
		if UACExecutionLevel != None:
			f.write('      <UACExecutionLevel>' + UACExecutionLevel + '</UACExecutionLevel>\n')

		outputAdditionalLinkTags(f, make, cfg)

		f.write('    </Link>\n')

		f.write('    <Lib>\n')

		additionalLibDependencies = getAdditionalLibDependencies(make, cfg)
		if additionalLibDependencies != None:
			f.write('      <AdditionalDependencies>' + additionalLibDependencies + '</AdditionalDependencies>\n')

		LibTargetMachine = getLibTargetMachine(make, cfg)
		if LibTargetMachine != None:
			f.write('      <TargetMachine>' + LibTargetMachine + '</TargetMachine>\n')

		f.write('    </Lib>\n')

		PreBuildEventCommand = getPreBuildEventCommand(make, cfg)
		PreBuildEventMessage = getPreBuildEventMessage(make, cfg)
		if (PreBuildEventCommand != None):
			f.write('    <PreBuildEvent>\n')
			f.write('      <Command>' + PreBuildEventCommand + '</Command>\n')
			if (PreBuildEventMessage != None):
				f.write('      <Message>' + PreBuildEventMessage + '</Message>\n')
			f.write('    </PreBuildEvent>\n')


		PreLinkEventCommand = getPreLinkEventCommand(make, cfg)
		PreLinkEventMessage = getPreLinkEventMessage(make, cfg)
		if (PreLinkEventCommand != None):
			f.write('    <PreLinkEvent>\n')
			f.write('      <Command>' + PreLinkEventCommand + '</Command>\n')
			if (PreLinkEventMessage != None):
				f.write('      <Message>' + PreLinkEventMessage + '</Message>\n')
			f.write('    </PreLinkEvent>\n')

		PostBuildEventCommand = getPostBuildEventCommand(make, cfg)
		PostBuildEventMessage = getPostBuildEventMessage(make, cfg)
		if (PostBuildEventCommand != None):
			f.write('    <PostBuildEvent>\n')
			f.write('      <Command>' + PostBuildEventCommand + '</Command>\n')
			if (PostBuildEventMessage != None):
				f.write('      <Message>' + PostBuildEventMessage + '</Message>\n')
			f.write('    </PostBuildEvent>\n')

		f.write('  </ItemDefinitionGroup>\n')

	# source files
	project['files'] = []
	for cfg in project['configurations']:	# grab across all configurations
		cfg['files'] = make.get('files', cfg['ctx'])
		if cfg['files']:
			cfg['files'] = [getSolutionFileName(file, output_path) for file in cfg['files']]
			project['files'].extend(cfg['files'])

	project['files'] = list(set(project['files']))
	project['files'] = [{'name': file, 'skip_cfg': [], 'bigobj_cfg': [], 'nopch_cfg': []} for file in project['files']]

	if len(project['files']) == 0:
		api.warning("No files added to project '" + project['name'] + "' in context " + str(project_ctx), 1)

	# skipped configurations per file
	def getProjectFile(name):
		for file in project['files']:
			if file['name'] == name:
				return file
		return None

	for cfg in project['configurations']:
		skips = make.get('skip_files', cfg['ctx'])
		if skips:
			for skip in skips:
				file = getProjectFile(getSolutionFileName(skip, output_path))
				if file:
					file['skip_cfg'].append(cfg)

	for file in project['files']:
		for cfg in project['configurations']:
			if file['name'] not in cfg['files']:
				file['skip_cfg'].append(cfg)

	# PCH creation per configuration
	for cfg in project['configurations']:
		create_pch = make.get('create_pch', cfg['ctx'])
		cfg['create_pch'] = api.getRelativePath(create_pch[0], output_path, 'windows') if create_pch != None else ''

	# big obj per file
	for cfg in project['configurations']:
		nopchs = make.get('big_obj', cfg['ctx'])
		if nopchs:
			for nopch in nopchs:
				file = getProjectFile(getSolutionFileName(nopch, output_path))
				if file:
					file['bigobj_cfg'].append(cfg)

	for file in project['files']:
		for cfg in project['configurations']:
			if file['name'] not in cfg['files']:
				file['bigobj_cfg'].append(cfg)
	
	# no pch per file
	for cfg in project['configurations']:
		nopchs = make.get('no_pch', cfg['ctx'])
		if nopchs:
			for nopch in nopchs:
				file = getProjectFile(getSolutionFileName(nopch, output_path))
				if file:
					file['nopch_cfg'].append(cfg)

	for file in project['files']:
		for cfg in project['configurations']:
			if file['name'] not in cfg['files']:
				file['nopch_cfg'].append(cfg)

	# distribute over file categories	
	distributeProjectFiles(make, project, output_path)

	# output include files
	f.write('  <ItemGroup>\n')
	for file in project['include_files']:
		openIncludeFileClDirective(f, project, file, output_path)
		outputIncludeFileClDirective(f, make, project, file, output_path)
		closeIncludeFileClDirective(f, project, file, output_path)
	f.write('  </ItemGroup>\n')

	# output compilation units
	f.write('  <ItemGroup>\n')
	for file in project['source_files']:
		openCompileFileClDirective(f, project, file, output_path)
		outputCompileFileClDirective(f, make, project, file, output_path)
		outputPCHDirective(f, project, file)
		outputBigObjDirective(f, project, file)
		outputNoPchDirective(f, file)
		outputExcludeFileFromBuildDirective(f, file)
		closeCompileFileClDirective(f, project, file, output_path)
	f.write('  </ItemGroup>\n')

	# output resource compilation
	f.write('  <ItemGroup>\n')
	for file in project['resource_files']:
		f.write('    <ResourceCompile Include=\"' + file['name'] + '\" />\n')
	f.write('  </ItemGroup>\n')

	# output custom units
	f.write('  <ItemGroup>\n')
	for file in project['custom_files']:
		openCustomFileClDirective(f, project, file, output_path)
		outputCustomFileClDirective(f, make, project, file, output_path)
		outputPCHDirective(f, project, file)
		outputBigObjDirective(f, project, file)
		outputNoPchDirective(f, file)
		outputExcludeFileFromBuildDirective(f, file)
		closeCustomFileClDirective(f, project, file, output_path)
	f.write('  </ItemGroup>\n')

	# project dependencies
	common_links = copy.deepcopy(project['all_link'])	# links common to all configurations
	for cfg in project['configurations']:
		if cfg['links'] != None:
			common_links = [link for link in common_links if link in cfg['links']]

	for cfg in project['configurations']:				# links specific to this configuration
		if cfg['links'] != None:
			cfg['cfg_links'] = [link for link in cfg['links'] if link not in common_links]

	if common_links and len(common_links) > 0:
		f.write('  <ItemGroup>\n')
		for link in common_links:
			prj = getProject(projects, link)
			if prj != None:
				f.write('    <ProjectReference Include="' + prj['name'] +'.vcxproj">\n')
				f.write('      <Project>{' + prj['guid'] +'}</Project>\n')
				f.write('    </ProjectReference>\n')
		f.write('  </ItemGroup>\n')

	for cfg in project['configurations']:
		if 'cfg_links' in cfg and len(cfg['cfg_links']) > 0:
			f.write('  <ItemGroup ' + getCondition(cfg) + '>\n')
			for link in cfg['cfg_links']:
				prj = getProject(projects, link)
				if prj != None:
					f.write('    <ProjectReference Include="' + prj['name'] +'.vcxproj">\n')
					f.write('      <Project>{' + prj['guid'] +'}</Project>\n')
					f.write('    </ProjectReference>\n')
			f.write('  </ItemGroup>\n')

	# extensions
	f.write('  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\n')
	f.write('  <ImportGroup Label="ExtensionTargets">\n')
	f.write('  </ImportGroup>\n')

	f.write('  <ProjectExtensions>\n')
	outputProjectExtensionTag(f, make, project)
	f.write('  </ProjectExtensions>\n')

	# project done, next!
	f.write('</Project>\n')