Make cpplint does not run

I’m not expert on Makefiles, and I was hoping that someone during all Stan years would have gained lot of experience. Before making the pull request, here’s what I would use (it now also gives more informative error message), but I could test this only in Ubuntu

# Old distros have python to default to Python2
PYTHON2 ?= python
# Check version, because new distros have python to default to Python3
PYTHON_VERSION = $(shell $(PYTHON2) -c "print(__import__('sys').version.split(' ' )[0].split('.')[0])")
ifneq ($(PYTHON_VERSION),2)
  # Check if python2 is installed with name python2
  PYTHON2 = python2
  PYTHON_VERSION = $(shell $(PYTHON2) -c "print(__import__('sys').version.split(' ' )[0].split('.')[0])")
  ifneq ($(PYTHON_VERSION),2)
    $(error Python2 required by cpplint, but not found. See 'make help')
  endif
endif

.PHONY: cpplint
cpplint:
	@$(PYTHON2) $(CPPLINT)/cpplint.py --output=vs7 --counting=detailed --root=src --extension=hpp,cpp --filter=-runtime/indentation_namespace,-readability/namespace,-legal/copyright,-whitespace/indent,-runtime/reference $(shell find src/stan -name '*.hpp' -o -name '*.cpp')
1 Like

I’ve gained a lot of experience, but more importantly, found out how not to use make.

That’s a neat solution!

I’d be inclined to not have that much complexity and just put up the error message if the PYTHON2 variable isn’t correct. The reason I say that might interact poorly under at least these conditions:

  • secondary expansion of the makefile
  • this will overwrite make/local if it’s pointing at the wrong PYTHON2 variable. I don’t think that’s good practice

Some things that will help: for the PYTHON_VERSION line using := will only evaluate it once.

Thanks @syclik , I made a pull request taking into account your comments.