MakefileTips

If you're using a build tool like autoconf, it handles these details for you. But, if you're building your app with a simple Makefile, there are a few ways you can make it easier to package your app.

Debian/Ubuntu use the DESTDIR variable in Makefiles to set a temporary install location for building packages. So, in your install target, anywhere you might use an install path like '/usr/bin/', make sure you put DESTDIR in front like '$(DESTDIR)/usr/bin'. (See http://www.gnu.org/prep/standards/html_node/DESTDIR.html for more details.)

Another useful trick is to use a PREFIX variable for the system install path, instead of literal install paths like /usr, or /usr/local, or /opt/extras.ubuntu.com/appname. You can start your Makefile with something like:

PREFIX ?= /usr
bindir = $(PREFIX)/bin
libdir = $(PREFIX)/lib
datadir = $(PREFIX)/share

And then in the install and uninstall targets, replace literal paths like:

        /usr/bin/myapp

With a path that uses the defined variables:

        $(DESTDIR)$(bindir)/myapp

That way, the debian/rules file can just set the install path once by setting PREFIX:

override_dh_auto_install:
        dh_auto_install -- PREFIX=/opt/extras.ubuntu.com/myapp

AppReviewBoard/Submissions/MakefileTips (last edited 2012-04-02 00:36:41 by allison)