質問

I am looking to write a script to go into each child directory (not recursively) and run a make file to create a binary. One way to do this is to change directories and run make for each folder but it's not very elegant and can be error prone if additional folders and files are added.

I have had a little success delving into child dirs with the following:

find -maxdepth 2 -type f -print -exec make {} . \;

I get the error for each dir which states the following:

make: Nothing to be done for reduc211/makefile.

Anyone got any ideas as to what I can change? Any help would be greatly appreciated!

Many thanks and happy coding.

役に立ちましたか?

解決

make reduc211/makefile doesn't run the named makefile; it looks for a Makefile using make's lookup rules and tries to make the target reduc211/makefile. What you want is something like

find -maxdepth 2 -name 'Makefile' -print -execdir make \;

This runs the make command in every directory where a file named Makefile is found.

If you have differently named makefiles, for example each is of the form Makefile.something, you could try

find -maxdepth 2 -name 'Makefile.*' -print -execdir make -f \{}\ \;

to run make using the specific Makefiles found by find.

他のヒント

Something like this?

for dir in *; do
    if [ -d "$dir" ]; then
        (cd "$dir" && make)
    fi
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top