You are not logged in.

#1 2013-04-06 20:50:33

The.Jackal
Member
Registered: 2013-03-30
Posts: 5

How does a program "know" where /usr/shared is?

Hi,
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.

Offline

#2 2013-04-06 20:58:58

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: How does a program "know" where /usr/shared is?

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).

Offline

#3 2013-04-06 23:11:39

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: How does a program "know" where /usr/shared is?

Procyon wrote:

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. smile

Offline

#4 2013-04-06 23:37:23

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: How does a program "know" where /usr/shared is?

@drcouzelis
If you have any useful links to get people started, please include them in your post.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#5 2013-04-07 00:05:01

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: How does a program "know" where /usr/shared is?

See e.g. datadir.

Offline

#6 2013-04-07 05:07:16

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: How does a program "know" where /usr/shared is?

UPDATE
UPDATE: This information is now posted in the wiki here: https://wiki.archlinux.org/index.php/GNU_Build_System
UPDATE

Xyne wrote:

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:

https://en.wikipedia.org/wiki/GNU_autotools

I then read through the history of why autotools was created, and learned a bit about the programming language M4:

http://www.freesoftwaremagazine.com/boo … ke_libtool

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 tongue):

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.

The project I used autotools on is Kwest Kingdom. You can see my configure.ac file and Makefile.am file.

brebs wrote:

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)

Offline

#7 2013-04-07 09:44:21

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: How does a program "know" where /usr/shared is?

That is some nice information drcouzelis! I'm going to bookmark it and read it all later.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

Board footer

Powered by FluxBB