So I wrote a program, and it has an icon I made. After reading about the filesystem hierchy I understand it belongs in /usr/shared/MYPROGRAM/ICON.png for example. My question is, how do I reference this file in my program. For portablility I can't assume it's there in every linux distro can I? And even arch may change this one day if the standards change. So what's the correct way to write the path to my icon in my code? I bet hard coding it isn't the correct way to go.
The "configure" script usually does this with --prefix=/usr. Programs can also check multiple dirs starting with ~/.local/share to see if the user made custom changes (doesn't apply for an icon, but still).
The "configure" script usually does this with --prefix=/usr
I just learned how to do this myself, by using GNU autotools. Holy cow is it confusing, but I think it was well worth learning. It was kind of neat, I've used "./configure; make; make install" a million times, but now I know how to actually setup a project to use those files myself.
There are other options (like cmake I think), but if you'd like help setting up GNU autotools for your project I could help.
UPDATE: This information is now posted in the wiki here: https://wiki.archlinux.org/index.php/GNU_Build_System
If you have any useful links to get people started, please include them in your post.
Sure, here is the information I used to learn GNU autotools.
I started with the Wikipedia article:
I then read through the history of why autotools was created, and learned a bit about the programming language M4:
I read as many tutorials and introductions and online books that I could find. I summarized what I learned into this (I wrote a GNU autotools HOWTO file just for me ):
Autotools uses a big long chain of applications and configuration files to help you build your project. It all begins with two files: configure.ac and Makefile.am. The configure.ac file is used by the application autoconf. This file tells autoconf about what is needed to build your application; things like the name of the application and what compiler and libraries to use. Only one configure.ac file is needed, and it goes in the root directory of your source code tree. The Makefile.am file is used by the application automake. The Makefile.am file tells automake how to build (or simply what to do with) the files that are in the directory. Each directory will have its own Makefile.am file, including the root directory. In summary: configure.ac -> autoconf Makefile.am -> automake Did you notice that the file extension for the autoconf file is AC and that the file extension for the automake file is AM? Cute, right? Now, what do you put in those files? The Makefile.am file is relatively simple. Here is an example of a project directory structure: / /src /src/resources.c /src/resources.h /src/theapp.c /src/theapp.h You would need two Makefile.am files: /Makefile.am ------------ SUBDIRS = src /src/Makefile.am ---------------- bin_PROGRAMS = theapp theapp_SOURCES = resources.c theapp.c Good news! As for the configure.ac file, autotools can help you create it. In the root directory of your project run the program autoscan. The autoscan program will look at your files and create a simple file called configure.scan for you to start with. autoscan -> configure.scan Just rename configure.scan to configure.ac. Edit the configure.ac file. There are some nice easy to understand placeholders for you to fill in, such as "FULL-PACKAGE-NAME" and "VERSION". [TODO HOW TO FILL IN Makefile.am] [TODO HOW TO FILL IN configure.ac] Now that you've prepared the configuration files it's time to let autotools to do some automating. Run "autoreconf --install" to run the autotools scripts. The "--install" command will install any missing files for you, such as the NEWS and README files.
See e.g. datadir.
brebs is totally correct. You can see an example of how I used "datadir" in my other Makefile.am file. If you want to, checkout the source code to my project and look at every configure.ac (1 file) and Makefile.am (6 files) file.
Last edited by drcouzelis (2016-06-03 20:05:45)
That is some nice information drcouzelis! I'm going to bookmark it and read it all later.