function build(argv, tempDir, outputBaseFile, ccFiles, done) {
  switch (os.platform()) {
    case 'linux':
      buildWithGcc();
      break;
    case 'win32':
     buildWithVisualStudio();
     break;
    default:
      console.log('Unsupported build platform: ' + os.platform());
      return 1;
  }

  function buildWithGcc() {
    var outputFile = outputBaseFile;

    // Add shared files.
    ccFiles.push(path.join(templatePath, 'webgl-main.cc'));

    // Build base command line for G++.
    var commandLine = [
      'CXXFLAGS="' + [
        '-std=c++0x',
        '-I' + templatePath,
        '-L/usr/local/lib',
        '-Wl,-rpath,/usr/local/lib',
        '-lm -lSDL2 -lpthread -lGL -ldl -lrt',
        '-I/usr/local/include/SDL2',
        '-D_REENTRANT',
      ].join(' ') + '"',
      'LDFLAGS="' + [
        '-o ' + outputFile,
        '-L/usr/local/lib',
        '-lm -lSDL2 -lpthread -lGL -ldl -lrt',
      ].join(' ') + '"',
      'make',
      '-f ' + templatePath + '/Makefile',
      '-j 16',
      'src="' + ccFiles.join(' ') + '"'
    ];

    // Build!
    child_process.exec(
        commandLine.join(' '), {
        }, function(error, stdout, stderr) {
          if (error !== null) {
            console.log(stdout);
            console.log(stderr);
            console.log(error);
            done(1);
          } else {
            done(0);
          }
        });
  };

  function buildWithVisualStudio() {
    var templates = {
      vcxproj: fs.readFileSync(path.join(templatePath, 'msbuild.vcxproj'), 'utf8')
    };

    var config = argv['vs_config'] || 'Debug';
    var platform = argv['vs_platform'] || 'x86';
    var useAngle = argv['use_angle'] || false;
    var depsPath = argv['vs_deps'] || 'C:\\Dev\\tf-deps\\';

    outputBaseFile = path.resolve(outputBaseFile);

    var vcxprojPath =
        path.join(tempDir, path.basename(outputBaseFile)) + '.vcxproj';
    var exeOutputPath;
    if (platform == 'x86') {
      exeOutputPath = path.join(
          tempDir, config,
          path.basename(outputBaseFile)) + '.exe';
    } else if (platform == 'x64') {
      exeOutputPath = path.join(
          tempDir, 'x64', config,
          path.basename(outputBaseFile)) + '.exe';
    }
    var appName = path.basename(outputBaseFile);

    // Generate a list of all .cc include lines.
    var ccFileIncludes = [];
    for (var n = 0; n < ccFiles.length; n++) {
      ccFileIncludes.push('<ClCompile Include="' + ccFiles[n] + '" />');
    }

    // Template the project file.
    var vcxproj = templates.vcxproj;
    vcxproj = vcxproj.replace(/%%APPNAME%%/g, appName);
    vcxproj = vcxproj.replace(/%%DEPS%%/g, depsPath);
    vcxproj = vcxproj.replace(/%%TEMPLATEPATH%%/g, path.resolve(templatePath));
    vcxproj = vcxproj.replace(/%%CCFILES%%/g, ccFileIncludes.join('\n'));
    vcxproj = vcxproj.replace(/%%USEANGLE%%/g, useAngle ? 1 : 0);
    vcxproj = vcxproj.replace(/%%EXEOUTPUTPATH%%/g, outputBaseFile + '.exe');

    // Write out project.
    fs.writeFileSync(vcxprojPath, vcxproj);

    // Copy DLLs to output path.
    function copyFile(src, dest) {
      var content = fs.readFileSync(src, 'binary');
      fs.writeFileSync(dest, content, 'binary');
    }
    var outputBasePath = path.dirname(outputBaseFile);
    copyFile(path.join(
        depsPath, 'angleproject', 'lib', platform, 'libEGL.dll'),
        path.join(outputBasePath, 'libEGL.dll'));
    copyFile(path.join(
        depsPath, 'angleproject', 'lib', platform, 'libGLESv2.dll'),
        path.join(outputBasePath, 'libGLESv2.dll'));
    copyFile(path.join(
        depsPath, 'd3d', platform, 'd3dcompiler_46.dll'),
        path.join(outputBasePath, 'd3dcompiler_46.dll'));
    copyFile(path.join(
        depsPath, 'SDL2-2.0.0', 'lib', platform, 'SDL2.dll'),
        path.join(outputBasePath, 'SDL2.dll'));
    copyFile(path.join(
        depsPath, 'glew-1.10.0', 'bin', 'Release',
        platform == 'x86' ? 'Win32' : 'x64', 'glew32.dll'),
        path.join(outputBasePath, 'glew32.dll'));

    // Invoke msbuild.
    // TODO(benvanik): build with msbuild - right now it just dies.
    console.log('Launching VS because msbuild crashes...');
    var commandLine = [
      'devenv',
      vcxprojPath
    ];
    child_process.exec(commandLine.join(' '));
    done(0);
    // var commandLine = [
    //   'msbuild',
    //   '/p:Configuration=' + config +
    //       ';Platform=' + (platform == 'x86' ? 'Win32' : 'x64'),
    //   vcxprojPath
    // ];
    // child_process.exec(
    //     commandLine.join(' '), {
    //     }, function(error, stdout, stderr) {
    //       if (error !== null) {
    //         // Copy exe out.
    //         console.log(stdout);
    //         console.log(stderr);
    //         console.log(error);
    //         done(1);
    //       } else {
    //         // Copy executable out.
    //         copyFile(exeOutputPath, outputBaseFile + '.exe');
    //         done(0);
    //       }
    //     });
  };
}
Builds a native app.
@param {!Object} argv Parsed options.
@param {string} tempDir Root temp path.
@param {string} outputBaseFile Base filename for output (without extension).
@param {!Array.<string>} ccFiles A list of input .cc files.
@param {function(number)} done Done callback. 0 for success.