Developing for Elementary OS – Setup and Compiling

Weekends are a great time to enjoy doing what you like to do, ins’t it? I like to code and read and learn new technologies, experience new computer languages, so past weekend I did something that I was planning to do a long time, try to code something to Elementary OS.

Why the Elementary OS? Well, first of all, I like to try new tech stuff, in second, the Elementary OS makes me feel good to use, a strange feeling, different from using another linux distro. I don’t know, I think I’m in love for it…. ok, let’s stop with this bullshit and back to develop.

elementarylogo

Basically, the Elementary OS is over GTK 3 and uses Vala as main language (or not a language) to develop it’s applications. The Elementary “Getting Starter” section for developers already conduces you through very detailed steps to build your first app and to get involved with this magic enviroment.

In the end you get a very nice hello world simple app and a few resources. It’s a very nice experience to see your work running natively.

hello-world-vala-elementary-os

But I found that the steps are too much detailed, not that it’s bad but sometimes I would like to do it more quickly as I already know many of these basic stuff. Also, in sometimes I felt a little lost, so in the end, I decided to make a simple to-do list of the summary of how to setup a new enviroment to a new project, check it out:

  1. sudo apt install elementary-sdk
    It will install all dependencies to compile your app.
    Just need to do this step at the first time, don’t need it on your second project.
  2. create your project folder and sub-folders:
    ./project
    ./project/src
    ./project/build
    ./project/data
    ./project/po
  3. create the main project file:
    ./project/project-main-file.vala
  4. Add sample content on your .vala file:
    int main (string[] args) {
       Gtk.init (ref args);
       var window = new Gtk.Window ();
       window.title = "Hello World!";
       window.set_border_width (12);
       window.set_position (Gtk.WindowPosition.CENTER);
       window.set_default_size (350, 70);
       window.destroy.connect (Gtk.main_quit);
       var button_hello = new Gtk.Button.with_label ("Click me!");
    
       button_hello.clicked.connect (() => {
       button_hello.label = "Hello World!";
       button_hello.set_sensitive (false);
     });
     
     window.add (button_hello);
     window.show_all ();
     Gtk.main ();
     return 0;
    }
  5. create the CMakeLists file:
    ./project/CMakeLists.txt
  6. Add the basic content on the./project/CMakeLists.txt, copy it from:
    https://elementary.io/pt_BR/docs/code/getting-started#the-build-system
  7. Change the following content on the ./project/CMakeLists.txt to fit your project:
    should be on line: 39 ===> # files we want to compile
  8. Change the following content on the ./project/CMakeLists.txt to define your executable file name:
    should be on line: 17 ===> set (EXEC_NAME “com.github.yourusername.yourrepositoryname”))
  9. Add translation information to the ./project/CMakeLists.txt, copy from:
    https://elementary.io/pt_BR/docs/code/getting-started#Adding-Translations
    (step 2)
  10. Create the translation CMake file file:
    ./project/po/CMakeLists.txt
  11. Add content to the translation file ./project/po/CMakeLists.txt, from:
    https://elementary.io/pt_BR/docs/code/getting-started#Adding-Translations
    (step 3)
  12. Create the base for your shortcut app file:
    ./project/data/com.github.yourusername.yourrepositoryname.desktop
  13. Add content on .desktop file, copy from:
    https://elementary.io/pt_BR/docs/code/getting-started#the-desktop-file
  14. Create the App Center File information, on:
    ./project/date/com.github.yourusername.yourrepositoryname.appdata.xml
  15. Add content on .appdata.xml file, copy from:
    https://elementary.io/pt_BR/docs/code/getting-started#appdata
  16. Create your author’s file info, on:
    ./project/AUTHORS
  17. Add content on ./project/AUTHORS file, copy from:
    https://elementary.io/pt_BR/docs/code/getting-started#legal-stuff
  18. creating cmake information, run on ./project/build:
    cmake -DCMAKE_INSTALL_PREFIX=/usr ../
  19. creating the translations, run on ./project/build:
    make pot
  20. compiling your project, run on ./project/build:
    make
  21. finally run your compiled project:
    ./project/build/executable-filename-defined-on-cmakelists

 

Also, I want to share some useful links that I found it may help you to save some time:

The ValaDoc Reference: The references for all commands and functions that you will need to make a Vala app.

The Vala Tutorials: A lot of tutorial codes, file manipulations, fields, components and more.

Elementary OS sample libs: A preview of the Elementary OS lib components

Elementary OS widgets: The native OS components to use on the apps

GTK3 Icons reference: May be you need this

The DoodleSpark reference to Elementary OS Icons

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s