2

I have written a program in c++ and I would like to generate the executables using a makefile. This works, however I also have some Doxygen style comments in my code, and I want my makefile to automatically generate the HTML page with the documentation. Unfortunately I can't figure out how this should be done correctly. So far the docs part of my makefile looks like:

docs: doxygen ./Doxyfile 

I am guessing I will need to add some extra files, could someone please clarify the procedure for me?

5
  • Could you say more about what the problem is? What is the result of what you've tried so far? Commented Mar 11, 2014 at 22:07
  • @PeterSw - The thing is that I have never done it before, and I'm not sure how to do this. At the moment my code does nothing Commented Mar 15, 2014 at 14:46
  • Does running doxygen ./Doxyfile directly do nothing? What about make docs? Have you tried adding the line PHONY: docs to your Makefile? Commented Mar 15, 2014 at 15:20
  • This is a duplicate of <stackoverflow.com/questions/13777301/…> Commented Jan 25, 2015 at 11:14
  • Isn't it .PHONY: docs (with a period in the beginning?). I think it's only really needed if doxygen is putting its output in a docs/ directory. In that case, make will notice the directory already exists and since there are no dependencies listed, it will not rebuild it. If there is no file or directory called "docs", the target will be rebuilt every time, but I agree it's still cleaner to mark it as phony. Even better would be to list all the source and header files as dependencies instead (so you only rerun doxygen if anything has changed). Commented Oct 17, 2019 at 9:00

3 Answers 3

3

You likely want to add dependencies so the documentation generates when the source changes. The easiest place to do that would be in the build rule for the application. When the sources change and the application needs to be built, then you could use that as a trigger for building the docs:

$(PROGRAM): $(OBJECTS) @echo Building $@ $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS) @echo Updating Docs $@ @doxygen 

I suppose the same could work seperately

DOCS=MyProject_html docs: $(DOCS)/MyProject.html $(DOCS)/MyProject.html: $(PROGRAM) $(OBJECTS) @echo Building Docs @doxygen clean: rm -rf $(PROGRAM) $(OBJECTS) $(DOCS) 

There's like a more automatic way to do the generation, but this should work.

Sign up to request clarification or add additional context in comments.

2 Comments

The documentation generation should depend on the sources not on the objects as it is not necessary to build the objects before generation of the documentation (although it is recommended as in that case the code is already validated by the compiler and thus doxygen gets fo certain valid code). There might be some files source files that are generated during the "compilation" build process, they of course should be added as well.
@albert Agreed, and in addition, you may need to rerun doxygen even though the object files haven't changed, e.g. if you only changed the documentation.
1

My method of generating docs from the make file is:

docs: @doxygen @open doxygen/html/index.html 

You can then get access to it by running make docs.

Comments

1

If the question is how to make sure that make (as opposed to make docs) also rebuilds your documentation:

  1. Make a docs target that is either phony or has all source and header files listed as dependencies.

  2. Make sure your default target (the first one in the makefile) has both docs and your executable as dependencies.

For example

all: hello docs .PHONY: docs docs: @doxygen ./Doxyfile hello: hello.o foo.o ... hello.o: hello.cpp hello.h foo.h ... foo.o: foo.cpp foo.h ... 

Alternative which will only rerun Doxygen if any of its inputs changed (more work to maintain though):

all: hello docs # Doxygen needs to be rerun if the Doxyfile changed, or if any source or # header file with Doxygen comments changed. If all your comments are in # the headers, you don't need to include the .cpp files. docs: hello.cpp hello.h foo.cpp foo.h ./Doxyfile @doxygen ./Doxyfile hello: hello.o foo.o ... hello.o: hello.cpp hello.h foo.h ... foo.o: foo.cpp foo.h ... 

(Make sure to replace the spaces before the build rules by tabs in the actual Makefile)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.