Make: only build something if the source's md5 checksum was changed

后端 未结 3 1630
执念已碎
执念已碎 2020-12-25 15:28

Is it possible to tell make to only build a target if it\'s sources md5 checksum has changed (instead of the edit time)?

I\'m using make to

相关标签:
3条回答
  • 2020-12-25 16:00

    I found 3 ways: From simply

    • Using temporary md5-files over an
    • elegant but unreadable hack to
    • patching GNU Make yourself

    (from patchy but simple to clean but hard to realize)

    0 讨论(0)
  • 2020-12-25 16:03

    No, this is not supported by Make — as you've found out, support for this feature is one of the reasons why tools like Scons exist.

    I found a manual recipe for GNU make, though. Maybe you can use that as a work around.

    0 讨论(0)
  • 2020-12-25 16:05

    Maybe my scons latex and org-mode recipe helps you:

    ## I need a couple of special builders for my projects
    # the $SOURCE replacement only uses the first source file. $SOURCES gives all.
    # specifying all source files makes it possible to rerun the build if a single source file changed.
    orgexportpdf = 'emacs --batch --visit "$SOURCE" --funcall org-export-as-pdf'
    pyxplot = 'pyxplot $SOURCE'
    # pdflatex is quite dirty. I directly clean up after it with rm.
    pdflatex = 'pdflatex $SOURCE -o $TARGET; rm -f  *_flymake* flymake* *.log *.out *.toc *.aux *.snm *.nav *.vrb'
    
    # build the PhD thesis from emacs org-mode.
    Command("doktorarbeit.pdf", "doktorarbeit.org",
            orgexportpdf)
    
    # create plots
    Command(["images/comp-t3-s07-tem-boas.png", 
             "images/comp-t3-s07-tem-bona.png"], 
            ["nee-comp.pyx", 
             "nee-comp.txt"],
            pyxplot)
    
    # build my sink.pdf
    Command("sink.pdf", 
            ["sink.tex", 
             "images/comp-t3-s07-tem-boas.png", 
             "images/comp-t3-s07-tem-bona.png", 
             "images/bona-marble.png", 
             "images/boas-marble.png"],
            pdflatex)
    
    # My editors leave tempfiles around. I want them gone after a build clean. This is not yet supported!
    tempfiles = Glob('*~') + Glob('#*#') + Glob('*.bak')
    # using this here would run the cleaning on every run.
    #Command("clean", [], Delete(tempfiles))
    

    It is the counterpart for my Makefile:

    all: doktorarbeit.pdf sink.pdf
    
    sink.pdf : sink.tex images/comp-t3-s07-tem-boas.png images/comp-t3-s07-tem-bona.png images/bona-marble.png images/boas-marble.png
        pdflatex sink.tex
        rm -f  *_flymake* flymake* *.log *.out *.toc *.aux *.snm *.nav *.vrb # kill litter
    
    comp-t3-s07-tem-boas.png comp-t3-s07-tem-bona.png : nee-comp.pyx nee-comp.txt
        pyxplot nee-comp.pyx
    
    # http://www.reddit.com/r/emacs/comments/dy9yt/anyone_know_of_a_script_that_i_can_feed_an/
    # http://blog.nguyenvq.com/2010/10/30/bash-batch-script-to-convert-org-mode-file-to-html/comment-page-1/#comment-27013
    doktorarbeit.pdf : doktorarbeit.org
        emacs --batch --visit "doktorarbeit.org" --funcall org-export-as-pdf
    
    # this is not what clean is intended to do, but I do it anyway.
    clean : 
        rm -f \#* *~ *.bak # kill editor backups
    
    # alternatively run scons. Should I switch to SCons, just put this in all :)
    sconsrun : scons
        python scons/bootstrap.py -Q
    
    scons : 
        hg clone https://bitbucket.org/ArneBab/scons
    
    0 讨论(0)
提交回复
热议问题