Extend the makefile to generate a library and docu

2020-03-30 05:42发布

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 makefile which is:

CC=gcc
CFLAGS=-g -Wall
DEPS = tree.h
OBJ = main.o tree.o 

%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

tree: $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS)

clean:
    rm -f *.o tree

Now I want to make it generate a library not only an object file for the binary trees functions and afterwards to generate the documentation of doxygen inside the makefile. Any help would be helpful.

2条回答
SAY GOODBYE
2楼-- · 2020-03-30 06:15

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.

查看更多
够拽才男人
3楼-- · 2020-03-30 06:39

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.

查看更多
登录 后发表回答