Browse DevX
Sign up for e-mail newsletters from DevX


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

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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Do the same thing for Sample.il. If you are not familiar with IL, dont worry: it will seem cryptic at first, but this code snippet is really simple. It merely creates instances of CSClass and VBClass, and then calls their methods:

// Current assembly .assembly Sample { } // We use the following modules in Main .module extern CSClass.netmodule .file CSClass.netmodule .module extern VBClass.netmodule .file VBClass.netmodule // CLR will start here at .entrypoint .method public static void Main() cil managed { .entrypoint .maxstack 1 // Declare local variables .locals init([0] class [.module CSClass.netmodule]CSClass cs, [1] class [.module VBClass.netmodule]VBClass vb) // Create new instance of CSClass newobj instance void [.module CSClass.netmodule]CSClass::.ctor() stloc.0 ldloc.0 // Call its Method callvirt instance void [.module CSClass.netmodule]CSClass::Method() // Create new instance of VBClass newobj instance void [.module VBClass.netmodule]VBClass::.ctor() stloc.1 ldloc.1 // Call its Method callvirt instance void [.module VBClass.netmodule]VBClass::Method() ret }

Now that your source files are ready, you can work on your make file. Ironically, there is no straightforward way to add a makefile to a make project, so you have to follow these steps:
  • Right click on the sample project in Solution Explorer and select Add Existing Item.
  • In the Add Existing Item dialog box, change Files of Type to All Files (*.*).
  • Create a new text file by right clicking on the file listbox, and clicking on New Text Document.
  • Rename New Text Document.txt as makefile.
  • Double-click on makefile.

Figure 4: Project Settings

Now your Solution Explorer should resemble Figure 4. Double-click on makefile to edit its contents inside the development environment.

You need only a few rules: One should teach make how to generate a .netmodule file from a .vb file. You'll need a similar rule for .cs files, like the following:

# # VB and C# modules used by sample.exe # Debug\VBClass.netmodule: VBClass.vb vbc /debug /t:module /out:Debug\VBClass.netmodule VBClass.vb Debug\CSClass.netmodule: CSClass.cs csc /debug /t:module /out:Debug\CSClass.netmodule CSClass.cs

Finally, the executable is dependent on the two modules you previously defined, and to the IL file Sample.il:

# # Compile Sample.il into sample.exe # Debug\sample.exe: Debug\VBClass.netmodule Debug\CSClass.netmodule Sample.il ilasm /debug /out:Debug\sample.exe Sample.il

As stated previously, Visual Studio needs to know three commands to integrate its environment to make: Build, rebuild, and clean. The rules thus far provide the means to build and rebuild the solution. Cleaning, on the other hand, is easily implemented by deleting everything under the Debug directory:

# # Clean up for rebuild # clean: del /q Debug\*

Save all four files and choose Build Solution from the Build menu. Visual Studio will call make to generate your executable.

You can even debug, set breakpoints, and step through IL, C#, and VB code at the same time. To do that, go to Project Properties, and change the Debugger Type from Auto to Managed Only, as pictured in Figure 5. When you hit F11, the instruction pointer should be on the line where the C# class is created. Three lines later, when Method is called, you'll be stepping into C# code, and six lines later into VB code.

Figure 5: Changing Debugger Type to Managed Only

Caveat Emptor
It is apparent from these tricks and workarounds that Microsoft support for this utility is minimal. You may already have noticed that IntelliSense, which is one of the primary reasons developers use Visual Studio as opposed to a text editor, does not work with make based projects.

Perhaps the reason for this lies in the different approaches taken by the Microsoft and UNIX camps. Historically, Microsofts approach has always been product-centric. Developers are provided with the best tools to produce what they want to produce, whether it's a Windows executable in Visual Basic or an ATL DLL in Visual C++. On the other hand, the philosophy in the UNIX camp is process-centric. Developers are provided with utilities that perform the simplest tasks best, but it is up to them to use such tools effectively. The assumption is that the ingenuity of developers will provide the best usage patterns.

Hasmet Akgun is an independent consultant based in New York City. When not helping his clients deploy and coexist .NET framework solutions with legacy technologies, he enjoys writing articles for the developer community and dreams of adopting another cat. Reach him by e-mail at h.akgun@acm.org.
Comment and Contribute






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



Thanks for your registration, follow us on our social networks to keep up-to-date