'cd' in debian/rules

Christopher Halse Rogers chalserogers at gmail.com
Mon Mar 31 03:43:32 BST 2008

On 3/31/08, Matt G. <mattismyname at gmail.com> wrote:
> Hello all,
>   I'm up to the point of running debuild but have run into trouble.  The
>   normal build sequence for this library is "./configure; cd src; make".
>   So, I've edited the debian/rules file that was autogenerated by
>   dh_make to add the "cd src" command to the build-stamp target right
>   before the line containing $(MAKE).  I also added a 'cd src' command
>   for the clean target.  However, the cd command does not seem to get
>   executed for build-stamp: or clean:.
I replied in #ubuntu-motu, but for posterity's sake...
This is because each tab-indented line of a Makefile is interpreted in
a separate shell.  So make encounters "\t cd src", promptly spawns a
shell and runs "cd src" in that shell.  The current working directory
of _that shell_ is now ./src, but it has successfully completed that
command, and so exits.  Make then goes on to run the next line
"\t$(MAKE)" in a new shell, which has inherited the Makefile's current
working directory, and so fails.

You'll notice in your build output:
>   matt at Aluminumy:~/Packaging/libgfx/libgfx-debhelper-1.1.0$ debuild
>   fakeroot debian/rules clean
>   dh_testdir
>   dh_testroot
>   rm -f build-stamp
>   # Add here commands to clean up after the build process.
>   # -/usr/bin/make distclean
>   cd src
>   /usr/bin/make clean
>   make[1]: Entering directory
>  `/home/matt/Packaging/libgfx/libgfx-debhelper-1.1.0'
>   make[1]: *** No rule to make target `clean'.  Stop.
>   make[1]: Leaving directory `/home/matt/Packaging/libgfx/libgfx-debhelper-1.1.0'
>   make: [clean] Error 2 (ignored)
>   cd ..
>   rm -f config.sub config.guess
>   dh_clean
>   dpkg-source -b libgfx-debhelper-1.1.0
>   dpkg-source: warning: source directory './libgfx-debhelper-1.1.0' is
>   not <sourcepackage>-<upstreamversion> 'libgfx-1.1.0'
>   dpkg-source: warning: .orig directory name libgfx-debhelper-1.1.0.orig
>   is not <package>-<upstreamversion> (wanted libgfx-1.1.0.orig)
>   dpkg-source: building libgfx using existing libgfx_1.1.0.orig.tar.gz
>   dpkg-source: building libgfx in libgfx_1.1.0-0ubuntu0.diff.gz
>   dpkg-source: warning: executable mode 0755 of 'config.status' will not
>   be represented in diff
>   dpkg-source: building libgfx in libgfx_1.1.0-0ubuntu0.dsc
>   debian/rules build
>   dh_testdir
>   # Add here commands to compile the package.
>   cd src
>   /usr/bin/make
>   make[1]: Entering directory
>  `/home/matt/Packaging/libgfx/libgfx-debhelper-1.1.0'
>   make[1]: *** No targets specified and no makefile found.  Stop.
>   make[1]: Leaving directory `/home/matt/Packaging/libgfx/libgfx-debhelper-1.1.0'
>   make: *** [build-stamp] Error 2
>   debuild: fatal error at line 1247:
>   debian/rules build failed
that your cd commands get run.

Probably what you actually want to do is pass -C src/ to make (so
$(MAKE) -C src), which tells it to start in the src/ directory.  Or
ask the upstream developers why the build system is strange. :)

Makefiles can be a bit strange when you start.  It's very important to
remember that they are _not_ shell scripts!

More information about the Ubuntu-motu mailing list