-
Notifications
You must be signed in to change notification settings - Fork 10
/
lazpackagerdebian.pas
292 lines (256 loc) · 9.02 KB
/
lazpackagerdebian.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
{ LazDebian packager for debian packages.
Copyright (C) 2012 Bernd Kreuss prof7bit@gmail.com
This source is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
A copy of the GNU General Public License is available on the World Wide
Web at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by
writing to the Free Software Foundation, Inc., 59 Temple Place - Suite
330, Boston, MA 02111-1307, USA.
}
unit LazPackagerDebian;
{$mode objfpc}{$H+}
interface
uses
LazPackagerBase;
const
CONFNAME_DEB = CONFNAME_BASE + '/deb';
DEFAULT_CONTROL
= 'Source: ?PACKAGE_NAME?'+ LF
+ 'Maintainer: ?MAINTAINER? <?MAINTAINER_EMAIL?>'+ LF
+ 'Section: misc'+ LF
+ 'Priority: optional'+ LF
+ 'Standards-Version: 3.9.3'+ LF
+ 'Build-Depends: fpc, lazarus, lcl, lcl-utils, debhelper (>= 8)'+ LF
+ LF
+ 'Package: ?PACKAGE_NAME?'+ LF
+ 'Architecture: any'+ LF
+ 'Depends: ${shlibs:Depends}, ${misc:Depends},'+ LF
+ 'Description: ?DESCRIPTION?'+ LF
+ ' ?DESCRIPTION_LONG?'+ LF
;
DEFAULT_RULES
= '#!/usr/bin/make -f' + LF
+ LF
+ 'ROOT = $(CURDIR)/debian/?PACKAGE_NAME?' + LF
+ LF
+ 'override_dh_auto_clean:' + LF
+ TAB + '$(RM) -r lib' + LF
+ TAB + '$(RM) lib *.res ?EXECUTABLE?' + LF
+ LF
+ 'override_dh_auto_build:' + LF
+ TAB + 'lazbuild ?PROJECT?' + LF
+ LF
+ 'override_dh_auto_install:' + LF
+ TAB + 'install -d -m 755 $(ROOT)/usr/bin' + LF
+ TAB + 'install -s -m 755 ?EXECUTABLE? $(ROOT)/usr/bin' + LF
+ LF
+ '%:' + LF
+ TAB + 'dh $@' + LF
;
DEFAULT_CHANGELOG
= '?PACKAGE_NAME? (?FULLVERSION?) ?SERIES?; urgency=low' + LF
+ LF
+ ' * Original version ?VERSION? packaged with lazdebian' + LF
+ LF
+ ' -- ?MAINTAINER? <?MAINTAINER_EMAIL?> ?DATER?' + LF
;
DEFAULT_COPYRIGHT
= 'Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/' + LF
+ LF
+ 'Files: *' + LF
+ 'Copyright: ?COPYRIGHT?' + LF
+ 'License: GPL-2+' + LF
+ ' This program is free software; you can redistribute it and/or modify' + LF
+ ' it under the terms of the GNU General Public License as published by' + LF
+ ' the Free Software Foundation; either version 2 of the License, or' + LF
+ ' at your option) any later version.' + LF
+ ' .' + LF
+ ' This program is distributed in the hope that it will be useful,' + LF
+ ' but WITHOUT ANY WARRANTY; without even the implied warranty of' + LF
+ ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the' + LF
+ ' GNU General Public License for more details.' + LF
+ ' .' + LF
+ ' You should have received a copy of the GNU General Public License along' + LF
+ ' with this program; if not, write to the Free Software Foundation, Inc.,' + LF
+ ' 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.' + LF
+ ' .' + LF
+ ' On Debian systems, the full text of the GNU General Public' + LF
+ ' License version 2 can be found in the file' + LF
+ ' /usr/share/common-licenses/GPL-2' + LF
;
type
{ TPackagerDebian adds some debian specific methods to the
packager base class and also a few more debian related
templates and settings, creates the debian files and creates
and runs DEBUILD.sh build script to build the package.}
TPackagerDebian = class(TPackagerBase)
public
Control: String;
Rules: String;
Changelog: String;
Copyright: String;
Series: String; // "precise", "quantal", etc.
PPA: String;
procedure Save; override;
procedure Load; override;
function FillTemplate(Template: String): String; override;
procedure DoMakePackage(Binary, Sign, Upload: Boolean); override;
protected
procedure CreateDebianBuildScript(Binary, Sign, Upload: Boolean);
procedure CreateDebianFiles;
function GetBuildScriptName: String; override;
function GetDateRFC2822: String;
function GetOrigTarNameOnly: String;
function GetDebuildPathAbsolute: String;
function GetDebuildSrcPathAbsolute: String;
function GetDebuildSrcDebianPathAbsolute: String;
end;
implementation
uses
sysutils,
process,
FileUtil;
{ TPackagerDebian }
procedure TPackagerDebian.Save;
begin
inherited Save;
SaveValue(CONFNAME_DEB, 'series', Series);
SaveValue(CONFNAME_DEB, 'ppa', PPA);
SaveValue(CONFNAME_DEB, 'tpl_control', Control);
SaveValue(CONFNAME_DEB, 'tpl_rules', Rules);
SaveValue(CONFNAME_DEB, 'tpl_changelog', Changelog);
SaveValue(CONFNAME_DEB, 'tpl_copyright', Copyright);
end;
procedure TPackagerDebian.Load;
begin
inherited Load;
Series := LoadValue(CONFNAME_DEB, 'series', 'precise');
PPA := LoadValue(CONFNAME_DEB, 'ppa', 'ppa:johndoe/use-your-own');
Control := LoadValue(CONFNAME_DEB, 'tpl_control', DEFAULT_CONTROL);
Rules := LoadValue(CONFNAME_DEB, 'tpl_rules', DEFAULT_RULES);
Changelog := LoadValue(CONFNAME_DEB, 'tpl_changelog', DEFAULT_CHANGELOG);
Copyright := LoadValue(CONFNAME_DEB, 'tpl_copyright', DEFAULT_COPYRIGHT);
end;
function TPackagerDebian.FillTemplate(Template: String): String;
begin
Result := inherited FillTemplate(Template);
ReplaceMany(Result, ['?SERIES?', Series
,'?FULLVERSION?', GetOriginalProjectVersion + '-1'
,'?DATER?', GetDateRFC2822
]);
end;
procedure TPackagerDebian.DoMakePackage(Binary, Sign, Upload: Boolean);
begin
CreateDebianFiles;
CreateDebianBuildScript(Binary, Sign, Upload);
RunBuildScriptAsync;
end;
procedure TPackagerDebian.CreateDebianBuildScript(Binary, Sign, Upload: Boolean);
var
S: String;
SName: String;
DEBUILD: STRING;
begin
s := '#!/bin/sh' + LF
+ LF
+ 'set -v' + LF
+ 'set -e' + LF
+ Format('cd "%s"', [GetProjectPathAbsolute]) + LF
+ Format('mkdir -p %s', [GetTempPathAbsolute]) + LF
+ FillTemplate(ExportCommands) + LF
+ LF
+ Format('cd %s', [GetTempPathAbsolute]) + LF
+ 'rm -rf DEBUILD' + LF
+ 'rm -f DEBUILD.sh' + LF
+ LF
+ 'cd ..' + LF
+ Format('tar czf %s %s', [GetOrigTarNameOnly, GetOrigFolderNameOnly]) + LF
+ Format('mv %s "%s"', [GetOrigFolderNameOnly, GetDebuildPathAbsolute]) + LF
+ Format('mv %s "%s"', [GetOrigTarNameOnly, GetDebuildPathAbsolute]) + LF
+ LF
+ Format('cd "%s"', [GetDebuildSrcPathAbsolute]) + LF
+ 'mkdir -p debian/source' + LF
+ 'echo "1.0" > debian/source/format' + LF
+ 'echo "8" > debian/compat' + LF
+ 'mv ../control debian/' + LF
+ 'mv ../rules debian/' + LF
+ 'chmod +x debian/rules' + LF
+ 'mv ../changelog debian/' + LF
+ 'mv ../copyright debian/' + LF
;
if Binary then
S += 'debuild -us -uc -d -b' + LF
else
S += 'debuild -us -uc -S' + LF;
if Sign then begin
S += 'cd ..' + LF;
S += 'xterm -e "debsign *.changes"' + LF;
end;
if Upload then begin
S += Format('dput %s *.changes', [PPA]) + LF;
end;
SName := ConcatPaths([GetProjectPathAbsolute, 'DEBUILD.sh']);
CreateFile(SName, S);
end;
procedure TPackagerDebian.CreateDebianFiles;
var
DirDebuild: String;
begin
DirDebuild := GetDebuildPathAbsolute;
if DirectoryExists(DirDebuild) then
DeleteDirectory(DirDebuild, False);
MkDir(DirDebuild);
CreateFile(ConcatPaths([DirDebuild, 'control']), FillTemplate(Control));
CreateFile(ConcatPaths([DirDebuild, 'rules']), FillTemplate(Rules));
CreateFile(ConcatPaths([DirDebuild, 'changelog']), FillTemplate(Changelog));
CreateFile(ConcatPaths([DirDebuild, 'copyright']), FillTemplate(Copyright));
end;
function TPackagerDebian.GetBuildScriptName: String;
begin
Result := 'DEBUILD.sh';
end;
function TPackagerDebian.GetDateRFC2822: String;
var
P: TProcess;
N: Integer;
begin
P := TProcess.Create(nil);
P.Executable := 'date';
P.Parameters.Add('-R');
P.Options := [poUsePipes, poWaitOnExit];
try
P.Execute;
SetLength(Result, 31);
// needs to look like this; "Thu, 27 Sep 2012 19:19:14 +0200"
// exactly 31 characters long, no more, no less.
N := P.Output.Read(Result[1], 31);
if N < 31 then
Result := '### date -R gave wrong data ###';
except
Result := '#### error calling date -R ####';
end;
P.Free;
end;
function TPackagerDebian.GetOrigTarNameOnly: String;
begin
Result := Format('%s_%s.orig.tar.gz', [PackageName, GetOriginalProjectVersion]);
end;
function TPackagerDebian.GetDebuildPathAbsolute: String;
begin
Result := ConcatPaths([GetProjectPathAbsolute, 'DEBUILD']);
end;
function TPackagerDebian.GetDebuildSrcPathAbsolute: String;
begin
Result := ConcatPaths([GetDebuildPathAbsolute, GetOrigFolderNameOnly]);
end;
function TPackagerDebian.GetDebuildSrcDebianPathAbsolute: String;
begin
Result := ConcatPaths([GetDebuildSrcPathAbsolute, 'debian']);
end;
end.