If you use rebarthrough make, you can add this kind of code to your Makefile:
@if [[ -f $@/Makefile ]]; \
then echo 'make -C $@ all' ; \
make -C $@ all ; \
else echo 'cd $@ && rebar get-deps compile && cd ../..' ; \
cd $@ && rebar get-deps compile && cd ../.. ; fi
It checks to see if it has a $@Makefile, decides to use makeor rebar.
This snippet is from erl.mk https://github.com/fenollp/erl-mk/blob/master/erl.mk#L17-L21