Application Development – How to Create a PPA for C++ Program

application-developmentppa

MyAgenda 1.0 screenshot

If I have a c++/gtkmm project created with NetBean, how can I make a package to PPA from this?

I have created target files structure (*.desktop, iconfile, ui glade files).

Binary goes to /opt/extras.ubuntu.com/myagenda/bin/myagenda.

There is also a folder of glade files, that must go to /opt/extras.ubuntu.com/myagenda/bin/myagenda/ui.

Desktop file goes to /usr/share/applications/myagenda.desktop.
Icon goes to /usr/share/icons/hicolor/scalable/apps/myagenda.svg

As you see, there is only a small number of files.

Now, how to manage all this stuff, to create package on PPA, which knows where and how put this files to their targets?

├── opt
│   └── extras.ubuntu.com
│       └── myagenda
│           ├── bin
│           │   └── myagenda
│           └── ui
│               ├── item_btn_delete.png
│               ├── item_btn_edit.png
│               ├── myagenda.png
│               ├── myagenda.svg
│               ├── reminder.png
│               └── ui.glade
└── usr
    └── share
        ├── applications
        │   └── myagenda.desktop
        └── icons
            └── hicolor
                └── scalable
                    └── apps
                        └── myagenda.svg

Update:

  1. Created install file in debian directory with targets:

    data/myagenda /opt/extras.ubuntu/com/myagenda/bin
    data/ui/* /opt/extras.ubuntu/com/myagenda/ui
    data/myagenda.desktop /usr/share/applications
    data/myagenda.svg /usr/share/icons/hicolor/scalable/apps
    

After dpkg-buildpackage it builds, but for amd64 architecture. Now, trying to change that to i386.

Best Answer

Creating PPA is very simple & at the same time somewhat complex process depending on the complexity of the package( i.e single binary, multiple binary...etc). But for simple application like your MyAgenda creating a PPA is very simple.

First install necessary packages.

sudo apt-get install build-essential devscripts ubuntu-dev-tools debhelper dh-make diff patch cdbs quilt gnupg fakeroot lintian pbuilder piuparts. Most of them are probably already installed by default.

Now setup your gpg-key & ssh-key. Follow instruction from here & here.


STEP1:Layout Of The Source Package

Now go to your application source folder.Here's your basic source package layout:

 MyAgenda-1.0/
    -- data/
          -- myagenda
          -- myagenda.desktop
          -- myagenda.svg
          --ui
             -- myagenda.glade
             -- otherfiles
    -- debian/
        -- changelog
        -- copyright
        -- compat
        -- rules
        -- control
        -- install

STEP2:Know your GPG KEY ID & Format

First run:

gpg --list-keys. It will give you output something like this:

   pub: YOURGPG-KEY
   uid: YOURUSERNAME <YOURMAIL-ID>   #note your username & email.
   sub: --------

STEP3:Create Debian Folder

To create debian folder & all other necessary files under debian folder run(use the same username & email-id from above):

DEBFULLNAME="YOURUSERNAME" dh_make -n -s -e YOUREMAIL-ID. This will help to sign the package with gpg key.

However this wont create the "install" file under debian folder. Create the file manually & save it with following data:

        data/myagenda /opt/extras.ubuntu/com/myagenda/bin
        data/ui/* /opt/extras.ubuntu/com/myagenda/ui
        data/myagenda.desktop /usr/share/applications
        data/myagenda.svg /usr/share/icons/hicolor/scalable/apps

STEP4: Update Changelog

To update changelog run:

dch -i

Here is a sample changelog:

package (version) distribution; urgency=urgency

 * change details
   more change details
 * even more change details

 -- maintainer name <email address>[two spaces]  Sun, 8 July 2012 18:14:08 +0530

Make sure the above format is preserved.When done editing press CTRL+O to write out.Remove
.dch part & overwrite changelog file.Press CTRL+X to exit.

You may want to delete extra .ex files under debian.Enter into debian folder & delete .ex & .EX files.

cd debian
rm *.ex *.EX

STEP5: Create DEB Package

Then to create deb package run:

debuild --no-tgz-check #Optional.it will not check for the source tarball.


STEP6: Upload To PPA

To upload the source package to a PPA you must run:

debuild -S

What the -S flag does is tell debuild to build a source package using another script, dpkg-buildpackage, together with fakeroot, which grants us fake root privileges while making the package. It will take the .orig.tar.gz file and produce a .diff.gz (the difference between the original tarball from the author and the directory we have created, debian/ and its contents) and a .dsc file that has the description and md5sums for the source package. The .dsc and *_source.changes (used for uploading the source package) files are signed using your GPG key.

debuild -S will create a source.changes file outside your source directory. Go to launchpad & create a PPA. Now upload the source.changes to that PPA((change the file name accordingly):

dput ppa:YOUR-LAUNCHPAD-USERNAME/myagenda myagenda-1.0-ubuntu1.changes 

DONE!


Notes:

If you want to upload package for several ubuntu versions get help from here.

Sources: Complete Packaging Guide Wiki.

Related Question