Extend the makefile to generate a library and documentation with doxygen

允我心安 提交于 2019-12-01 11:55:51

I know that my answer comes in a bit late, but i hope someone will benefit from this.

I have a makefile that generates Doxygen doc. You have to twist Doxygen a tiny bit Create the Doxygen setup file that fits Your need, then open that in an editor and remove the lines containg the following two settings (they will be added by the make file later)

INPUT
FILE_PATTERNS

add this line

@INCLUDE = doxyfile.inc

Save this file under a different name I use Doxyfile.mk

in You makefile You need a list of sources and the directories where they are located example

SRCS =  $(OBJS:.o=.c)
SRCDIRS = ./src
SRCDIRS += ./other_src

Now You can put this rule in the Makefile, it will create the file doxyfile.inc that contains the settings You removed from Doxyfile.mk.

.PHONY: all clean distclean doxy

# If makefile changes, maybe the list of sources has changed, so update doxygens list
doxyfile.inc: Makefile.mk
        echo INPUT         =  $(SRCDIRS) > doxyfile.inc
        echo FILE_PATTERNS =  *.h $(SRCS) >> doxyfile.inc

doxy: doxyfile.inc $(SRCS) 
        doxygen.exe doxyfile.mk

Bonus: If run from inside an IDE like Eclipse the errors that Doxygen spits out becomes clickable and will jump to the bad comment.

Well, I don't really know the syntax for the doxygen command, so I'll make a generic answer:

in your Makefile, each

term: [dep]
    action

is a target.

So if you add something like:

doc: $(OBJ)
    doxygen with-correct-options

You will be able to generate the documentation using:

make doc

(doc being here the name of the target)

Now, if you add:

all: tree doc
    @echo "Generating program and doc."

you will have the program and the documentation generated with simply invoking

make

In the end, there is an additional statment your Makefile could have use of: .PHONY. It's "A way to mark one of many targets as not directly producing files, and ensure their execution even if a file having the same name as the target exists". In other terms, it's to make sure doc, clean or all will always be executed even if files named doc, clean or all exist.

Its syntax is the following:

.PHONY: all clean doc

And is usually put at the end of the Makefile.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!