void CreateConfigureDotAC(Solution solution, string defaultConf, IProgressMonitor monitor, AutotoolsContext context) { monitor.Log.WriteLine(GettextCatalog.GetString("Creating configure.ac")); TemplateEngine templateEngine = new TemplateEngine(); templateEngine.Variables["WARNING"] = "Warning: This is an automatically generated file, do not edit!"; // add solution configuration options StringBuilder config_options = new StringBuilder(); foreach (SolutionConfiguration config in solution.Configurations) { string name = context.EscapeAndUpperConfigName(config.Id).ToLower(); string def = config.Id == defaultConf ? "YES" : "NO"; string ac_var = "enable_" + name; // test to see if a configuration was enabled config_options.AppendFormat("AC_ARG_ENABLE({0},\n", name); config_options.AppendFormat(" AC_HELP_STRING([--enable-{0}],\n", name); config_options.AppendFormat(" [Use '{0}' Configuration [default={1}]]),\n", context.EscapeAndUpperConfigName(config.Id), def); config_options.AppendFormat(" {0}=yes, {0}=no)\n", ac_var); config_options.AppendFormat("AM_CONDITIONAL({0}, test x${1} = xyes)\n", ac_var.ToUpper(), ac_var); // if yes, populate some vars config_options.AppendFormat("if test \"x${0}\" = \"xyes\" ; then\n", ac_var); // AppendConfigVariables ( combine, config.Name, config_options ); config_options.Append(" CONFIG_REQUESTED=\"yes\"\nfi\n"); } // if no configuration was specified, set to default (if there is a default) if (defaultConf != null) { config_options.Append("if test -z \"$CONFIG_REQUESTED\" ; then\n"); // AppendConfigVariables ( combine, defaultConf, config_options ); config_options.AppendFormat(" AM_CONDITIONAL(ENABLE_{0}, true)\n", context.EscapeAndUpperConfigName(defaultConf)); config_options.AppendFormat("\tenable_{0}=yes\n", context.EscapeAndUpperConfigName(defaultConf).ToLower()); config_options.Append("fi\n"); } // Add specific user switch if (switchs != null) { foreach (Switch s in switchs) { string name = s.SwitchName.ToLowerInvariant(); config_options.AppendLine(string.Format(@"AC_ARG_ENABLE({0}, AC_HELP_STRING([--enable-{0}], [{1}]), enable_{2}=yes, enable_{2}=no) AM_CONDITIONAL(ENABLE_{3}, test x$enable_{2} = xyes)", name, s.HelpStr, name.Replace('-', '_'), name.Replace('-', '_').ToUpperInvariant())); } } templateEngine.Variables ["CONFIG_OPTIONS"] = config_options.ToString(); // build compiler checks StringBuilder compiler_checks = new StringBuilder(); foreach (string compiler in context.GetCommandChecks()) { compiler_checks.AppendFormat("AC_PATH_PROG({0}, {1}, no)\n", compiler.ToUpper(), compiler); compiler_checks.AppendFormat("if test \"x${0}\" = \"xno\"; then\n", compiler.ToUpper()); compiler_checks.AppendFormat(" AC_MSG_ERROR([{0} Not found])\n", compiler); compiler_checks.Append("fi\n"); } templateEngine.Variables["COMPILER_CHECKS"] = compiler_checks.ToString(); // build list of *.in files StringBuilder configFiles = new StringBuilder(); string tmpmf = null; foreach (string makefile in context.GetAutoConfFiles()) { tmpmf = FileService.AbsoluteToRelativePath(solution_dir, makefile); if (PlatformID.Unix != Environment.OSVersion.Platform) { tmpmf = tmpmf.Replace("\\", "/"); } AutotoolsContext.CheckSpaces(tmpmf); configFiles.Append(FileService.NormalizeRelativePath(tmpmf)); configFiles.Append("\n"); } templateEngine.Variables["CONFIG_FILES"] = configFiles.ToString(); // build list of pkgconfig checks we must make StringWriter packageChecks = new StringWriter(); packageChecks.WriteLine("dnl package checks, common for all configs"); Set <SystemPackage> commonPackages = context.GetCommonRequiredPackages(); foreach (SystemPackage pkg in commonPackages) { packageChecks.WriteLine("PKG_CHECK_MODULES([{0}], [{1}])", AutotoolsContext.GetPkgConfigVariable(pkg.Name), pkg.Name); } packageChecks.WriteLine("\ndnl package checks, per config"); foreach (SolutionConfiguration config in solution.Configurations) { Set <SystemPackage> pkgs = context.GetRequiredPackages(config.Id, true); if (pkgs == null || pkgs.Count == 0) { continue; } packageChecks.WriteLine(@"if test ""x$enable_{0}"" = ""xyes""; then", context.EscapeAndUpperConfigName(config.Id).ToLower()); foreach (SystemPackage pkg in pkgs) { packageChecks.WriteLine("\tPKG_CHECK_MODULES([{0}], [{1}])", AutotoolsContext.GetPkgConfigVariable(pkg.Name), pkg.Name); } packageChecks.WriteLine("fi"); } templateEngine.Variables["PACKAGE_CHECKS"] = packageChecks.ToString(); templateEngine.Variables["SOLUTION_NAME"] = solution_name; templateEngine.Variables["VERSION"] = solution_version; string configureFileName = Path.Combine(solution_dir, "configure.ac"); StreamWriter writer = new StreamWriter(configureFileName); Stream stream = context.GetTemplateStream("configure.ac.template"); StreamReader reader = new StreamReader(stream); templateEngine.Process(reader, writer); reader.Close(); writer.Close(); context.AddGeneratedFile(configureFileName); }
void CreateConfigureScript(Solution solution, string defaultConf, AutotoolsContext ctx, IProgressMonitor monitor) { monitor.Log.WriteLine(GettextCatalog.GetString("Creating configure script")); TemplateEngine templateEngine = new TemplateEngine(); // Build list of configurations StringBuilder sbConfig = new StringBuilder(); sbConfig.Append("\""); foreach (string config in ctx.GetConfigurations()) { sbConfig.AppendFormat(" {0}", config); } sbConfig.Append("\""); // Build list of packages required by all configs string commonPackages = String.Format("common_packages=\"{0}\"", GetPackageListFromSet(context.GetCommonRequiredPackages())); // Build list of packages required per config StringBuilder requiredPackages = new StringBuilder(); foreach (SolutionConfiguration config in solution.Configurations) { Set <SystemPackage> pkgs = context.GetRequiredPackages(config.Id, true); if (pkgs == null || pkgs.Count == 0) { continue; } if (requiredPackages.Length > 0) { requiredPackages.Append("\n"); } requiredPackages.AppendFormat("required_packages_{0}=\"{1}\"", context.EscapeAndUpperConfigName(config.Id), GetPackageListFromSet(pkgs)); } templateEngine.Variables ["VERSION"] = solution_version; templateEngine.Variables ["PACKAGE"] = solution.Name.ToLower(); templateEngine.Variables ["DEFAULT_CONFIG"] = ctx.EscapeAndUpperConfigName(defaultConf); templateEngine.Variables ["CONFIGURATIONS"] = sbConfig.ToString(); templateEngine.Variables ["COMMON_PACKAGES"] = commonPackages.ToString(); templateEngine.Variables ["REQUIRED_PACKAGES"] = requiredPackages.ToString(); Stream stream = context.GetTemplateStream("configure.template"); string filename = Path.Combine(solution_dir, "configure"); StreamReader reader = new StreamReader(stream); StreamWriter writer = new StreamWriter(filename); templateEngine.Process(reader, writer); reader.Close(); writer.Close(); ctx.AddGeneratedFile(filename); if (PlatformID.Unix == Environment.OSVersion.Platform) { Syscall.chmod(filename, FilePermissions.S_IXOTH | FilePermissions.S_IROTH | FilePermissions.S_IRWXU | FilePermissions.S_IRWXG); } }
void CreateConfigureDotAC (Solution solution, string defaultConf, IProgressMonitor monitor, AutotoolsContext context) { monitor.Log.WriteLine ( GettextCatalog.GetString ("Creating configure.ac") ); TemplateEngine templateEngine = new TemplateEngine(); templateEngine.Variables["WARNING"] = "Warning: This is an automatically generated file, do not edit!"; // add solution configuration options StringBuilder config_options = new StringBuilder (); foreach ( SolutionConfiguration config in solution.Configurations ) { string name = context.EscapeAndUpperConfigName (config.Id).ToLower(); string def = config.Id == defaultConf ? "YES" : "NO"; string ac_var = "enable_" + name; // test to see if a configuration was enabled config_options.AppendFormat ( "AC_ARG_ENABLE({0},\n", name ); config_options.AppendFormat (" AC_HELP_STRING([--enable-{0}],\n", name ); config_options.AppendFormat (" [Use '{0}' Configuration [default={1}]]),\n", context.EscapeAndUpperConfigName (config.Id), def ); config_options.AppendFormat ( " {0}=yes, {0}=no)\n", ac_var ); config_options.AppendFormat ( "AM_CONDITIONAL({0}, test x${1} = xyes)\n", ac_var.ToUpper(), ac_var ); // if yes, populate some vars config_options.AppendFormat ( "if test \"x${0}\" = \"xyes\" ; then\n", ac_var ); // AppendConfigVariables ( combine, config.Name, config_options ); config_options.Append ( " CONFIG_REQUESTED=\"yes\"\nfi\n" ); } // if no configuration was specified, set to default (if there is a default) if (defaultConf != null) { config_options.Append ( "if test -z \"$CONFIG_REQUESTED\" ; then\n" ); // AppendConfigVariables ( combine, defaultConf, config_options ); config_options.AppendFormat ( " AM_CONDITIONAL(ENABLE_{0}, true)\n", context.EscapeAndUpperConfigName (defaultConf)); config_options.AppendFormat ("\tenable_{0}=yes\n", context.EscapeAndUpperConfigName (defaultConf).ToLower ()); config_options.Append ("fi\n"); } // Add specific user switch if (switchs != null) { foreach (Switch s in switchs) { string name = s.SwitchName.ToLowerInvariant (); config_options.AppendLine (string.Format (@"AC_ARG_ENABLE({0}, AC_HELP_STRING([--enable-{0}], [{1}]), enable_{2}=yes, enable_{2}=no) AM_CONDITIONAL(ENABLE_{3}, test x$enable_{2} = xyes)", name, s.HelpStr, name.Replace ('-', '_'), name.Replace ('-', '_').ToUpperInvariant ())); } } templateEngine.Variables ["CONFIG_OPTIONS"] = config_options.ToString(); // build compiler checks StringBuilder compiler_checks = new StringBuilder(); foreach (string compiler in context.GetCommandChecks () ) { compiler_checks.AppendFormat ("AC_PATH_PROG({0}, {1}, no)\n", compiler.ToUpper(), compiler); compiler_checks.AppendFormat ("if test \"x${0}\" = \"xno\"; then\n", compiler.ToUpper() ); compiler_checks.AppendFormat (" AC_MSG_ERROR([{0} Not found])\n", compiler ); compiler_checks.Append("fi\n"); } templateEngine.Variables["COMPILER_CHECKS"] = compiler_checks.ToString(); // build list of *.in files StringBuilder configFiles = new StringBuilder(); string tmpmf = null; foreach (string makefile in context.GetAutoConfFiles () ) { tmpmf = FileService.AbsoluteToRelativePath ( solution_dir, makefile ); if (PlatformID.Unix != Environment.OSVersion.Platform) tmpmf = tmpmf.Replace("\\","/"); AutotoolsContext.CheckSpaces (tmpmf); configFiles.Append(FileService.NormalizeRelativePath (tmpmf)); configFiles.Append("\n"); } templateEngine.Variables["CONFIG_FILES"] = configFiles.ToString(); // build list of pkgconfig checks we must make StringWriter packageChecks = new StringWriter(); packageChecks.WriteLine ("dnl package checks, common for all configs"); Set<SystemPackage> commonPackages = context.GetCommonRequiredPackages (); foreach (SystemPackage pkg in commonPackages) packageChecks.WriteLine("PKG_CHECK_MODULES([{0}], [{1}])", AutotoolsContext.GetPkgConfigVariable (pkg.Name), pkg.Name); packageChecks.WriteLine ("\ndnl package checks, per config"); foreach (SolutionConfiguration config in solution.Configurations) { Set<SystemPackage> pkgs = context.GetRequiredPackages (config.Id, true); if (pkgs == null || pkgs.Count == 0) continue; packageChecks.WriteLine (@"if test ""x$enable_{0}"" = ""xyes""; then", context.EscapeAndUpperConfigName (config.Id).ToLower()); foreach (SystemPackage pkg in pkgs) packageChecks.WriteLine("\tPKG_CHECK_MODULES([{0}], [{1}])", AutotoolsContext.GetPkgConfigVariable (pkg.Name), pkg.Name); packageChecks.WriteLine ("fi"); } templateEngine.Variables["PACKAGE_CHECKS"] = packageChecks.ToString(); templateEngine.Variables["SOLUTION_NAME"] = solution_name; templateEngine.Variables["VERSION"] = solution_version; string configureFileName = Path.Combine (solution_dir, "configure.ac"); StreamWriter writer = new StreamWriter(configureFileName); Stream stream = context.GetTemplateStream ("configure.ac.template"); StreamReader reader = new StreamReader(stream); templateEngine.Process(reader, writer); reader.Close(); writer.Close(); context.AddGeneratedFile (configureFileName); }