Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Manage Cross-Platform Projects with the make Utility : Page 2

Make is a powerful program maintenance utility that has been deployed by our colleagues in the UNIX world to automate the build process for decades. Learn how to use the concepts behind this versatile tool in the .NET world to integrate CLR compliant languages and more.


advertisement
Using make with Visual Studio .NET
Although the command line tool provided with Visual Studio is ample for many projects, its integration with Visual Studio is, at best, minimal. You are given the option to map three core actions within the GUI environment to commands by using the Project Properties page, as shown in Figure 1.

 
Figure 1: Mapping Visual Studio GUI Actions to Build Commands

  • Build: corresponds to Build Project in the Build menu. The action should result in creating the target file entered in the Output box.
  • Clean: triggered when you choose Clean Project from the Build menu, resulting in the removal of all changes produced by Build.
  • Rebuild: is equivalent to a clean followed by a build. It handles the to Rebuild Project command in the Build menu.
What if you receive a make project that you want to port to Visual Studio? The short answer: there is no general way. Although make can use any program to produce the target you require, Visual Studio is a static environment, so there may not always be a suitable transformation. However, you can use the following rules of thumb:
  • Each executable produced by make corresponds to a separate project in Visual Studio. You can mimic dependencies between executables by using the Project Dependencies dialog box.
  • Supporting entities, such as automatic documentation generators or database creation scripts, are good matches for the Pre-Build, Pre-Link, and Post-Build steps in a Visual C++ project.
  • Any set of rules that cannot be translated, because they require a third party utility or they may effect the course of the build process, can be kept in a separate make project.



Can Your Visual Studio Do That?
A significant limitation of Visual Studio is its inability to handle more than one language in a single project. This is because of the way VB and C# compilers are designed;although both compilers produce IL binaries, their output is limited to standalone executables and libraries, rather than object modules that can later be consolidated into an executable. Consequently, Visual Studio has no built-in mechanism to mix multiple CLR languages into a single executable.

 
Figure 2: Creating Your Project

Another limitation of Visual Studio is that it does not support modules at all (generated by the /target:module option in VB and C# compilers). However, with the help of make, you can bypass both of these shortcomings.

Say you have a project, sample.exe that consists of three source files in three different languages: C#, VB, and IL assembly. With the standard mechanisms of Visual Studio .NET, it is not possible to manage such a diverse project. But by using the make utility and doing a little bit of homework, you can use the VS.NET development environment to deal with this exotic project.

Start by creating a new project. Visual Studio supports make only within C++ projects, so your only recourse is to create a new C++ project. Name your project " sample," and click on Finish.

 
Figure 3: Project Settings

Next, fill in your application settings as shown. As mentioned earlier, you have to provide handlers for three distinct cases: Build, rebuild, and clean. Fill in boxes as in Figure 3.

  • Build: nmake Debug\sample.exe
  • Output: Debug\sample.exe
  • Clean: nmake clean
  • Rebuild: nmake clean Debug\sample.exe

Add the source files to the project by right clicking on the Source Files folder in Solution Explorer, and selecting Add New Item from the menu. In the dialog box, replace <Enter name> with VBClass.vb, and click Open. In the text window that appears, paste in the following code:

Public Class VBClass Public Sub Method System.Console.WriteLine("Hello from VBClass") End Sub End Class

Do the same thing with CSClass.cs:

public class CSClass { public void Method() { System.Console.WriteLine("Hello from CSClass"); } }



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap