Mikhail
Mikhail

Reputation: 9007

Getting `make install` to source your bash_completion

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

Upvotes: 3

Views: 594

Answers (2)

ndim
ndim

Reputation: 37827

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.

Upvotes: 3

Foo Bah
Foo Bah

Reputation: 26271

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

Upvotes: 2

Related Questions