🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Creating a Directory with Autotools During Install

Started by
5 comments, last by Kwizatz 14 years, 11 months ago
I'm having issues with using autotools (automake/autoconf). So what I want to do is create a directory that contains some configuration files during installation. So far I've tried multiple solutions. Using sysconf_DATA in the automake.am file only has the capability to install a single file. That's not necessarily bad but it doesn't recreate the folder structure. Every file is dropped into /usr/local/etc (by default). If you try to do it for a directory, it quits. I also tried adding the following in configure.ac: AC_PROG_INSTALL Which should set the $(INSTALL_DATA) variable and then within makefile.am install-data-local: $(INSTALL_DATA) $(srcdir)/conf/config.file $(prefix)/etc/conf/config.file That complains as well with an error. Basically saying that there is no option to process '-c' or something similar. Looking at the actual Makefile that's created, the install program (and install-sh script) uses the -c option so I'm wondering if I'm not initializing a variable somewhere or if I'm just missing something over all. I've looked around on Google quite a bit and read the Automake/Autoconf books to see if I could find something but the automake and autoconf tools all say to use sysconf_DATA but don't mention anything about the fact that sysconf_DATA doesn't appear to support creating directories and looking at Google, it appears the syntax that i have for the install-data-local route should work but it's not. Any help would be appreciated.
Advertisement
I think the usual is to keep system wide configuration in etc (autotools will always respect the installation prefix, which is by default /usr/local, use --prefix= on configure to change it), for per user configuration, the application itself when first run creates a folder at ~/.[appname] and creates and keeps track of its contents, I suggest you do this instead.

That said, there is a way to add a hook target that gets run post instalation where you could call mkdir or whatever you need, its just not a very good idea to do so.

you just have to add a "install-exec-hook" to one of the Makefile.am files like so:

install-exec-hook:      mkdir [path]


Again, I really advice against this, but it can be done that way.

Now, if what you wanted was to have a sub directory under etc, say /usr/local/etc/progname, I think you can overwrite the _etcdir for that program in Makefile.am (I've done it with include, never with etc):

bin_PROGRAMS = prognameprogname_etcdir = $(etcdir)/progname...
I should clarify. The files I'm installing should be in /etc or /use/local/etc. I'm not trying to get away from the common behavior for installing ackages. I'm not sure just renaming the etc variable would solve the problem because I will also have subdilders containing specific information as well so it would look like:

/etc/progname
/etc/progname/progname.conf
/etc/progname/folder1/
/etc/progname/folder1/file1

etc...

I'm wondering if there is something better than install hook as that would mean I would have to do a mkdir and a copy which could overwrite modified (non-default) config files. I tried the manual way under install-local-data and it complained saying it didn't know what mkdir was...
It seems using hooks is the only way to do that, check these pages from the manual, specially The two parts of Install and Extending Installation, the hook you really want is install-data-local, as you found out, however, note that it should be more like this:

install-data-local: $(srcdir)/conf/config.file $(srcdir)/conf/sub1/config.file        mkdir $(sysconfdir)/conf        cp $(srcdir)/conf/config.file $(sysconfdir)/conf        mkdir $(sysconfdir)/conf/sub1        cp $(srcdir)/conf/sub1/config.file $(sysconfdir)/conf/sub1etc...


The tabs are important.

The format for the make targets is

target_name: target_requisite1 target_requisite2        command        command        command        ...


the "target requisites" can be files or other targets.
Do the tabs have to be a minimum number of spaces? So right now I have:

In Makefile.am

install-data-local: $(srcdir)/etc/prog/prog.conf   mkdir /etc/prog   cp $(srcdir)/etc/prog/prog.conf /etc/prog


Where when I reconfigure (autoreconf -ifv) the scripts, run configure, make, make install, I still get an error (although different than the one before). It's saying there is no rule to make the target $(srcdir)/etc/prog/prog.conf. Do I have to define $(srcdir)/etc/prog/prog.conf as a separate target as well meaning I would have to do that for everything single conf file that needs to get copied over? Which that doesn't make sense.

For example with making a regular program you can do:

prog: main.c   gcc prog main.c


Which is exactly what you described. So I would assume that would work for the install-data-local as well.

Also, I saw that documentation and was working through that last week trying to get it to work. Still was having issues so thought I was missing something within the docs.

Btw...thanks for all the help so far.
I played around with it a bit more and figured out the issue. I've got everything working now. Thanks a ton.
No problem, glad you managed to figure it out.

This topic is closed to new replies.

Advertisement