1

I would like to run two targets using a makefile but don't know how to specify the targets from the command line.

This is my makefile.

.PHONY: all clean test
PYTHON=python
PYTESTS=pytest

all:
    $(PYTHON) setup.py build_ext --inplace

clean:
    find . -name "*.so" -o -name "*.pyc" -o -name "*.md5" -o -name "*.pyd" | xargs rm -f
    find . -name "*.pyx" -exec ./tools/rm_pyx_c_file.sh {} \;

benchmark_coverage:
    $(PYTESTS) benchmarks --cov=skimage

coverage: test_coverage

test_coverage:
    $(PYTESTS) -o python_functions=test_* skimage --cov=skimage

So, I'm mainly interested in coverage, benchmark_coverage and test_coverage.

When I run the command make coverage, it runs
$(PYTESTS) -o python_functions=test_* skimage --cov=skimage.

When I run make bench_coverage, it runs
$(PYTESTS) benchmarks --cov=skimage.

Now, I want to run both of these together, how do I do this?

Someone suggested me make coverage bench_coverage but it only runs the first command.

Please help.

Thanks

Abhishek Arya
  • 450
  • 4
  • 16

1 Answers1

8

I tried creating the following Makefile:

a:
   echo a

b:
   echo b

and if I run make a b it runs both, so running multiple targets actually is allowed.

Bitwise
  • 7,577
  • 6
  • 33
  • 50
  • 1
    oh, my bad. Thanks @Bitwise. The first command resulted in an error. That's why it didn't run the second one. I changed the order and both of them ran. Can I do something in the case when one command fails? I want the others to run. – Abhishek Arya Aug 07 '18 at 19:09
  • @AbhishekArya see here: https://stackoverflow.com/questions/2670130/make-how-to-continue-after-a-command-fails – Bitwise Aug 07 '18 at 19:11
  • 2
    Used `--keep-going` flag – Abhishek Arya Aug 07 '18 at 19:11
  • tip: this (supplying multiple targets) works with pattern matching (i.e. `%`, and `$@`) with different inputs too. aside, same happened with me too, make encountered a fatal error (i.e. the error log starting with ***) with first target lol – user8395964 Aug 24 '22 at 16:40