Sign in Join
Wiki copytemporary

Debian upstream: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11On Debian distribution, the upstream source is the code of the program that can be compiled for any target platform. It needs to be compilable using packages already available in the latest Debian distribution.
22
33If you want to distribute the .deb file directly, you may generate it following [[Debian package structure]].
44
55### Dependence on Lazarus custom packages
66
77Generally Debian packages will use dynamically linked libraries, that will be provided as another Debian package. However in Lazarus, it is common to use statically linked libraries that are provided as Lazarus custom packages (the main file have `.lpk` extension).
88
99If you are using custom Lazarus packages, you will need to include them in the upstream source. You can do that by copying the custom packages source code into your projects repository or create an upstream repository that will contain your own project as well as all custom packages source code.
1010
1111Publishing a new version of your project on Debian will thus require you to copy the source of used packages with the adequate version number. It is recommended to specify the required package version in the project inspector, so that you won't use an outdated custom package for compilation and also that you will be able to know which version is supposed to be used.
1212
1313### Upstream source, package maintainer and sponsor
1414
1515There are different levels when it comes to uploading packages into Debian:
1616
1717- upstream source provided by the software developer
1818- [[Debian package source]] provided by the package maintainer
1919- upload done by the package sponsor/mentor
2020
2121Note that it may be difficult to find a package maintainer so that the developer can as a matter of fact be the maintainer as well. This article talks only about the upstream source.
2222
2323The term sponsor/mentor does not refer to a financial support but to a Debian developer.
2424
2525### Upstream source content
2626
2727The upstream source consists of:
2828
2929- you project source code and custom Lazarus packages source code
3030- compilation scripts
3131- additional information about the program
3232
3333It can be organized for example like this:
3434
3535`upstream`\
3636`  ├─ myproject ...     # folder for main project (containing a .lpi file)`\
3737`  ├─ custompackage ... # folder for custom package (containing a .lpk file)`\
3838`  ├─ configure         # script to setup compilation`\
3939`  ├─ Makefile          # compilation and installation script`\
4040`  └─ info`\
4141`      ├─ myproject.1         # command line manual`\
4242`      ├─ myproject.desktop   # GUI application description`\
4343`      └─ icons               # GUI icons`\
4444`          ├─ 16x16.png`\
4545`          ├─ 32x32.png`\
4646`          ...`
4747
4848In all cases, the `debian` folder name is reserved for the Debian package so the upstream must not contain such folder unless it takes the responsibility of describing the Debian package.
4949
5050Common icon sizes: 16x16, 22x22, 24x24, 32x32, 36x36, 48x48, 64x64, 256x256, scalable, symbolic. Scalable and symbolic are in SVG format. You don't need to provide all of them, they will be stretched if necessary.
5151
5252#### Project and custom packages
5353
5454It is recommended to use a specific folder for each custom package, though there is no restriction here. You just need to remember the path to those when writing the `Makefile`.
5555
5656#### Command line manual
5757
5858The syntax is of the .1 file is a bit peculiar. There are some tools to help but you still need to know the syntax.
5959
6060- description of the syntax: <https://liw.fi/manpages/>
6161- editor with wizard and WYSIWYG preview mode: **gmanedit**
6262- live preview editor (toggle to **AN mode**): <https://roperzh.github.io/grapse/>
6363
6464Here is a sample file:
6565
6666`.TH Project1 1 "19 May 2020" "" Project1`\
6767`.SH NAME`\
6868`Project1 - My cool project`\
6969`.SH SYNOPSIS`\
7070`.B project1`\
7171`[PARAMETER]`\
7272`.SH DESCRIPTION`\
7373`What my program does.`\
7474`.PP`\
7575`More description.`
7676
7777#### Application description
7878
7979To add your application to the Linux menu, you need to add a file called ***.desktop** containing:
8080
8181`[Desktop Entry]`\
8282`Name=Project1`\
8383`Comment=Cool project`\
8484`Icon=project1`\
8585`Exec=project1`\
8686`Terminal=false`\
8787`Type=Application`\
8888`Categories=Graphics`\
8989`GenericName=Project1`\
9090`Keywords=feature1; feature2; feature3`
9191
9292This file is similar to a shortcut to your program.
9393
9494The **Categories** field is similar to the one in the **control** file. It can be for example: Communication, Database, Development, Editors, Electronics, Fonts, Games, Graphics, Math, Internet, Networking, News, Science, Sound, Utility, Video.
9595
9696The keywords help search through applications.
9797
9898#### configure script
9999
100100The script called `configure` is a script that is called initially before compilation. It can be used to detect the compilation environment and take appropriate actions. In the case of Lazarus, the bare minimum is to handle the *prefix* parameter. Here is for example a simple script that will store the *prefix* parameter in a file called `prefix`.
101101
102102`#!/bin/bash`\
103103`args=("$@")`\
104104`defaultprefix=/usr/local`\
105105`wantedprefix=$defaultprefix`\
106106`for param in "${args[@]}"`\
107107`do`\
108108`   if [ "$param" == "-h" ] || [ "$param" == "--help" ]; then`\
109109`       echo "Usage: ./configure [OPTIONS]"`\
110110`       echo ""`\
111111`       echo "    --prefix=PREFIX"`\
112112`       echo "        Specifies the install prefix."`\
113113`       echo "        By default prefix is \"$defaultprefix\"" `\
114114`       echo "        For packages use \"/usr\""`\
115115`       exit 0`\
116116`   elif [ "${param:0:9}" == "--prefix=" ]; then`\
117117`       wantedprefix=${param:9}`\
118118`   else`\
119119`       echo "Warning: unknown option $param"`\
120120`   fi`\
121121`done`\
122122`echo "Prefix set to: $wantedprefix"`\
123123`echo $wantedprefix >prefix  # store the prefix into the file called "prefix"`
124124
125125Here are examples of calls:
126126
127127`./configure                 # when testing the program locally`\
128128`./configure --prefix=/usr   # when building the package`
129129
130130#### Makefile
131131
132132##### Initialization
133133
134134The Makefile is a sort of script. It does not have a shebang (line starting with "#!") and uses by default the minimalist shell `/bin/sh`. You can override it though and use bash with something like:
135135
136136`SHELL := /bin/bash`
137137
138138Note that in the `Makefile`, unlike a regular script, to access a variable one write `$(VARIABLE)` with brackets instead of `${VARIABLE}` with braces. To run a shell command and retrieve the result, the brackets will also be used, which can be a little bit confusing.
139139
140140Variables are set using `:=` operator. For example, to compute the actual target path, one can write the following:
141141
142142`prefix := $(shell cat prefix)   # retrieve the content of the file called "prefix"`\
143143`TARGET_DIR = $(DESTDIR)$(prefix)`
144144
145145When building locally, *DESTDIR* will be empty so that the target path will be the same as *prefix*. When building the package though, *DESTDIR* will indicate a temporary folder to use.
146146
147147To make things easier to update, let's define the name of your project (without the .lpi extension):
148148
149149`PROJECT_NAME := myproject`
150150
151151##### Compiling
152152
153153After the initialization of variables, the Makefile consists of entries called rules. The syntax of a rule is the following:
154154
155155`rule1: require1 require2`\
156156`#... how to make it`
157157
158158Here the name of the rule is *rule1* and it requires the rules *require1* and *require2* to be already made. This means that first *require1* and *require2* will be made and only afterwards *rule1* will be made. The following lines contain the instructions to execute to make *rule1*.
159159
160160If a rule does not need any other, there won't be anything after the colon. In the case of a Lazarus project, one can simply write:
161161
162162`all:`\
163163`   lazbuild --build-mode=Release $(PROJECT_NAME)/$(PROJECT_NAME).lpi`
164164
165165The rule *all* is the one invoked to compile the program. Note that before the instructions, a tab character is needed (not spaces). It is recommended to specify the build-mode, because there may be various build modes like Debug or for different widgetsets (gtk2, gtk3, qt4, qt5). So whatever build mode is active in the project, you will be assured of the build mode used to generate the Debian package.
166166
167167To clean the compiled files, there is a need for another rule:
168168
169169`clean:`\
170170`   rm -f $(PROJECT_NAME)/$(PROJECT_NAME)  # remove generated executable file`\
171171`   rm -rf lib             # remove object files`
172172
173173Note that the object files may be in another folder. Check the project options.
174174
175175For completeness, let's provide a rule to clean the whole building process:
176176
177177`distclean: clean clean_configure`\
178178`clean_configure:`\
179179`   rm -f prefix     # remove the "prefix" file generated by "configure" script`
180180
181181##### Installation and package building
182182
183183The `Makefile` needs to be able to install files on the system or to put them in the package. Both will be done with the same code and when building a package, the target directory will instead be a temporary one.
184184
185185We will need additional folders for the installation.
186186
187187`BIN_DIR = $(TARGET_DIR)/bin                  # executable file`\
188188`SHARE_DIR = $(TARGET_DIR)/share              # other files`\
189189`RESOURCE_DIR = $(SHARE_DIR)/$(PROJECT_NAME)  # custom resources`\
190190`MANUAL_DIR = $(SHARE_DIR)/man                # man page`\
191191`ICON_DIR = $(SHARE_DIR)/icons/hicolor        # icons (multiple resolutions)`\
192192`PIXMAP_DIR = $(SHARE_DIR)/pixmaps            # pixmap (fallback icon)`\
193-\
193+
194194`SRC_BIN_DIR = $(PROJECT_NAME)`\
195195`SRC_INFO_DIR = info`\
196196`SRC_ICON_DIR = $(SRC_INFO_DIR)/icons`
197197
198198One can retrieve all icons in the folder with:
199199
200200`SRC_ICONS = $(shell find "$(SRC_ICON_DIR)" -maxdepth 1 -type f -name *x*.png -exec basename {} .png ';')`
201201
202202##### Installation rule
203203
204204The installation will require the *prefix* file to exist. This can be specified like any other rule:
205205
206206`install: prefix`\
207207`   install -D "$(SRC_BIN_DIR)/$(PROJECT_NAME)" "$(BIN_DIR)/$(PROJECT_NAME)"`\
208208`   install -d "$(SHARE_DIR)/man/man1"`\
209209`   gzip -9 -n -c "$(SRC_INFO_DIR)/man/man1/$(PROJECT_NAME).1" >"$(SHARE_DIR)/man/man1/$(PROJECT_NAME).1.gz"`\
210210`   chmod 0644 "$(SHARE_DIR)/man/man1/$(PROJECT_NAME).1.gz"`\
211211`   install -D "$(SRC_INFO_DIR)/$(PROJECT_NAME).desktop" "$(SHARE_DIR)/applications/$(PROJECT_NAME).desktop"`\
212212`   install -D --mode=0644 "$(SRC_ICON_DIR)/48x48.png" "$(SHARE_DIR)/pixmaps/$(PROJECT_NAME).png"`\
213213`   for s in $(SRC_ICONS); do install -D --mode=0644 "$(SRC_ICON_DIR)/$$s.png" "$(ICON_DIR)/$$s/apps/$(PROJECT_NAME).png"; done`
214214
215215Note:
216216
217217- copying is done using the `install` command. The -D option will create missing directories for the file and the -d option will create the specified directory. The option --mode=0644 must be used for data files.
218218- the 48x48 icon is used as default pixmap.
219219- there are no resources installed in this case but you can add them in a similar way using `install` command.
220220
221221##### Uninstallation rule
222222
223223A similar rule must be created to uninstall the software:
224224
225225`uninstall: prefix`\
226226`   rm -f "$(BIN_DIR)/$(PROJECT_NAME)"`\
227227`   rm -f "$(SHARE_DIR)/man/man1/$(PROJECT_NAME).1.gz"`\
228228`   rm -f "$(SHARE_DIR)/applications/$(PROJECT_NAME).desktop"`\
229229`   rm -f "$(SHARE_DIR)/pixmaps/$(PROJECT_NAME).png"`\
230230`   for s in $(SRC_ICONS); do rm -f "$(ICON_DIR)/$$s/apps/$(PROJECT_NAME).png"; done`
231231
232232### Compiling upstream
233233
234234Once you have all upstream files ready, you can check it compiles by going into the upstream folder and doing:
235235
236236`./configure`\
237237`make`\
238238`sudo make install`\
239239`#test the program`\
240240`sudo make uninstall`
241241
242242Note that before installing, make sure your program is not already installed on the system. Otherwise you won't be able to check that the installation was successful.
243243
244244To test that the command line is working, simply call your program or check the manual:
245245
246246`myproject`\
247247`man myproject`
248248
249249To test that the GUI is working, go in the Linux menu and find your program. Check that it is displayed with the appropriate icon.
250250
251251If everything works, the next step is to get your upstream packaged. You can request that someone take care of it by sending an RFP bug request: <https://wiki.debian.org/RFP>
252252
253253If you don't get any answer, you may want to do the packaging yourself. See [[Debian package source]].
254254
255255---
256256*From the Free Pascal wiki, page "Debian upstream", as it stood on 2021-12-16 after a change by Dbannon, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
257257Category: Deployment
258258Category: Install
259259Category: Linux

Back to history