Mac / Linux cross-development

Introduction
Mac has always been the default alternative to Wintel systems. In the past, the Mac OS has been a fairly unique entity, without too much in common with the other OSes around, like Windows or the Unix variants. Cross-platform work has always been a bit more convoluted.
With the advent of the latest incarnation of the Mac OSX, or Darwin, we've got an alternative that is very comfortable for Linux geeks. Since Darwin is based on BSD Unix, we now have the possibility of using POSIX compliant applications on the Mac. This article will cover using Linux apps on a Mac, and some of the issues in running Mac apps on Linux. We'll also take a look at using the Mac as a development environment, developing applications that will end up on Linux.
Running Linux Code on Mac OSX
Apple provides a package called Xcode on their developer site. This packages gives you the tools you need to compile programs on the Mac. This includes a nice graphical IDE and lots of examples for developing your own applications for OSX. But that is not the only thing you can do. Xcode is based on the GNU toolset, providing tools like gcc, libtool, make, etc. This means that using Xcode, most command line applications can be compiled and run on the Mac. So our simple little hello world program

   #include <stdio.h>
   #include <stdlib.h>
   int main (int argc, char **argv) {
      printf("Hello World\n");
   }
compiles fine with gcc, giving us an executable which prints out "Hello World" on the command line. Basically, anything that is POSIX compliant should compile and run with no issues.
The process of getting graphical programs to run can be a bit more involved. Mac OSX does provide an X11 server, and all of the standard development libraries that you would need for a purely X11 application, like Xlib. However, none of the other standard libraries, like gtk or Qt, are available by default. You are responsible for getting them downloaded, compiled and installed on your system yourself. In this sense, it's a lot like the Linux From Scratch project. This works fairly well, but you do have to pick the correct configuration options, and collect all of the required dependencies. However, there's no reason why you need to go through this much pain. There are two projects in active development which provide some form of package management for GNU software, Fink and MacPorts. Using these, getting and installing GNU software is made as easy as most Linux distro.
The Fink project started in 2001. Fink is based on the Debian package management system. This means that you can use the Debian package tools like dpkg, dselect and apt-get. This makes it familiar for users of Debian-based distros, like Debian or Ubuntu. Once the base installation is done, you can start to install packages. If you like a text based manager, you can use dselect . If you like a graphical manager instead, you can use the command
sudo apt-get install synaptic
to get synaptic
 Using these applications, we can install many of the packages that we are used to in Linux. The package count, as of the writing of this article, is 10872. Not all packages are available as a binary install using these tools. For this class of packages, fink will install them directly from source, compiling and installing on your Mac. So, for example, if you wanted to install gramps and get some genealogy done, you would simply execute
sudo fink install gramps
Even installing from source, fink deals well with the dependency issues since it is still based on the Debian package management system.
The Mac Ports project started in 2002. This project decided to model itself after the BSD port packaging system. This means that you use the command port to manage the packages on your system. Once you have done the base install, you can install other software packages by simply running the command
sudo port install stellarium
There are several graphical interfaces available, as well, such as Porticus. However, they tend to be independent projects, as opposed to the Debian tools available in Fink. As such, their development cycle and behavior tend to be a bit more erratic and unstable then the older and more mature Debian tools. But still, they may be exactly what your are looking for if you prefer a graphical interface. Like the Fink project, it has both binary packages and source packages available. There are 5829 packages available in the Mac Ports project, and it is growing constantly.
Both projects provide the user with access to the full wealth of open source applications that has been available to Linux users, and the number of packages available continues to grow. This further blurs the line between what makes an OS. If the only difference between Mac OSX and, say Debian, is the kernel and maybe the GUI, are they effectively the same OS? I won't pretend to have an answer, but I think that we may have to start opening our ideas of what constitutes an OS.
Once you have one, or both, of these projects installed (they can peacefully coexist on your system) you will have all of the tools necessary to do your own code development. I have used anjuta
 on my MacBook to develop some small Gnome applications. These compile and run equally well on my MacBook, and my netbook running Ubuntu. While there isn't binary compatibility between OSX and Linux, with source compatibility we can essentially run the same code on both machines.
Running Mac OSX on Linux
This is not as easy as running Linux on Mac OSX. The real stumbling block is the graphical interface in the Mac OS. This is the area where Apple have been very secretive and proprietary. The graphical interface is based on a software technology called Quartz. While the kernel and most of the command line tools have been released as open source software, Quartz is still very closed. As of the writing of this article, I could not find any references to a reverse-engineered open source replacement for Quartz. So the only option available is running OSX inside a virtual machine. While this is not technically running Mac applications on Linux, it does provide the ability of running OSX on a Linux box.
Conclusion
Using the links and information in this article, user who straddle the Linux / Mac divide can narrow that gap a considerable amount. With projects like Fink and MacPorts, Linux users have access to the full spread of GNU and other open source software. As well, the Mac makes a good development environment, allowing a user to develop code that will run on both Linux and OSX. Hopefully, you will explore the possibilities and shrink the divide a little more.
Links
  • http://developer.apple.com
  • http://www.opensource.apple.com
  • http://www.finkproject.org
  • http://www.macports.org






















No comments:

Post a Comment