Extend the makefile to generate a library and documentation with doxygen

前端 未结 2 1295
悲&欢浪女
悲&欢浪女 2021-01-15 22:27

I have implemented a binary tree program which includes the tree.c with the functions, the tree.h with the declarations of them and a main.c for testing. Also, I have a mak

相关标签:
2条回答
  • 2021-01-15 23:04

    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.

    0 讨论(0)
  • 2021-01-15 23:07

    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.

    0 讨论(0)
提交回复
热议问题