Install data directory tree with massive number of files using automake

前端 未结 3 1179
一向
一向 2021-02-07 10:17

I have a data directory which I would like automake to generate install and uninstall targets for. Essentially, I just want to copy this directory verbatim to the DATA director

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 10:59

    I've found that installing hundreds of files separately makes for a tormentingly long invocation of make install. I had a similar case where I wanted to install hundreds of files, preserving the directory structure, and I did not want to change my Makefile.am every time a file was added to or removed from the collection.

    I included a LZMA archive of the files in my distribution, and made automake rules like so:

    GIANTARCHIVE = My_big_archive.tar.lz
    
    dist_pkgdata_DATA = $(GIANTARCHIVE)
    
    install-data-hook:
        cd $(DESTDIR)$(pkgdatadir); \
        cat $(GIANTARCHIVE) | unlzma | $(TAR) --list > uninstall_manifest.txt; \
        cat $(GIANTARCHIVE) | unlzma | $(TAR) --no-same-owner --extract; \
        rm --force $(GIANTARCHIVE); \
        cat uninstall_manifest.txt | sed --expression='s/^\|$$/"/g' | xargs chmod a=rX,u+w
    
    uninstall-local:
        cd $(DESTDIR)$(pkgdatadir); \
        cat uninstall_manifest.txt | sed --expression='s/ /\\ /g' | xargs rm --force; \
        rm --force uninstall_manifest.txt
    

    This way, automake installs My_big_archive.tar.lz in the $(pkgdata) directory, and extracts it there, making a list of all the files that were in it, so it can uninstall them later. This also runs much faster than listing each file as an install target, even if you were to autogenerate that list.

提交回复
热议问题