8

How can I tell Automake to install arbitrary data files in places I want?

I have some files I need to put in specific places, e.g. "datafile1", in my project, needs to be copied to "/usr/MyProduct/flash_memory".

  • "/usr/MyProduct/flash_memory" is an absolute path that I can't change.
  • "datafile1" is a binary data file that is not "built" by make, but just needs to be copied by make install.
  • I can't bear on make dist. It needs to be copied by make install (its a long explanation, so, please just take this into account).
  • I rather not use install-hook, but prefer to have a more elegant approach (if possible).
usr1234567
  • 21,601
  • 16
  • 108
  • 128
j4x
  • 3,595
  • 3
  • 33
  • 64

1 Answers1

16

Do not use full paths in your Makefile.am. Ever. You can tell automake to put the datafile1 in $(datadir) which will expand to $(prefix)/share/MyProduct, or you can define flash_DIR to expand to $(prefix)/MyProduct/flash_memory and put the files there, but the end user must be allowed to set $(prefix) either to /usr or to something else. What you want to do in Makefile.am is:

flashdir = $(prefix)/$(PACKAGE)/flash_memory
flash_DATA = datafile1

(It would probably be more appropriate to use $(prefix)/@PACKAGE@/flash_memory, since PACKAGE probably should not be modifiable at make time, but I don't think this is terribly important.)

Then, when you are a user, run make install with prefix set to /usr. If you try to use an absolute path in the Makefile.am, it will disallow staged installations (ie setting DESTDIR), will restrict user flexibility, and is the wrong thing to do. The main point is that the package maintainer does not get to choose the final location; that is a decision for the user.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • As I sayd before, "`/usr/MyProduct/flash_memory`" is an absolute path that I can't change. Its not my choice. Ignoring that, I tried "`confdir=... conf_DATA=datafile1`" but it didn't work. Any hint? Thanks – j4x May 23 '12 at 14:44
  • 4
    @fljx When you say "I cannot change", do you mean "I" as the user installing the package, or do you mean "I" when you are the package maintainer. If the former, my answer works. If you mean the latter, then stop using automake; you are abusing the tool. – William Pursell May 23 '12 at 14:48
  • I mean "I, the worker that obeys my boss". Anyway, I changed `confdir` to "`confdir = $(prefix)/usr/awmg/flash/`" and it works. The absolute path does not. I just want to understand why, now... Thanks again! – j4x May 23 '12 at 14:53
  • 1
    you should always respect $(prefix) and $(DESTDIR). it makes packaging so much easier (e.g. someone wants to create debian/ubuntu packages one day...) and the default will (basically) satisfy your boss. just create a wrapper scripts that runs configure with "--prefix=/usr" and tell them that this is the way to configure your program rather than calling configure directly – umläute Jun 05 '12 at 12:31
  • @umlaeute - Thank you for pointing that out, but DESTDIR should not be prepended to flashdir since automake prepends DESTDIR in the `install-flashDATA` rule. Is there something in my solution that requires a DESTDIR to be prepended? – William Pursell Jun 05 '12 at 12:39
  • no that's fine; my point was mainly that one shouldn't be too clever when trying to force installation targets (and respecting DESTDIR is somehow contradictory with "absolute paths"). even though somebody might urge you to do something in a certain way, you can still do it in a standard-confirmant way that allows the specific case (and make a wrapper that makes the specific case the default) – umläute Jun 05 '12 at 13:06
  • `$(datadir)` expands to `$(prefix)/share`, while `$(pkgdatadir)` expands to `$(prefix)/share/$(PACKAGE)`. If you need stuff in a subdirectory with the name of your package, then you should use `pkgdata_DATA = myfile` – lanoxx Apr 09 '13 at 21:57
  • *"It would probably be more appropriate to use `$(prefix)/@PACKAGE@/flash_memory`..."* - I believe Automake uses `@PACKAGE_TARNAME@`. Or it does so for `docdir = ${datarootdir}/doc/${PACKAGE_TARNAME}`. – jww Nov 07 '17 at 02:11