using System;
using System.IO;
using System.Linq;
partial class PortableBuilder : SolutionProjectBuilder
{
static void Main(String[] args)
{
try
{
var fi = typeof(PortableBuilder).GetField("supportOnlyOs", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
String onlyPlatform = ( fi != null ) ? fi.GetValue(null).ToString(): null;
String[] OSes;
if (onlyPlatform != null)
OSes = new string[] { onlyPlatform };
else
OSes = new String[] { "windows", "android" };
foreach (String platform in OSes)
{
bool isWindows = platform == "windows";
if( m_solution != null && !m_solution.name.EndsWith( "_" + platform ) )
continue;
group( Path.GetDirectoryName(ProjectName) );
String projName = Path.GetFileName(ProjectName);
project(projName + "_" + platform);
configurations("Debug", "Release");
if (isWindows)
{
platforms("Win32", "x64");
vsver(2013);
toolset("v120");
}
else
{
platforms("ARM", "ARM64");
vsver(2015);
androidapilevel("android-21");
useofstl("system");
toolset("Gcc_4_9");
configureLanguage();
filter( "platforms:ARM" );
thumbmode( EThumbMode.ARM );
filter();
}
targetdir("../bin/$(Configuration)_$(Platform)_" + platform);
targetname(projName);
objdir("../../obj/$(Configuration)_$(Platform)_" + platform + "_" + projName);
//filter("Debug");
// //defines("_DEBUG");
// symbols("on");
// optimize("off");
// CCpp_CodeGeneration_EnableFunctionLevelLinking();
// Ccpp_Optimization_WholeProgramGeneration();
// Ccpp_Optimization_Optimization();
//filter("Release");
// defines("NDEBUG");
// optimize("speed");
//filter();
BuildProject(platform);
}
}
catch (Exception ex)
{
ConsolePrintException(ex, args);
}
} //Main
/// <summary>
/// Probes for language which this class specifies, by default uses plain "C".
/// </summary>
static void configureLanguage()
{
String lang = "C";
var lanF = typeof( PortableBuilder ).GetField( "language", System.Reflection.BindingFlags.Static );
if( lanF != null && lanF.GetType() == typeof( String ) )
lang = lanF.GetValue( null ) as String;
if( lang == "C" )
{
language();
buildoptions( "-std=gnu99" );
}
else
{
language( "C++" );
}
}
/// <summary>
/// Adds file and configures it to be compiled with nasm.exe
/// </summary>
/// <param name="file">.nasm file to add</param>
static void nasmFiles(params String[] _files)
{
foreach ( String file in _files )
{
files(file);
filter("files:" + file);
String name = Path.GetFileNameWithoutExtension(file);
String objFile = "$(ProjectDir)$(IntermediateOutputPath)" + Path.GetFileNameWithoutExtension(file) + ".obj";
buildrule(new CustomBuildRule()
{
Message = "Assembling " + file,
Command = @"nasm.exe -f win32 -d OBJ_FORMAT_win32 -i ia32/ " + file + " -o " + objFile,
Outputs = objFile,
AdditionalInputs = "ia32/nasm.h"
});
}
filter();
}
/// <summary>
/// Adds assembly files for particular platform. For Windows uses yasm.exe (external tool), for Android uses gcc itself.
/// </summary>
/// <param name="platform">windows or android</param>
static void ffmpeg_asmFiles( String platform )
{
bool isWindows = platform == "windows";
String[] pickDirs;
if( isWindows )
pickDirs = new String[] { "x86" };
else
pickDirs = new String[] { "arm" };
String projectDir = Path.GetFileName( Path.GetDirectoryName( m_project.getFullPath() ) );
foreach( String asmDir in pickDirs )
{
String asmExt = ".asm";
if( asmDir != "x86" )
asmExt = ".S";
files( asmDir + "/*.c" );
files( asmDir + "/*" + asmExt );
// test projects
removefiles( "**test.c");
// template files, included from another .c files
removefiles( "**template.c");
if( asmDir == "x86")
removefiles( "x86/x86inc.asm", "x86/x86util.asm" );
foreach( FileInfo fi in getCurrentProjectFiles( asmDir + "/**" + asmExt ) )
{
selectConfigurations( fi );
String dir = Path.GetDirectoryName( fi.relativePath );
String name = Path.GetFileNameWithoutExtension( fi.relativePath );
String objExt = ".obj";
if( !isWindows )
objExt = ".o";
String uniqueObjName = Path.Combine( Path.GetDirectoryName( fi.relativePath ), Path.GetFileNameWithoutExtension( fi.relativePath ) ).Replace( "\\", "_" ) + objExt;
String objFile = "$(ProjectDir)$(IntermediateOutputPath)" + uniqueObjName;
String exe = ( isWindows ) ? "yasm.exe" : "$(ClangToolExe)";
String asmParams;
if( isWindows )
asmParams = "-f win32 -DPREFIX -I./ -I.// -Pconfig.asm -I " + projectDir + "/x86/";
else
asmParams = "-I . -march=armv7-a -mfloat-abi=softfp -c";
String fileLongPath = Path.Combine( projectDir, fi.relativePath );
String cmd = exe + " " + asmParams + " -o " + objFile + " " + fileLongPath;
if( !String.IsNullOrEmpty( dir ) )
cmd = "pushd ..\r\n" + cmd + "\r\npopd";
buildrule( new CustomBuildRule()
{
Message = "Assembling '" + fi.relativePath + "'...",
Command = cmd,
Outputs = objFile
} );
}
} //asmDir
} //ffmpeg_asmFiles
/// <summary>
/// Sets ffmpeg project configuration - disables some of warnings, sets up compilation options.
/// </summary>
/// <param name="platform"></param>
static void ffmpeg_setCommonProjectOptions( String platform )
{
defines("_ISOC99_SOURCE", "_FILE_OFFSET_BITS=64", "_LARGEFILE_SOURCE");
defines("HAVE_AV_CONFIG_H", "_USE_MATH_DEFINES", "_CRT_SECURE_NO_WARNINGS");
EnableMultiProcessorBuild();
includedirs("..\\.");
if ( platform == "windows")
{
disablewarnings( "4244", "4127", "4018", "4389", "4146", "4057", "4204", "4706", "4305", "4152", "4324", "4100", "4214", "4554" );
disablewarnings( "4273", "4701" );
defines( "_WIN32_WINNT=0x0502" );
defines( "strtod=avpriv_strtod", "snprintf=avpriv_snprintf", "_snprintf=avpriv_snprintf", "vsnprintf=avpriv_vsnprintf", "inline=__inline", "strtoll=_strtoi64" );
return;
}
String[] warnings = new String[]
{
"declaration-after-statement",
"all",
"disabled-optimization",
"pointer-arith",
"redundant-decls",
"write-strings",
"type-limits",
"undef",
"missing-prototypes",
"no-pointer-to-int-cast",
"strict-prototypes",
"empty-body",
"no-parentheses",
"no-switch",
"no-format-zero-length",
"no-pointer-sign",
"error=format-security",
//"error=implicit-function-declaration",
"error=missing-prototypes",
"error=return-type",
"error=vla",
"format",
"no-maybe-uninitialized"
};
String opts = String.Join( " ", warnings.Select( x => "-W" + x ) );
buildoptions( opts );
//
// -marm is required at least by vp5.c, vp56.c, vp6, might be others as well, but in general arm is faster than thumb -
// see https://stackoverflow.com/questions/11062936/gcc-mthumb-against-marm
//
buildoptions( "-march=armv7-a -marm" );
}
}; //class PortableBuilder