3

This is the install part of my Makefile:

install:
    for e in $(EXEC); do \
        sudo cp --remove-destination ${CURDIR}/$$e /usr/local/bin; done
    sudo cp ${CURDIR}/bin/stage2.d /etc/bash_completion.d/stage2
    . /etc/bash_completion

Where "stage2" is the name of my executable.

The last line is what provides the issue. After adding a file into bash_completion.d directory I want to source the bash_completion. But calling source or . yields:

. /etc/bash_completion
/etc/bash_completion: 32: [[: not found
/etc/bash_completion: 38: [[: not found
/etc/bash_completion: 50: Bad substitution
make: *** [install] Error 2
Mikhail
  • 8,692
  • 8
  • 56
  • 82

2 Answers2

3

I see two issues:

  1. Using sudo in a Makefile rule is a bad idea. Avoid that, and call sudo make install instead.
  2. Why would you want to source the bash_completion file in the non-interactive shell which is the make rule? It makes no sense.

As to solving them:

install:
    $(INSTALL) -m 0755 -d $(DESTDIR)$(bindir)
    $(INSTALL) -m 0755 -p $(EXEC) $(DESTDIR)$(bindir)/
    $(INSTALL) -m 0755 -d $(DESTDIR)$(sysconfdir)/bash_completion.d
    $(INSTALL) -m 0644 -p ${CURDIR}/bin/stage2.d $(DESTDIR)$(sysconfdir)/bash_completion.d/stage2

for the make rule part and

sudo make install && . /etc/bash_completion.d/stage2

for the actual running of that command. You will want to document the latter in a README, or in a line which the install: target prints when finished.

ndim
  • 35,870
  • 12
  • 47
  • 57
  • `$(INSTALL)` is the complicated/flexible way commonly used to call `install(1)` from a `Makefile`. Add a line `INSTALL = install` at the beginning of your `Makefile` to provide a default. – ndim Feb 09 '11 at 17:17
2

Make uses /bin/sh by default. you have to force it to use bash since [[ is not supported by normal sh.

gnu make lets you set SHELL variable [in the makefile] to force it to use bash. So you would need to add a line

SHELL=/bin/bash

at the top of your makefile

Foo Bah
  • 25,660
  • 5
  • 55
  • 79
  • in combination with : http://stackoverflow.com/questions/589276/how-can-i-use-bash-syntax-in-makefile-targets – Mikhail Feb 09 '11 at 15:28
  • colon is not necessary. try it out without the colon (in this case both are acceptable) – Foo Bah Feb 09 '11 at 15:30
  • let me be more specific: the := is an immediate evaluation [its processed at that spot] whereas the = is deferred [expansion occurs when it is used -- akin to C macro] – Foo Bah Feb 09 '11 at 15:34
  • Sourcing bash completion stuff into a non-interactive shell still makes no sense. – ndim Feb 09 '11 at 17:18