views:

89

answers:

3

I am relatively new to programming, and have built a few working C++ commandline programs with Xcode in Mac OS X (no dependencies on Mac-only libraries or APIs). My question is:

What is the standard way of packaging and distributing the source code (and possibly compiled binaries)? i.e. Almost all Linux programs seemed to be distributed that a user simply needs to run ./configure && make && make install from the source directory.

Thank you.

+2  A: 

It depends on what operating system you are targetting. Providing a source code archive that supports "./configure" followed by "make" followed by "sudo make install" is pretty typical. However, if you want to distribute your package, then the following are some alternative ways to distribute your package:

  • Ubuntu: provide an apt-get repository for your program so it can be installed via "sudo apt-get install".
  • Mac OS X: create and submit a "port" to MacPorts so that it can be installed via "sudo port install".
  • RedHat/Fedora: provide a package that can be downloaded and installed with "yum".

Many other UNIX variants have other package managers for which providing an appropriate package is ideal. If you are distributing a binary to Mac OS X users, it is also nice to provide a self-contained DMG disk image containing the fully built application or library framework or a *.mpkg or *.pkg installer.

For Debian-based OSs, providing a *.deb package is a good alternative to an apt-get repository. For Redhat/Fedora, providing a *.rpm package is a good alternative to supporting an install via yum.

I should point out that you really only need to provide your package using the simple "./configure", "make", and "sudo make install" mechanism. The fans of the various package managers can provide a convenient package of your source code... that is not necessarily your responsibility... although you can certainly encourage the process to happen sooner on your own.

EDIT
I see that you've asked how to achieve the "./configure", "make", and "sudo make install" behavior. This has traditionally been achieved using the GNU Autotools. However, I strongly recommend that you avoid them as they are quite messy and tricky to use. Instead, I would recommend you use CMake. I already have two project templates in C++ that use CMake and which provide the "./configure", "make", and "sudo make install" behavior. Those templates are: C++ Project Template and C++ Library Project Template. Alternatively, if you already have a Makefile, you can add a target named "install" that does the appropriate installation; however, doing that in a portable and manner is quite tricky. Using CMake+CPack (as I've done) is simpler.

Michael Aaron Safyan
+2  A: 

If your code is destined for developers only, the standard ./configure && make && make install is just fine. If your code is destined for end users, recall that the GCC toolchain is installed with the OS X Developer Tools. All users have these available on the OS X install DVD, but most won't have it installed and it's a lot to ask that they do so just for your code. The preferred deployment option for OS X is a compiled binary .app bundle that can be drag 'n dropped into the user's /Applications directory. If your app is command-line only, that would require writing a GUI wrapper so that it can be launched via double-click (there are several such wrappers out there as open source projects). To begin, you will probably want to take a look at Apple's Unix Porting Guide.

In between options include developing a MacPorts (based on the BSD ports tree and the officially-sanctioned Unix package manager for OS X )port of your code and submitting it for inclusion in the MacPorts repository or similarly for Fink (based on deb packages and, I think , somewhat falling out of favor).

Barry Wark
penyuan
Barry Wark
A: 

Found some tutorials that answered my question:

Learning the GNU development tools

the GNU build and configure system

Autotools Tutorial

Thanks again for your suggestions!

penyuan