views:

67

answers:

2

I understand that when installing a C++ command line program on Linux/UNIX, it is customary instead of leaving it in its original directory, to move it to a directory that is already on the path, so I have a make install entry:

mv ayane /usr/local/bin

Looking a bit further ahead, I'm going to end up with a directory or two full of configuration, data and script files, which the program needs to read, some at startup, some later on demand, and in some cases subsequently modify and save again.

This leads to the question of how the program can know where its data files are located. Looking in /bin on my Ubuntu Linux virtual machine, it seems to live up to its name in containing only binary files, so the data files are not typically placed in the same directory as the program.

What's the usual solution for putting data files in a location that can be known to the program?

+5  A: 

There are some filesystem standards, reading up on FHS or something like that (note that there are different approaches to filesystem layout).

Basically, you put your executable binaries into $prefix/bin/, per-host configuration goes into $prefix/etc/, per-user into user's home directory, arch-independent static data into $prefix/share, arch-dependent data and libraries into $prefix/lib and the mutable data normally goes into /var/lib/.

It's better to have this stuff configurable both at compile-time and runtime. And it's also customary not to write Makefiles with install targets by hand, you may want to look at the autotools suite or similar (a matter of taste).

Michael Krelin - hacker
It makes more sense to put data into $prefix/share/<program> and $prefix/lib/<program>. And if there's more than one configuration file: /etc/<program>
PiedPiper
PiedPiper, right, when I refer to `$prefix/lib` and `$prefix/share` I did not imply that the files should necessarily be immediate descendants of the said directories.
Michael Krelin - hacker
+2  A: 

You should look at the File System Hierarchy standard.

In brief, if you program needs system-wide files, then config should go in /etc. Resources, such as scripts and image files go in /usr/share. Runtime data goes in /var/run.

Per-user files live in the user's home directory, of course.

alex tingle