1

I have a directory structure as follows:

.
├── one
│   ├── one_one
│   │   └── one_one_one
│   │       ├── Makefile
│   │       └── one_one_oneTest.cpp
│   └── one_two
│       ├── Makefile
│       └── one_twoTest.cpp
├── three
│   ├── Makefile
│   └── threeTest.cpp
└── two
    └── two_one
        ├── Makefile
        └── two_oneTest.cpp

I want to run the make command where ever I find the Makefile. So, I have written a shell script as follows.

#!/bin/bash
find . -type f -name Makefile -exec make \;

But it gives error saying make: *** No targets specified and no makefile found. Stop.

If I just run find . -type f -name Makefile, I get

./two/two_one/Makefile
./three/Makefile
./one/one_two/Makefile
./one/one_one/one_one_one/Makefile

which is the correct output I expected.

If I run the Makefile using make command, it runs properly, so I think the Makefile is correct. What can be wrong with the shell script?

Just for reference, one of my Makefiles is as follows:

all: TestTwoOne

TestTwoOne: two_oneTest.cpp
    g++ two_oneTest.cpp -o TestTwoOne

1 Answer 1

4

Your "current directory" is not being changed to the appropriate subdirectories for running the make. Do this instead:

find . -type f -name Makefile -execdir make \;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.