Note that there are some explanatory texts on larger screens.

plurals
  1. POAre there good reasons not to exploit '#!/bin/make -f' at the top of a makefile to give an executable makefile?
    primarykey
    data
    text
    <p>Mostly for my amusement, I created a <code>makefile</code> in my <code>$HOME/bin</code> directory called <code>rebuild.mk</code>, and made it executable, and the first lines of the file read:</p> <pre><code>#!/bin/make -f # # Comments on what the makefile is for ... all: ${SCRIPTS} ${LINKS} ... ... </code></pre> <p>I can now type:</p> <pre><code>rebuild.mk </code></pre> <p>and this causes <code>make</code> to execute.</p> <p>What are the reasons for not exploiting this on a permanent basis, other than this:</p> <ul> <li>The makefile is tied to a single directory, so it really isn't appropriate in my main <code>bin</code> directory.</li> </ul> <p>Has anyone ever seen the trick exploited before?</p> <hr> <p>Collecting some comments, and providing a bit more background information.</p> <ol> <li>Norman Ramsey reports that this technique is used in Debian; that is interesting to know. Thank you.</li> <li>I agree that typing 'make' is more idiomatic.</li> <li>However, the scenario (previously unstated) is that my $HOME/bin directory already has a cross-platform main makefile in it that is the primary maintenance tool for the 500+ commands in the directory.</li> <li>However, on one particular machine (only), I wanted to add a makefile for building a special set of tools. So, those tools get a special makefile, which I called <code>rebuild.mk</code> for this question (it has another name on my machine).</li> <li>I do get to save typing '<code>make -f rebuild.mk</code>' by using '<code>rebuild.mk</code>' instead.</li> <li>Fixing the position of the <code>make</code> utility is problematic across platforms.</li> <li>The <code>#!/usr/bin/env make -f</code> technique is likely to work, though I believe the official rules of engagement are that the line must be less than 32 characters and may only have one argument to the command.</li> <li>@dF comments that the technique might prevent you passing arguments to make. That is not a problem on my Solaris machine, at any rate. The three different versions of 'make' I tested (Sun, GNU, mine) all got the extra command line arguments that I type, including options ('-u' on my home-brew version) and targets 'someprogram' and macros CC='cc' WFLAGS=-v (to use a different compiler and cancel the GCC warning flags which the Sun compiler does not understand).</li> </ol> <h3>I would not advocate this as a general technique.</h3> <p>As stated, it was mostly for my amusement. I may keep it for this particular job; it is most unlikely that I'd use it in distributed work. And if I did, I'd supply and apply a '<code>fixin</code>' script to fix the pathname of the interpreter; indeed, I did that already on my machine. That script is a relic from the first edition of the Camel book ('Programming Perl' by Larry Wall).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload