Reputation: 69
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?
Upvotes: 2
Views: 12715
Reputation: 579
If the question is how to make sure that make
(as opposed to make docs
) also rebuilds your documentation:
Make a docs
target that is either phony or has all source and header files listed as dependencies.
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)
Upvotes: 1
Reputation: 51
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.
Upvotes: 3
Reputation: 113
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
.
Upvotes: 1