Steve Schnepp
Steve Schnepp

Reputation: 4710

How to launch a make from a sub dir

I have one top level Makefile. The project has several subdirectories of various depths.

How can I launch make from any subdirectory, so it uses the top level Makefile, just like git finds automatically its top-level .git directory ?

Structure :

/
/a/
/b/c
/Makefile
/Readme

Scenario :

/$ make
... Works ...
/b$ make
... Cannot find makefile

I'd like the 2nd scenario to do the same as the first one.

Hint, it would ideally serve as :make rule in vi, but shouldn't be vi-specific

Update: the / is not the root dir, only the root of the project, the real intent is to mimic git

Upvotes: 0

Views: 126

Answers (2)

Sagar Sakre
Sagar Sakre

Reputation: 2426

Hint by Beta would work. create a alias

alias make=`sh /home/makecrawl.sh`

where makecrawl.sh would look like

#! /bin/bash
while ! [ -f makefile ] &&  [$PWD != "/" ]
do
cd ..
done
make

Upvotes: 2

Beta
Beta

Reputation: 99154

#!/bin/bash  

HERE=$PWD

while ! [ -f Makefile ] && [ $PWD != "/" ]
do
 cd ..
done

MFILE=$PWD/Makefile

cd $HERE
make -f $MFILE

Upvotes: 1

Related Questions