Blame platform-demos/pt_BR/weatherAutotools.js.page

Packit 1470ea
Packit 1470ea
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" type="topic" style="task" id="weatherAutotools.js" xml:lang="pt-BR">
Packit 1470ea
  <info>
Packit 1470ea
    <link type="guide" xref="weatherApp.js#main" group="#last"/>
Packit 1470ea
    <revision version="0.1" date="2012-03-09" status="stub"/>
Packit 1470ea
Packit 1470ea
    <credit type="author copyright">
Packit 1470ea
      <name>Susanna Huhtanen</name>
Packit 1470ea
      <email its:translate="no">ihmis.suski@gmail.com</email>
Packit 1470ea
      <years>2012</years>
Packit 1470ea
    </credit>
Packit 1470ea
Packit 1470ea
    <desc/>
Packit 1470ea
  
Packit 1470ea
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
Packit 1470ea
      <mal:name>Rafael Ferreira</mal:name>
Packit 1470ea
      <mal:email>rafael.f.f1@gmail.com</mal:email>
Packit 1470ea
      <mal:years>2013</mal:years>
Packit 1470ea
    </mal:credit>
Packit 1470ea
  </info>
Packit 1470ea
Packit 1470ea
  <title>Autotools and Icons</title>
Packit 1470ea
  <synopsis>
Packit 1470ea
    

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:

Packit 1470ea
Packit 1470ea
    <list>
Packit 1470ea
      <item>

<link xref="#autotools"> Autotools</link>

</item>
Packit 1470ea
      <item>

<link xref="#icons">Custom icons for your application</link>

</item>
Packit 1470ea
    </list>
Packit 1470ea
  </synopsis>
Packit 1470ea
Packit 1470ea
Packit 1470ea
Packit 1470ea
  <section id="autotools">
Packit 1470ea
  <title>Autotools and necessary files</title>
Packit 1470ea
  

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, <link href="http://en.wikipedia.org/wiki/GNU_build_system">the wikipedia article</link> provides a good overview on the subject.

Packit 1470ea
  

Packit 1470ea
    <list>
Packit 1470ea
      <item>

weatherapp.desktop

</item>
Packit 1470ea
      <item>

weatherapp.sh.in

</item>
Packit 1470ea
      <item>

Makefile.am

</item>
Packit 1470ea
      <item>

configure.ac

</item>
Packit 1470ea
      <item>

autogen.sh

</item>
Packit 1470ea
    </list>
Packit 1470ea
    

weatherapp.desktop

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

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.

Packit 1470ea
Packit 1470ea
    

weatherapp.sh.in

Packit 1470ea
    
Packit 1470ea
#!/bin/sh
Packit 1470ea
export GJS_PATH=@bindir@
Packit 1470ea
gjs @bindir@/weatherapp.js]]>
Packit 1470ea
    

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

Packit 1470ea
Packit 1470ea
    

Makefile.am

Packit 1470ea
    
Packit 1470ea
# The actual runnable program is set to the SCRIPTS primitive. Prefix bin_ tells where to copy this
Packit 1470ea
bin_SCRIPTS = weatherapp.js geonames.js weatherapp.sh
Packit 1470ea
# List of files to be distributed
Packit 1470ea
EXTRA_DIST=  \
Packit 1470ea
    $(bin_SCRIPTS) \
Packit 1470ea
    $(private_icons)	\
Packit 1470ea
	  $(NULL)
Packit 1470ea
Packit 1470ea
CLEANFILES =
Packit 1470ea
Packit 1470ea
# The desktop files
Packit 1470ea
desktopdir = $(datadir)/applications
Packit 1470ea
desktop_DATA =weatherapp.desktop
Packit 1470ea
Packit 1470ea
# convenience command for doing Makefile variable substitutions in non-Makefile
Packit 1470ea
# files (scripts, service files, etc.)
Packit 1470ea
do_subst = sed -e 's|@abs_top_srcdir[@]|$(abs_top_srcdir)|g' \
Packit 1470ea
               -e 's|@abs_top_builddir[@]|$(abs_top_builddir)|g' \
Packit 1470ea
               -e 's|@localedir[@]|$(localedir)|g' \
Packit 1470ea
               -e 's|@bindir[@]|$(bindir)|g' \
Packit 1470ea
               -e 's|@libexecdir[@]|$(libexecdir)|g' \
Packit 1470ea
	       -e 's|@pkglibdir[@]|$(pkglibdir)|g' \
Packit 1470ea
	       -e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
Packit 1470ea
	       -e 's|@have_libnotify[@]|$(HAVE_LIBNOTIFY)|g' \
Packit 1470ea
	       -e 's|@have_libsoup[@]|$(HAVE_LIBSOUP)|g' \
Packit 1470ea
	       -e 's|@have_cheese[@]|$(HAVE_CHEESE)|g'
Packit 1470ea
Packit 1470ea
weatherapp.sh: weatherapp.sh.in
Packit 1470ea
	$(AM_V_GEN) $(do_subst) $< > $@
Packit 1470ea
	chmod +x $@
Packit 1470ea
Packit 1470ea
CLEANFILES += weatherapp.sh
Packit 1470ea
EXTRA_DIST += weatherapp.sh.in
Packit 1470ea
Packit 1470ea
#the application icon
Packit 1470ea
appicondir=$(datadir)/icons/hicolor/scalable/apps
Packit 1470ea
appicon_DATA=weather-icon.svg
Packit 1470ea
Packit 1470ea
#icons in the application
Packit 1470ea
NULL =
Packit 1470ea
Packit 1470ea
private_icons = \
Packit 1470ea
	weather-clear.svg \
Packit 1470ea
  weather-few-clouds.svg \
Packit 1470ea
  weather-fog.svg \
Packit 1470ea
  weather-icon.svg \
Packit 1470ea
  weather-overcast.svg \
Packit 1470ea
  weather-showers.svg \
Packit 1470ea
  weather-showers-scattered.svg \
Packit 1470ea
  weather-snow.svg \
Packit 1470ea
  $(NULL)
Packit 1470ea
Packit 1470ea
install-icons:
Packit 1470ea
	for icon in $(private_icons); do \
Packit 1470ea
		mkdir -p $(DESTDIR)$(pkgdatadir)/icons/; \
Packit 1470ea
		$(INSTALL_DATA) $(srcdir)/$$icon $(DESTDIR)$(pkgdatadir)/icons/; \
Packit 1470ea
	done
Packit 1470ea
Packit 1470ea
install-data-local: install-icons]]>
Packit 1470ea
    

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:

Packit 1470ea
    

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.

Packit 1470ea
    

EXTRA_DIST are the files that are to be distributed

Packit 1470ea
    

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

Packit 1470ea
    

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 by the install-icons: bit

Packit 1470ea
Packit 1470ea
    

configure.ac

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

autogen.sh

Packit 1470ea
    
Packit 1470ea
#!/bin/sh
Packit 1470ea
# This will run autoconf, automake, etc. for us
Packit 1470ea
autoreconf --force --install]]>
Packit 1470ea
  </section>
Packit 1470ea
  <section id="icons">
Packit 1470ea
  <title>Custom icons for your application</title>
Packit 1470ea
  

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

Packit 1470ea
  

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

Packit 1470ea
  

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

Packit 1470ea
  

appicon_DATA=weather-icon.svg

Packit 1470ea
  </section>
Packit 1470ea
Packit 1470ea
</page>