Author: ankit
Date: 2007-10-15 15:45:39 -0400 (Mon, 15 Oct 2007)
New Revision: 87531

Modified:
   trunk/monodevelop/Extras/MonoDevelop.Autotools/ChangeLog
   
trunk/monodevelop/Extras/MonoDevelop.Autotools/SimpleProjectMakefileHandler.cs
   
trunk/monodevelop/Extras/MonoDevelop.Autotools/templates/Makefile.noauto.project.template
   trunk/monodevelop/Extras/MonoDevelop.Autotools/templates/rules.make
Log:
* SimpleProjectMakefileHandler.cs (Deploy): Add support for emitting
custom commands for simple makefiles.
(EmitCustomCommandTargets): New.
* templates/Makefile.noauto.project.template: Insert calls to *Build targets.
* templates/rules.make: Insert calls to *Clean targets and add empty default
targets for the custom commands.


Modified: trunk/monodevelop/Extras/MonoDevelop.Autotools/ChangeLog
===================================================================
--- trunk/monodevelop/Extras/MonoDevelop.Autotools/ChangeLog    2007-10-15 
18:47:32 UTC (rev 87530)
+++ trunk/monodevelop/Extras/MonoDevelop.Autotools/ChangeLog    2007-10-15 
19:45:39 UTC (rev 87531)
@@ -1,3 +1,12 @@
+2007-10-16  Ankit Jain  <[EMAIL PROTECTED]>
+
+       * SimpleProjectMakefileHandler.cs (Deploy): Add support for emitting
+       custom commands for simple makefiles.
+       (EmitCustomCommandTargets): New.
+       * templates/Makefile.noauto.project.template: Insert calls to *Build 
targets.
+       * templates/rules.make: Insert calls to *Clean targets and add empty 
default
+       targets for the custom commands.
+
 2007-10-12  Mike Krüger <[EMAIL PROTECTED]> 
 
        * SolutionMakefileHandler.cs, SimpleProjectMakefileHandler.cs, 
Handler.cs,

Modified: 
trunk/monodevelop/Extras/MonoDevelop.Autotools/SimpleProjectMakefileHandler.cs
===================================================================
--- 
trunk/monodevelop/Extras/MonoDevelop.Autotools/SimpleProjectMakefileHandler.cs  
    2007-10-15 18:47:32 UTC (rev 87530)
+++ 
trunk/monodevelop/Extras/MonoDevelop.Autotools/SimpleProjectMakefileHandler.cs  
    2007-10-15 19:45:39 UTC (rev 87531)
@@ -63,6 +63,9 @@
                StringBuilder extras;
                StringBuilder datafiles;
 
+               // custom commands
+               StringBuilder customCommands;
+
                public bool CanDeploy (CombineEntry entry, MakefileType type)
                {
                        Project project = entry as Project;
@@ -184,6 +187,8 @@
                                        installDeps = new StringBuilder ();
                                        installDirs = new List<string> ();
 
+                                       customCommands = new StringBuilder ();
+
                                        string programFilesDir = 
ctx.DeployContext.GetDirectory (TargetDirectory.ProgramFiles);
                                        //FIXME:temp
                                        programFilesDir = 
programFilesDir.Replace ("@prefix@", "$(prefix)");
@@ -301,6 +306,18 @@
 
                                        ProcessDeployFilesForConfig 
(deployFiles, project, configSection, ctx);
                                        configSections.Add (configSection);
+
+                                       if (!generateAutotools) {
+                                               EmitCustomCommandTargets 
(config.CustomCommands, project, customCommands, combineConfig.Name,
+                                                               new 
CustomCommandType [] {
+                                                                       
CustomCommandType.BeforeBuild,
+                                                                       
CustomCommandType.AfterBuild,
+                                                                       
CustomCommandType.BeforeClean,
+                                                                       
CustomCommandType.AfterClean}, monitor);
+                                       } else {
+                                               if (config.CustomCommands.Count 
> 0)
+                                                       monitor.ReportWarning 
(GettextCatalog.GetString ("Custom commands are not supported for autotools 
based makefiles. Ignoring Ignoring.."));
+                                       }
                                }
                                ctx.TargetCombine.ActiveConfiguration = 
saveConfiguration;
 
@@ -362,7 +379,6 @@
                                        }
                                }
 
-
                                // Register files generated by the compiler
                                ctx.AddBuiltFile (project.GetOutputFileName ());
                                //FIXME: mdb is not generated for non-DEBUG 
profiles
@@ -386,6 +402,9 @@
                                        uninstallTarget.Append ("\tmake 
post-uninstall-local-hook prefix=$(prefix)\n");
                                }
 
+                               if (!generateAutotools && customCommands.Length 
> 0)
+                                       customCommands.Insert (0, "# Targets 
for Custom commands\n");
+
                                templateEngine.Variables["CONFIG_VARS"] = 
conf_vars.ToString ();
                                templateEngine.Variables["DEPLOY_FILE_VARS"] = 
vars.ToString ();
                                
templateEngine.Variables["COPY_DEPLOY_FILES_VARS"] = 
deployFileCopyVars.ToString();
@@ -402,6 +421,7 @@
                                        
templateEngine.Variables["TEMPLATE_FILES_TARGETS"] = 
templateFilesTargets.ToString();
                                        
templateEngine.Variables["INSTALL_TARGET"] = installTarget.ToString();
                                        
templateEngine.Variables["UNINSTALL_TARGET"] = uninstallTarget.ToString();
+                                       
templateEngine.Variables["CUSTOM_COMMAND_TARGETS"] = customCommands.ToString();
                                }
 
                                // Create project specific makefile
@@ -598,6 +618,65 @@
                        }
                }
 
+               void EmitCustomCommandTargets (CustomCommandCollection 
commands, Project project, StringBuilder builder, string configName, 
CustomCommandType[] types, IProgressMonitor monitor)
+               {
+                       bool warned = false;
+                       configName = configName.ToUpper ();
+                       foreach (CustomCommandType type in types) {
+                               bool targetEmitted = false;
+                               string lastdir = project.BaseDirectory;
+                               for (int i = 0; i < commands.Count; i ++) {
+                                       CustomCommand cmd = commands [i];
+                                       if (cmd.Type != type) {
+                                               if (!warned && Array.IndexOf 
(types, cmd.Type) < 0) {
+                                                       //Warn (only once) if 
unsupported custom command is found,
+                                                       StringBuilder 
types_list = new StringBuilder ();
+                                                       foreach 
(CustomCommandType t in types)
+                                                               
types_list.AppendFormat ("{0}, ", t);
+                                                       monitor.ReportWarning 
(GettextCatalog.GetString (
+                                                               "Custom 
commands of only - {0} - types are supported.", types_list.ToString ()));
+                                                       warned = true;
+                                               }
+                                               continue;
+                                       }
+
+                                       if (!targetEmitted) {
+                                               builder.AppendFormat 
("{0}_{1}:\n", configName, type.ToString ());
+                                               targetEmitted = true;
+                                       }
+
+                                       string dir, exe, args;
+                                       ResolveCustomCommand (project, cmd, out 
dir, out exe, out args);
+                                       builder.AppendFormat ("\t(cd {0} && {1} 
{2})\n", dir, exe, args);
+                               }
+                               if (targetEmitted)
+                                       builder.Append ("\n");
+                       }
+               }
+
+               void ResolveCustomCommand (Project project, CustomCommand cmd, 
out string dir, out string exe, out string args)
+               {
+                       dir = exe = args = null;
+                       string outputname = project.GetOutputFileName();
+                       string [,] customtags = new string [,] {
+                               {"ProjectDir", "$(srcdir)"},
+                               {"TargetName", "$(notdir $(ASSEMBLY))"},
+                               {"TargetDir", "$(BUILD_DIR)"},
+                               {"CombineDir", "$(top_srcdir)"}
+                       };
+
+                       int i = cmd.Command.IndexOf (' ');
+                       if (i == -1) {
+                               exe = cmd.Command;
+                               args = string.Empty;
+                       } else {
+                               exe = cmd.Command.Substring (0, i);
+                               args = StringParserService.Parse 
(cmd.Command.Substring (i + 1), customtags);
+                       }
+
+                       dir = (string.IsNullOrEmpty (cmd.WorkingDir) ? 
"$(srcdir)" : StringParserService.Parse (cmd.WorkingDir, customtags));
+               }
+
                // Get the Project config corresponding to its @parentConfig
                IConfiguration GetProjectConfig (string parentConfig, 
CombineEntry entry)
                {

Modified: 
trunk/monodevelop/Extras/MonoDevelop.Autotools/templates/Makefile.noauto.project.template
===================================================================
--- 
trunk/monodevelop/Extras/MonoDevelop.Autotools/templates/Makefile.noauto.project.template
   2007-10-15 18:47:32 UTC (rev 87530)
+++ 
trunk/monodevelop/Extras/MonoDevelop.Autotools/templates/Makefile.noauto.project.template
   2007-10-15 19:45:39 UTC (rev 87531)
@@ -31,10 +31,14 @@
 $(build_resx_resources) : %.resources: %.resx
        %%RESGEN%% '$<' '$@'
 
+%%CUSTOM_COMMAND_TARGETS%%
+
 $(ASSEMBLY) $(ASSEMBLY_MDB): $(build_sources) $(build_resources) 
$(build_datafiles) $(DLL_REFERENCES) $(PROJECT_REFERENCES) $(build_xamlg_list)
        make pre-all-local-hook prefix=$(prefix)
        mkdir -p $(dir $(ASSEMBLY))
+       make $(CONFIG)_BeforeBuild
        $(ASSEMBLY_COMPILER_COMMAND) $(ASSEMBLY_COMPILER_FLAGS) 
-out:$(ASSEMBLY) -target:$(COMPILE_TARGET) $(build_sources_embed) 
$(build_resources_embed) $(build_references_ref)
+       make $(CONFIG)_AfterBuild
        make post-all-local-hook prefix=$(prefix)
 
 

Modified: trunk/monodevelop/Extras/MonoDevelop.Autotools/templates/rules.make
===================================================================
--- trunk/monodevelop/Extras/MonoDevelop.Autotools/templates/rules.make 
2007-10-15 18:47:32 UTC (rev 87530)
+++ trunk/monodevelop/Extras/MonoDevelop.Autotools/templates/rules.make 
2007-10-15 19:45:39 UTC (rev 87531)
@@ -1,6 +1,8 @@
 clean-local:
        make pre-clean-local-hook
+       make $(CONFIG)_BeforeClean
        -rm -f $(CLEANFILES)
+       make $(CONFIG)_AfterClean
        make post-clean-local-hook
 
 install-local:
@@ -30,3 +32,9 @@
 #      and their *-local variants
 pre-%-hook: ; @:
 post-%-hook: ; @:
+
+#targets for custom commands
+%_BeforeBuild: ; @:
+%_AfterBuild: ; @:
+%_BeforeClean: ; @:
+%_AfterClean: ; @:

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to