installationautotoolsautoconfautomakegit-annex

Using automake with files that may not be present in the source tree


I am transitioning to git-annex for storing data files in my git repo. With git-annex you can clone a repository and exclude the files in the annex until you specifically request them. So, Im trying to create a system in which users can build the src tree without the git-annexed data files being present during the make stage. Currently, we assume the files are present on the users filesystem, so the following snippet of the Makefile.am is sufficient:

foo_DATA=datafile1 datafile2 datafile3

EXTRA_DIST=$(foo_DATA)

However, when using the _DATA primary, an error is generated when the user attempts to make and any of the files in the list are not present. So my question is, is there a way to define the data files so that no error is generated when the data file is not present during make, but behaves exactly as the above code if the files are present during the make install step?

I have tried avoiding the _DATA primary altogether, doing something simple like the follow:

data_files=datafile1 datafile2 datafile3

install:
    test -z $(foodir) || mkdir -p $(foodir)
    install -c -m 644 $(data_files) $(foodir)

But that is rather hackey. Im hardcoding the "install" binary and the permission flags instead of getting them from the configure script. Ide rather just have automake not fail during the make step if the files were not present, but behave as expected in all other circumstances.

TLDR: Can I define a set of files using the _DATA primary that will not error out during make if the file is not present? But also installs exactly as the _DATA primary would if it were present?


Solution

  • Your current approach seems reasonable. I'd write it as an install-data-local hook, though:

    data_files=datafile1 datafile2 datafile3
    
    install-data-local:
        test -z $(foodir) || $(MKDIR_P) $(foodir)
        $(INSTALL_DATA) $(data_files) $(foodir)
    

    MKDIR_P and INSTALL_DATA should be set up for you by automake.

    If you'd rather not do this, the following may work in combination with your first Makefile.am snippet. I've not used git-annex before, so this may be wrong:

    $(foo_DATA) :
            if test ! -e $@; then git annex get $@; fi