Skip to content

Commit 0c0a4f4

Browse files
authored
Merge pull request #267 from s-makin/new-packages
New packages
2 parents bc2f43e + 8bea74f commit 0c0a4f4

File tree

6 files changed

+391
-207
lines changed

6 files changed

+391
-207
lines changed
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,250 @@
11
(how-to-create-a-new-package)=
22
# How to create a new package
33

4+
While there are thousands of packages in the Ubuntu archive, there are still a lot nobody has gotten to yet.
5+
If there is an exciting new piece of software that you feel needs wider exposure, maybe you want to try your hand at creating a package for Ubuntu [or a PPA](https://help.launchpad.net/Packaging/PPA).
6+
This guide will take you through the steps of packaging new software.
7+
8+
You should read the {ref}`Getting set up <how-to-set-up-for-ubuntu-development>` article first to prepare your development environment.
9+
10+
11+
## Checking the program
12+
13+
The first stage in packaging is to get the released tar from upstream (we call the authors of applications "upstream") and check that it compiles and runs.
14+
This guide will take you through packaging a simple application called GNU Hello which has been posted on [`GNU.org`](https://www.gnu.org/software/hello/).
15+
16+
Download GNU Hello:
17+
18+
```none
19+
wget -O hello-2.10.tar.gz "http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz"
20+
```
21+
22+
Now uncompress it:
23+
24+
```none
25+
tar xf hello-2.10.tar.gz
26+
cd hello-2.10
27+
```
28+
29+
This application uses the `autoconf` build system so we want to run `./configure` to prepare for compilation.
30+
31+
This checks for the required build dependencies. As `hello` is a simple example, `build-essential` and `texinfo` should provide everything we need.
32+
For more complex programs, the command will fail if you do not have the needed libraries and development files.
33+
Install the needed packages and repeat until the command runs successfully.:
34+
35+
```none
36+
./configure
37+
```
38+
39+
Now you can compile the source:
40+
41+
```none
42+
make
43+
```
44+
45+
If compilation completes successfully you can install and run the program:
46+
47+
```none
48+
sudo make install
49+
hello
50+
```
51+
52+
53+
## Starting a package
54+
55+
`bzr-builddeb` includes a plugin to create a new package from a template.
56+
The plugin is a wrapper around the `dh_make` command.
57+
Run the command providing the package name, version number, and path to the upstream tarball:
58+
59+
```none
60+
sudo apt-get install dh-make bzr-builddeb
61+
cd ..
62+
bzr dh-make hello 2.10 hello-2.10.tar.gz
63+
```
64+
65+
```{note}
66+
Unfortunately, the `bzr dh-make` subcommand is no longer available in releases later than Ubuntu 20.04.
67+
You might need a container or virtual machine running Ubuntu 20.04 for this particular step.
68+
```
69+
70+
When it asks what type of package, type `s` for single binary.
71+
This will import the code into a branch and add the `debian/` packaging directory.
72+
Examine the contents; most of the files it adds are only needed for specialist packages (such as Emacs modules) so you can start by removing the optional example files:
73+
74+
```none
75+
cd hello/debian
76+
rm *ex *EX
77+
```
78+
79+
You should now customise each of the files.
80+
81+
In `debian/changelog` change the version number to an Ubuntu version: `2.10-0ubuntu1` (upstream version 2.10, Debian version 0, Ubuntu version 1).
82+
Also change `unstable` to the current development Ubuntu release.
83+
84+
Much of the package building work is done by a series of scripts called `debhelper`.
85+
The exact behaviour of `debhelper` changes with new major versions, the `compat` file instructs `debhelper` which version to act as.
86+
You will generally want to set this to the most recent version.
87+
88+
`control` contains all the package metadata.
89+
The first paragraph describes the source package.
90+
The second and following paragraphs describe the binary packages to be built.
91+
We need to add the packages required to compile the application to `Build-Depends:`.
92+
For `hello`, make sure that it includes at least:
93+
94+
```none
95+
Build-Depends: debhelper (>= 9)
96+
```
97+
98+
And append `texinfo`, as noted earlier:
99+
100+
```none
101+
Build-Depends: debhelper (>= 9), texinfo
102+
```
103+
104+
You also need to fill in a description of the program in the `Description:` field.
105+
106+
`copyright` needs to be filled in to follow the licence of the upstream source.
107+
According to the hello/COPYING file this is GNU GPL 3 or later.
108+
109+
`docs` contains any upstream documentation files you think should be included in the final package.
110+
111+
`README.source` and `README.Debian` are only needed if your package has any non-standard features. In this case, we don't, so you can delete them.
112+
113+
`source/format` can be left as is; this describes the version format of the source package and should be `3.0 (quilt)`.
114+
115+
`rules` is the most complex file.
116+
This is the Makefile that compiles the code and turns it into a binary package.
117+
Fortunately, most of the work is automatically done these days by `debhelper 7` so the universal `%` Makefile target runs the `dh` script which runs everything needed.
118+
119+
All of these file are explained in more detail in the {ref}`overview of the debian/ directory <debian-directory>` article.
120+
121+
Finally, commit the code to your packaging branch (make sure to `bzr add` any untracked files that changed; for example, `debian/source/format`):
122+
123+
```none
124+
bzr add debian/source/format
125+
bzr commit -m "Initial commit of Debian packaging."
126+
```
127+
128+
129+
## Building the package
130+
131+
Now we need to check that our packaging successfully compiles the package and builds the `.deb` binary package:
132+
133+
```none
134+
bzr builddeb -- -us -uc
135+
cd ../../
136+
```
137+
138+
`bzr builddeb` is a command to build the package in its current location.
139+
The `-us -uc` tell it there is no need to GPG sign the package.
140+
The result will be placed in `..`.
141+
142+
:::{note}
143+
If it fails with `You must run ./configure before running 'make'.`, add this to `debian/rules` (make sure to `bzr add/commit` it) and retry `bzr builddeb`:
144+
145+
```none
146+
override_dh_auto_clean:
147+
[ -f Makefile ] || ./configure
148+
dh_auto_clean
149+
```
150+
:::
151+
152+
You can view the contents of the package with:
153+
154+
```none
155+
lesspipe hello_2.10-0ubuntu1_amd64.deb
156+
```
157+
158+
Install the package and check it works (later you will be able to uninstall it using `sudo apt remove hello` if you want):
159+
160+
```none
161+
sudo dpkg --install hello_2.10-0ubuntu1_amd64.deb
162+
```
163+
164+
You can also install all packages at once using:
165+
166+
```none
167+
sudo debi
168+
```
169+
170+
171+
## Next steps
172+
173+
Even if it builds the `.deb` binary package, your packaging may have bugs.
174+
Many errors can be automatically detected by our tool `lintian` which can be run on the source `.dsc` metadata file, `.deb` binary packages or `.changes` file:
175+
176+
```none
177+
lintian hello_2.10-0ubuntu1.dsc
178+
lintian hello_2.10-0ubuntu1_amd64.deb
179+
```
180+
181+
To see verbose description of the problems use `--info` lintian flag or `lintian-info` command.
182+
183+
For Python packages, there is also a `lintian4python` tool that provides some additional lintian checks.
184+
185+
After making a fix to the packaging you can rebuild using `-nc` ("no clean") without having to build from scratch:
186+
187+
```none
188+
bzr builddeb -- -nc -us -uc
189+
```
190+
191+
Having checked that the package builds locally you should ensure it builds on a clean system using `pbuilder`.
192+
Since we are going to upload to a Personal Package Archive (PPA) shortly, this upload will need to be *signed* to allow Launchpad to verify that the upload comes from you.
193+
You can tell the upload will be signed because the `-us` and `-uc` flags are not passed to `bzr builddeb` like they were before.
194+
For signing to work you need to have set up GPG.
195+
If you haven't set up `pbuilder-dist` or GPG yet, {ref}`do so now <how-to-set-up-for-ubuntu-development>`:
196+
197+
```none
198+
bzr builddeb -S
199+
cd ../build-area
200+
pbuilder-dist trusty build hello_2.10-0ubuntu1.dsc
201+
```
202+
203+
When you are happy with your package you will want others to review it.
204+
You can upload the branch to Launchpad for review:
205+
206+
```none
207+
bzr push lp:~<lp-username>/+junk/hello-package
208+
```
209+
210+
Uploading it to a PPA will ensure it builds and give an easy way for you and others to test the binary packages.
211+
You will need to set up a PPA in Launchpad and then upload with `dput`:
212+
213+
```none
214+
dput ppa:<lp-username>/<ppa-name> hello_2.10-0ubuntu1.changes
215+
```
216+
217+
You can ask for reviews in the {matrix}`devel` Matrix channel.
218+
There might also be a more specific team you could ask such as the GNU team for more specific questions.
219+
220+
221+
## Submitting for inclusion
222+
223+
There are a number of paths that a package can take to enter Ubuntu.
224+
In most cases, going through Debian first can be the best path.
225+
This way ensures that your package will reach the largest number of users as it will be available in not just Debian and Ubuntu but all of their derivatives as well.
226+
Here are some useful links for submitting new packages to Debian:
227+
228+
[Debian Mentors FAQ](https://wiki.debian.org/DebianMentorsFaq)
229+
: `debian-mentors` is for the mentoring of new and prospective Debian Developers. It is where you can find a sponsor to upload your package to the Archive.
230+
231+
[Work-Needing and Prospective Packages (WNPP)](https://www.debian.org/devel/wnpp/)
232+
: Information on how to file "Intent to Package" (ITP) and "Request for Package" (RFP) bugs as well as a list of open ITPs and RFPs.
233+
234+
[Debian Developer's Reference, 5.1. New packages](https://www.debian.org/doc/manuals/developers-reference/pkgs.html#newpackage)
235+
: The entire document is invaluable for both Ubuntu and Debian packagers. This section documents processes for submitting new packages.
236+
237+
In some cases, it might make sense to go directly into Ubuntu first.
238+
For instance, Debian might be in a freeze making it unlikely that your package will make it into Ubuntu in time for the next release.
239+
This process is documented in {ref}`New packages <new-packages>`.
240+
241+
242+
## Screenshots
243+
244+
Once you have uploaded a package to debian, you should add screenshots to allow propective users to see what the program is like.
245+
246+
To get a screenshot for software-center, use [screenshots.debian.net](https://screenshots.debian.net/packages).
247+
248+
You can use the same tool to [upload your screenshots](https://screenshots.debian.net/upload).
249+
250+

docs/how-ubuntu-is-made/processes/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Getting new versions of packages from Debian, dealing with build dependencies, a
2929
```{toctree}
3030
:maxdepth: 1
3131
32+
new-packages
3233
merges-and-syncs
3334
transitions
3435
backports

0 commit comments

Comments
 (0)