Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling makefile in a subdirectory

I have a source code folder structure as follows

src
 |-tests
 |-abc

I have a makefile in src which has a target called tests. tests has its own makefile which it uses to compile the source code into binary.(multiple targets).All that is managed by the Makefile in the test directory.

My src make file has the following targets.

all: main tests

main: $(DEPENDENCY IN SRC and ABC)
   command

tests: ??
     make -C tests

What dependancy can I specify for tests target in the main Makefile.. I don't want this Makefile to be aware of the source files in the tests folder.

like image 813
liv2hak Avatar asked Apr 23 '26 19:04

liv2hak


1 Answers

all: main tests

main: $(DEPENDENCY IN SRC and ABC)
   command

tests:
     $(MAKE) -C tests

this will unconditionally invoke make of tests on its private subdirectory. Note that usage of special $(MAKE) variable helps to propagate command-line parameters and reduces overhead.

like image 122
Alex Cohn Avatar answered Apr 28 '26 09:04

Alex Cohn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!