\section{Getting Started}
\label{group__Start}\index{Getting Started@{Getting Started}}


To write an Elementary app, you can get started with the following\-:  


To write an Elementary app, you can get started with the following\-: 
\begin{DoxyCode}
\textcolor{preprocessor}{#include <Elementary.h>}
EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   \textcolor{comment}{// create window(s) here and do any application init}
   elm_run(); \textcolor{comment}{// run main loop}
   elm_shutdown(); \textcolor{comment}{// after mainloop finishes running, shutdown}
   \textcolor{keywordflow}{return} 0; \textcolor{comment}{// exit 0 for exit code}
\}
ELM_MAIN()
\end{DoxyCode}


To use autotools (which helps in many ways in the long run, like being able to immediately create releases of your software directly from your tree and ensure everything needed to build it is there) you will need a configure.\-ac, Makefile.\-am and autogen.\-sh file.

configure.\-ac\-:


\begin{DoxyCode}
AC\_INIT(myapp, 0.0.0, myname@mydomain.com)
AC\_PREREQ(2.52)
AC\_CONFIG\_SRCDIR(configure.ac)
AM\_CONFIG\_HEADER(config.h)
AC\_PROG\_CC
AM\_INIT\_AUTOMAKE(1.6 dist-bzip2)
PKG\_CHECK\_MODULES([ELEMENTARY], elementary)
AC\_OUTPUT(Makefile)
\end{DoxyCode}


Makefile.\-am\-:


\begin{DoxyCode}
AUTOMAKE\_OPTIONS = 1.4 foreign
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.h.in configure depcomp install-sh missing

INCLUDES = -I$(top\_srcdir)

bin\_PROGRAMS = myapp

myapp\_SOURCES = main.c
myapp\_LDADD = @ELEMENTARY\_LIBS@
myapp\_CFLAGS = @ELEMENTARY\_CFLAGS@
\end{DoxyCode}


autogen.\-sh\-:


\begin{DoxyCode}
\textcolor{preprocessor}{#!/bin/sh}
\textcolor{preprocessor}{} echo \textcolor{stringliteral}{"Running aclocal..."} ; aclocal $ACLOCAL\_FLAGS || exit 1
 echo \textcolor{stringliteral}{"Running autoheader..."} ; autoheader || exit 1
 echo \textcolor{stringliteral}{"Running autoconf..."} ; autoconf || exit 1
 echo \textcolor{stringliteral}{"Running automake..."} ; automake --add-missing --copy --gnu || exit 1
 ./configure \textcolor{stringliteral}{"$@"}
\end{DoxyCode}


To generate all the things needed to bootstrap just run\-:


\begin{DoxyCode}
./autogen.sh
\end{DoxyCode}


This will generate Makefile.\-in's, the configure script and everything else. After this it works like all normal autotools projects\-: 
\begin{DoxyCode}
./configure
make
sudo make install
\end{DoxyCode}


Note sudo was assumed to get root permissions, as this would install in /usr/local which is system-\/owned. Use any way you like to gain root, or specify a different prefix with configure\-:


\begin{DoxyCode}
./configure --prefix=$HOME/mysoftware
\end{DoxyCode}


Also remember that autotools buys you some useful commands like\-: 
\begin{DoxyCode}
make uninstall
\end{DoxyCode}


This uninstalls the software after it was installed with \char`\"{}make install\char`\"{}. It is very useful to clear up what you built if you wish to clean the system.


\begin{DoxyCode}
make distcheck
\end{DoxyCode}


This firstly checks if your build tree is \char`\"{}clean\char`\"{} and ready for distribution. It also builds a tarball (myapp-\/0.\-0.\-0.\-tar.\-gz) that is ready to upload and distribute to the world, that contains the generated Makefile.\-in's and configure script. The users do not need to run autogen.\-sh -\/ just configure and on. They don't need autotools installed. This tarball also builds cleanly, has all the sources it needs to build included (that is sources for your application, not libraries it depends on like Elementary). It builds cleanly in a buildroot and does not contain any files that are temporarily generated like binaries and other build-\/generated files, so the tarball is clean, and no need to worry about cleaning up your tree before packaging.


\begin{DoxyCode}
make clean
\end{DoxyCode}


This cleans up all build files (binaries, objects etc.) from the tree.


\begin{DoxyCode}
make distclean
\end{DoxyCode}


This cleans out all files from the build and from configure's output too.


\begin{DoxyCode}
make maintainer-clean
\end{DoxyCode}


This deletes all the files autogen.\-sh will produce so the tree is clean to be put into a revision-\/control system (like C\-V\-S, S\-V\-N or G\-I\-T for example).

There is a more advanced way of making use of the quicklaunch infrastructure in Elementary (which will not be covered here due to its more advanced nature).

Now let's actually create an interactive \char`\"{}\-Hello World\char`\"{} gui that you can click the ok button to exit. It's more code because this now does something much more significant, but it's still very simple\-:


\begin{DoxyCode}
\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
on\_done(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{comment}{// quit the mainloop (elm\_run function will return)}
   elm_exit();
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *box, *lab, *btn;

   \textcolor{comment}{// new window - do the usual and give it a name (hello) and title (Hello)}
   win = elm_win_util_standard_add(\textcolor{stringliteral}{"hello"}, \textcolor{stringliteral}{"Hello"});
   \textcolor{comment}{// when the user clicks "close" on a window there is a request to delete}
   evas\_object\_smart\_callback\_add(win, \textcolor{stringliteral}{"delete,request"}, on\_done, NULL);

   \textcolor{comment}{// add a box object - default is vertical. a box holds children in a row,}
   \textcolor{comment}{// either horizontally or vertically. nothing more.}
   box = elm_box_add(win);
   \textcolor{comment}{// make the box horizontal}
   elm_box_horizontal_set(box, EINA\_TRUE);
   \textcolor{comment}{// add object as a resize object for the window (controls window minimum}
   \textcolor{comment}{// size as well as gets resized if window is resized)}
   elm_win_resize_object_add(win, box);
   evas\_object\_show(box);

   \textcolor{comment}{// add a label widget, set the text and put it in the pad frame}
   lab = elm_label_add(win);
   \textcolor{comment}{// set default text of the label}
   elm\_object\_text\_set(lab, \textcolor{stringliteral}{"Hello out there world!"});
   \textcolor{comment}{// pack the label at the end of the box}
   elm_box_pack_end(box, lab);
   evas\_object\_show(lab);

   \textcolor{comment}{// add an ok button}
   btn = elm_button_add(win);
   \textcolor{comment}{// set default text of button to "OK"}
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"OK"});
   \textcolor{comment}{// pack the button at the end of the box}
   elm_box_pack_end(box, btn);
   evas\_object\_show(btn);
   \textcolor{comment}{// call on\_done when button is clicked}
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, on\_done, NULL);

   \textcolor{comment}{// now we are done, show the window}
   evas\_object\_show(win);

   \textcolor{comment}{// run the mainloop and process events and callbacks}
   elm_run();
   elm_shutdown();
   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()
\end{DoxyCode}
 