GNU make with many target directories

后端 未结 4 811
长情又很酷
长情又很酷 2021-02-10 17:02

I have to integrate the generation of many HTML files in an existing Makefile. The problem is that the HTML files need to reside in many different directories. My i

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 17:44

    The best solution I found so far is to generate an implicit rule per target directory via foreach-eval-call, as explained in the GNU make manual. I have no idea how this scales to a few thousand target directories, but we will see...

    If you have a better solution, please post it!

    Here is the code:

    rootdir  = /home/user/project/doc
    HPC      = /usr/local/bin/hpc
    
    html = $(rootdir)/build/doc/2009/06/01/some.html \
           $(rootdir)/build/doc/2009/06/02/some.html
    
    targetdirs = $(rootdir)/build/doc/2009/06/01 \
                 $(rootdir)/build/doc/2009/06/02
    
    define generateHtml
     $(1)/%.html: %.st
        -mkdir -p $(1)
        $(HPC) -o $$@ $$<
    endef   
    
    $(foreach targetdir, $(targetdirs), $(eval $(call generateHtml, $(targetdir))))
    
    .PHONY: all
    all: $(html)
    

提交回复
热议问题