0

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

Steve Schnepp
  • 4,620
  • 5
  • 39
  • 54

2 Answers2

2

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
Sagar Sakre
  • 2,336
  • 22
  • 31
1
#!/bin/bash  

HERE=$PWD

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

MFILE=$PWD/Makefile

cd $HERE
make -f $MFILE
Beta
  • 96,650
  • 16
  • 149
  • 150