Susanna Huhtanen
ihmis.suski@gmail.com 2012

# Autotools and Icons

        In this part of the guide well construct the autotools and custom icons needed for weather application to be a seamless part of your desktop. To write and run all the code examples yourself, you need an editor to write code in, Terminal and GNOME 3 or higher installed into your computer. In this guide we we'll go through the following parts:

           Autotools
          Custom icons for your application

# Autotools and necessary files

Having more than one file in your folder makes using autotools a bit tricky. You need the .desktop file, autogen.sh, Makefile.am, configure.ac and as a new file: myapp.sh.in file. Hacking the autotools file is a complicated field. More information can be found in many different sources, the wikipedia article provides a good overwiev on the subject.

weatherapp.desktop

weatherapp.sh.in

Makefile.am

configure.ac

autogen.sh

weatherapp.desktop

[Desktop Entry] Version=1.0 Encoding=UTF-8 Name=Weather app Comment=Weather showing application Exec=weatherapp.sh Icon=application-default-icon Terminal=false Type=Application StartupNotify=true Categories=GNOME;GTK;Utility;

The thing to notice in this file is that the Exec line will make this .desktop file work only after running all the other makefiles. Weatherapp.sh is a small shell script created with the weatherapp.sh.in.

weatherapp.sh.in

#!/bin/sh export GJS_PATH=@bindir@ gjs @bindir@/weatherapp.js

This file is a template to the file Makefile will do to be run from .desktop.

Makefile.am

# The actual runnable program is set to the SCRIPTS primitive. Prefix bin_ tells where to copy this bin_SCRIPTS = weatherapp.js geonames.js weatherapp.sh # List of files to be distributed EXTRA_DIST= \ $(bin_SCRIPTS) \ $(private_icons) \ $(NULL)

CLEANFILES =

# The desktop files desktopdir = $(datadir)/applications desktop_DATA =weatherapp.desktop

# convenience command for doing Makefile variable substitutions in non-Makefile # files (scripts, service files, etc.) do_subst = sed -e 's|@abs_top_srcdir[@]|$(abs_top_srcdir)|g' \ -e 's|@abs_top_builddir[@]|$(abs_top_builddir)|g' \ -e 's|@localedir[@]|$(localedir)|g' \ -e 's|@bindir[@]|$(bindir)|g' \ -e 's|@libexecdir[@]|$(libexecdir)|g' \ -e 's|@pkglibdir[@]|$(pkglibdir)|g' \ -e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \ -e 's|@have_libnotify[@]|$(HAVE_LIBNOTIFY)|g' \ -e 's|@have_libsoup[@]|$(HAVE_LIBSOUP)|g' \ -e 's|@have_cheese[@]|$(HAVE_CHEESE)|g'

weatherapp.sh: weatherapp.sh.in $(AM_V_GEN) $(do_subst) $< > $@ chmod +x $@

CLEANFILES += weatherapp.sh EXTRA_DIST += weatherapp.sh.in

#the application icon appicondir=$(datadir)/icons/hicolor/scalable/apps appicon_DATA=weather-icon.svg

#icons in the application NULL =

private_icons = \ weather-clear.svg \ weather-few-clouds.svg \ weather-fog.svg \ weather-icon.svg \ weather-overcast.svg \ weather-showers.svg \ weather-showers-scattered.svg \ weather-snow.svg \ $(NULL)

install-icons: for icon in $(private_icons); do \ mkdir -p $(DESTDIR)$(pkgdatadir)/icons/; \ $(INSTALL_DATA) $(srcdir)/$$icon $(DESTDIR)$(pkgdatadir)/icons/; \ done

install-data-local: install-icons

This needs a bit more explaining. Compared to the HelloWorld Makefile.am this has changed quite a bit. Lets go through all the new blocks:

bin_scripts are the files that are needed to run your application. In thin case they are the first two files are the program itself and the third is the script that launches the application.

EXTRA_DIST are the files that are to be distributed

do_subst block is bits and pieces that need to be where they are

after the comment #icons in the application there are all the icons that are used by the program. For them to be useful you need to install the icons in correct places and that is done byt the install-icons: bit

configure.ac

dnl This file is processed by autoconf to create a configure script AC_INIT([Weather App], 1.0) AM_INIT_AUTOMAKE([1.10 no-define foreign]) AC_CONFIG_FILES(Makefile) AC_OUTPUT

autohen.sh

#!/bin/sh # This will run autoconf, automake, etc. for us autoreconf --force --install

# Custom icons for your application

When thinking about custom icons a good rule of thumb is: do you expect to see that icon used elsewhere or is it private to your app? If the first (e.g. the icons in the desktop file that are shown by the shell) then you need /usr/share/hicolor, otherwise (e.g. the weather icons of your app) /usr/share/$application/bla/bla

Using autotools you have to make some changes to your .desktop and Makefile.am files. In the desktop file you change the Icon's name Icon=weather-icon. In the Makefile.am file you add these two lines to the end of your application #the application icon

appicondir=$(datadir)/icons/hicolor/scalable/apps

appicon_DATA=weather-icon.svg