4

I would like to apply Gimpel PC-Lint to my source code in an incremental manner using Make. I want it to only run lint against the source file if the source file has changed since the last time lint was run. Is anyone doing this? How are you approaching it?

thetic
  • 174
  • 1
  • 11
lexicalscope
  • 7,158
  • 6
  • 37
  • 57
  • please show us a relevant makefile... make was designed for this, so of course it can be done. – sehe Dec 06 '11 at 12:18
  • my problem is I don't know how to write the make file, as pc-lint doesn't seem to have any output file? – lexicalscope Dec 06 '11 at 12:21
  • create one, artificial if it has to be. There are common patterns to do so. Also, of course pc-lint has output (it would be pretty useless without it) – sehe Dec 06 '11 at 12:23
  • I think it outputs to stdout/stderr and by exit code? Not using a file. Any pointers on where to look for make patterns on how to generate an output file? That would be a good answer for me... – lexicalscope Dec 06 '11 at 12:25

2 Answers2

4

The common pattern is to create output (or create artificial output if there is none).

Edit note that $(LINT) $< > $@ will expand to something like lint test.cpp > test.lint (redirecting output into that file)

E.g.

 %.o: %.cpp | %.lint
      S(CC) -o $@ $(CPPFLAGS) $<

 %.lint: %.cpp
      $(LINT) $< > $@

or for a process without output:

 %.o: %.cpp | %.emailsent
      S(CC) -o $@ $(CPPFLAGS) $<

 %.emailsent: %.cpp
      $(DOEMAIL) $^   # no output from mail sender
      touch $@        # won't be reached DOEMAIL returned error
sehe
  • 374,641
  • 47
  • 450
  • 633
  • For linting a single file you'll want to add the option `-u` for "unit-checkout", so PCLint will know you're not linting a full project. It will then suppress several warnings about unused items or unresolved externals. – Johan Bezem Dec 13 '11 at 08:11
  • "On some presentation I read that PC Lint is more for preventing bugs than analyzing existing code." - I don't agree with this. Preventing bugs is acheived by analyzing code. Practically, I think they mean that tools like ubsan, PVS-Studio, purify, Coverity, do more static analysis enabling factual conclusions rather than diagnostics based on guidelines/heuristics – sehe Jun 18 '15 at 21:45
  • I think Lint is an excellent tool for C. Much like FxCop/Gendarme are for C#/CLR. Don't overuse though. Bad code will still arise if you hit all the green bars for R#, FxCop etc. – sehe Jun 18 '15 at 21:47
1

You could add the lint compilation to your compilation rules whenever gcc (or whatever) is called. This would immediately bring up any issue with the code before testing or using it. On the other hand this would be far too slow on a larger project.

I am usually linting my projects before checking them in. Thus I made a small script where I lint everything that has been checked out. If you have a gentle platform (e.g. svn on a suitable server) this could even be done by the server thus users could work on without having to wait for lint to finish.

Jens
  • 6,173
  • 2
  • 24
  • 43