Debian Codegraph @

debian/gap2deb

raw
1 #! /usr/bin/gap -q
2 # GAP2DEB <https://salsa.debian.org/gap-packaging-team/gap2deb>
3 # Copyright 2014 Bill Allombert <[email protected]>
4 # This program is distributed under the term of the GNU GPL2+
5 # The author assert no copyright interest in the output.
6
7 # require htmltotext
8
9 debhelperver := "13";
10
11 StandardsVersion := "4.7.4";
12
13 Commas:=function(list)
14 return JoinStringsWithSeparator(list,", ");
15 end;
16
17 BaseDir:= function (path)
18 local tmp, file, dir, name, ext;
19 tmp := SplitString(path,"/");
20 file:= tmp[Length(tmp)];
21 Remove(tmp);
22 dir := JoinStringsWithSeparator(tmp,"/");
23 tmp := SplitString(file,".");
24 ext := tmp[Length(tmp)];
25 name := JoinStringsWithSeparator(tmp,".");
26 return [dir, name, ext];
27 end;
28
29 Backquote:= function (prg)
30 local shell, out, str;
31 str := "";
32 out := OutputTextString(str,true);
33 Process( DirectoryCurrent(), "/bin/sh", InputTextNone(), out, ["-c", prg] );
34 CloseStream(out);
35 return Chomp(str);
36 end;
37
38 HTMLToText:=function(html)
39 local shell, inp, out, str;
40 str := "";
41 inp := InputTextString(html);
42 out := OutputTextString(str,true);
43 Process(DirectoryCurrent(), "/usr/bin/html2text", inp, out,["-width","77"]);
44 CloseStream(inp);
45 CloseStream(out);
46 return str;
47 end;
48
49 Email:=function(r)
50 if IsBound(r.Email) then
51 return Concatenation(" <",r.Email,">");
52 else
53 return "";
54 fi;
55 end;
56
57 PkgName:=function(x)
58 return Concatenation("gap-pkg-",LowercaseString(x));
59 end;
60
61 DoError:=function(s)
62 Print("Error: ",s,"\n");
63 QUIT_GAP(1);
64 end;
65
66 MakeDocBase:=function(binname, authors, abstract, docbase, Doc)
67 local PackageDoc, PackageDocHTML, docid;
68 PackageDoc := BaseDir(Doc.HTMLStart);
69 PackageDocHTML := Concatenation(PackageDoc[1],"/*.",PackageDoc[3]);
70 docid := LowercaseString(ReplacedString(Doc.BookName," ","-"));
71 FileString(Concatenation("debian.gap2deb/",binname,".doc-base.",docid),Concatenation(
72 "Document: gap-",docid,"\n",
73 "Title: ",Doc.LongTitle,"\n",
74 "Author: ",authors,"\n",
75 "Abstract:\n ",abstract,"\n",
76 "Section: Science/Mathematics\n",
77 "\n",
78 "Format: pdf\n",
79 "Files: ",docbase,"/",Doc.PDFFile,"\n",
80 "\n",
81 "Format: HTML\n",
82 "Index: ",docbase,"/",Doc.HTMLStart,"\n",
83 "Files: ",docbase,"/",PackageDocHTML,"\n"));
84 end;
85
86 if IsBound(GAPInfo.SystemEnvironment.GAP2DEB_RULES) then
87 rules:=GAPInfo.SystemEnvironment.GAP2DEB_RULES;
88 else
89 rules:= "dh";
90 fi;
91
92 argv:=GAPInfo.KernelInfo.COMMAND_LINE;
93 argvrules:=List(Filtered(argv,s->Length(s)>=8 and s{[1..8]}="--rules="),s->s{[9..Length(s)]});
94
95 if Length(argvrules) > 0 then
96 rules:=argvrules[Length(argvrules)];
97 fi;
98
99 if IsDirectoryPath("debian.gap2deb") then
100 DoError("debian.gap2deb directory already exists");
101 fi;
102
103 if not IsReadableFile("PackageInfo.g") then
104 DoError(Concatenation(
105 "file PackageInfo.g not found\n",
106 "gap2deb must be launched inside a GAP package source directory"));
107 fi;
108 Unbind( GAPInfo.PackageInfoCurrent );
109 Read("PackageInfo.g");
110 pkg:= GAPInfo.PackageInfoCurrent;
111 Unbind( GAPInfo.PackageInfoCurrent );
112
113 env:=GAPInfo.KernelInfo.ENVIRONMENT;
114 if IsBound(env.DEBFULLNAME) then
115 maintname := env.DEBFULLNAME;
116 else
117 maintname:=SplitString(Backquote("getent passwd $USER"),":,")[5];
118 fi;
119 if IsBound(env.DEBEMAIL) then
120 maint:=Concatenation(maintname," <",env.DEBEMAIL,">");
121 else
122 maint := maintname;
123 fi;
124
125 if IsReadableFile("configure") then
126 arch := "any";
127 multiarch := "same";
128 else
129 arch := "all";
130 multiarch := "foreign";
131 fi;
132
133 pkgname := LowercaseString(pkg.PackageName);
134 srcname := Concatenation("gap-",pkgname);
135 binname := Concatenation("gap-",pkgname);
136 synopsis := Concatenation("GAP ",pkg.PackageName," - ",pkg.Subtitle);
137 homepage := Concatenation("https://www.gap-system.org/Packages/",pkgname,".html");
138 date := Backquote("date -R");
139 year := Backquote("date +%Y");
140 sDate:=SplitString(pkg.Date,"-");
141 if Length(sDate)=3 then
142 copyyear := sDate[1]; # New format yyyy-mm-dd
143 else
144 copyyear := SplitString(pkg.Date,"/")[3]; # Old format dd/mm/yyyy
145 fi;
146 if IsBound(pkg.License) then
147 license := pkg.License;
148 if license = "GPL-2.0-or-later" then
149 license := "GPL-2+";
150 gplver := "2";
151 elif license = "GPL-3.0-or-later" then
152 license := "GPL-3+";
153 gplver := "3";
154 elif license = "Artistic-2.0" then
155 license := "Artistic-2";
156 fi;
157 else
158 license := "GPL-2+";
159 gplver := "2";
160 fi;
161 abstract :=JoinStringsWithSeparator(SplitString(HTMLToText(pkg.AbstractHTML),"\n"),"\n ");
162 comp := SplitString(pkg.ArchiveURL,"/");
163 archivebase := SplitString(comp[Length(comp)],"0123456789")[1];
164 Remove(comp);
165 archiveURL := JoinStringsWithSeparator(comp,"/");
166 authors := Commas(List(pkg.Persons,x->Concatenation(x.FirstNames," ",x.LastName)));
167 authoremails :=
168 Commas(List(pkg.Persons,x->Concatenation(x.FirstNames," ",x.LastName,Email(x))));
169 pkgbaseN:=Concatenation("usr/share/gap/pkg/",pkg.PackageName);
170 pkgbase:=Concatenation("/",pkgbaseN);
171 docbaseN:=Concatenation("usr/share/doc/",binname);
172 docbase:=Concatenation("/",docbaseN);
173
174 gapdepver := ReplacedString(pkg.Dependencies.GAP,".","r");
175 gapdep := Concatenation("gap (",gapdepver,")");
176 neededslist:=List(pkg.Dependencies.NeededOtherPackages,x->PkgName(x[1]));
177 suggestionslist := List(pkg.Dependencies.SuggestedOtherPackages,x->PkgName(x[1]));
178 Doc := pkg.PackageDoc;
179 if not IsList(Doc) then
180 Doc := [ Doc ];
181 fi;
182 if IsBound(pkg.Dependencies.ExternalConditions) then
183 conditionslist := List(pkg.Dependencies.ExternalConditions,x->x);
184 else
185 conditionslist := [];
186 fi;
187 Depends:=Concatenation("Depends: ",
188 Commas(Concatenation(["${misc:Depends}", gapdep],neededslist,conditionslist)),"\n");
189 if IsEmpty(suggestionslist) then
190 Suggests:="";
191 else
192 Suggests:=Concatenation("Suggests: ",Commas(suggestionslist),"\n");
193 fi;
194
195 CreateDir("debian.gap2deb");
196 CreateDir("debian.gap2deb/source");
197 CreateDir("debian.gap2deb/patches");
198 FileString("debian.gap2deb/source/format","3.0 (quilt)\n");
199
200 if IsReadableFile("debian/changelog") then
201 Exec("cp debian/changelog debian.gap2deb/changelog");
202 else
203 FileString("debian.gap2deb/changelog",Concatenation(
204 srcname," (",pkg.Version,"-1) unstable; urgency=low\n",
205 "\n",
206 " * Initial Release.\n",
207 " * This is part of the GAP system.\n",
208 "\n",
209 " -- ",maint," ",date,"\n"));
210 fi;
211 FileString("debian.gap2deb/control",Concatenation(
212 "Source: ",srcname,"\n",
213 "Section: math\n",
214 "Priority: optional\n",
215 "Maintainer: ",maint,"\n",
216 "Build-Depends: debhelper-compat (= ",debhelperver,"), gap (>= 4r7), gap-doc\n",
217 "Standards-Version: ",StandardsVersion,"\n",
218 "Rules-Requires-Root: no\n",
219 "Homepage: ",homepage,"\n",
220 "\n",
221 "Package: ",binname,"\n",
222 "Provides: gap-pkg-",pkgname,"\n",
223 Depends,
224 "Recommends: gap\n",
225 Suggests,
226 "Multi-Arch: ",multiarch,"\n",
227 "Architecture: ",arch,"\n",
228 "Description: ",synopsis,"\n",
229 " GAP is a system for computational discrete algebra, with particular emphasis\n",
230 " on Computational Group Theory. GAP provides a programming language, a library\n",
231 " of thousands of functions implementing algebraic algorithms written in the GAP\n",
232 " language as well as large data libraries of algebraic objects. GAP is used in\n",
233 " research and teaching for studying groups and their representations, rings,\n",
234 " vector spaces, algebras, combinatorial structures, and more.\n",
235 " .\n",
236 " ",abstract,"\n"));
237
238 if IsBound(pkg.SourceRepository) then
239 FileString("debian.gap2deb/watch",Concatenation(
240 "version=4\n",
241 "opts=filenamemangle=s/.+\\/v?([\\.\\d]+)\\.tar\\.gz/",LowercaseString(pkg.PackageName),"-$1\\.tar\\.gz/,\\\n",
242 "downloadurlmangle=s/archive\\/refs\\/tags\\/v([\\.\\d]+)\\.tar\\.gz/releases\\/download\\/v$1\\/",LowercaseString(pkg.PackageName),"-$1\\.tar\\.gz/ \\\n",
243 " ",pkg.SourceRepository.URL,"/tags .*/v?([\\.\\d]+)\\.tar\\.gz debian uupdate\n"));
244 else
245 FileString("debian.gap2deb/watch",Concatenation(
246 "version=4\n",
247 archiveURL,"/",archivebase,"([0-9].*)\\.tar\\.gz debian uupdate\n"));
248 fi;
249
250 for doc in Doc do
251 MakeDocBase(binname, authors, abstract, docbase, doc);
252 od;
253
254 copyrighttext := Concatenation(
255 "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\n",
256 "Upstream-Name: ",pkg.PackageName,"\n",
257 "Source: ",pkg.PackageWWWHome,"\n",
258 "\n",
259 "Files: *\n",
260 "Copyright: Copyright ",copyyear," ",authoremails,"\n",
261 "License: ",license,"\n",
262 "\n",
263 "Files: debian/*\n",
264 "Copyright: Copyright ",year," ",maint,"\n",
265 "License: ",license,"\n",
266 "\n",
267 "License: ",license,"\n");
268
269 if IsBound(gplver) then
270 copyrighttext := Concatenation(copyrighttext,
271 " This program is free software: you can redistribute it and/or modify\n",
272 " it under the terms of the GNU General Public License as published by\n",
273 " the Free Software Foundation, either version ",gplver," of the license, or\n",
274 " (at your option) any later version.\n",
275 " .\n",
276 " This program is distributed in the hope that it will be useful,\n",
277 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
278 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
279 " GNU General Public License for more details.\n",
280 " .\n",
281 " You should have received a copy of the GNU General Public License\n",
282 " along with this program. If not, see <https://www.gnu.org/licenses/>.\n",
283 " .\n",
284 " On Debian systems, the full text of the GNU General Public\n",
285 " License version ",gplver," can be found in the file\n",
286 " `/usr/share/common-licenses/GPL-",gplver,"'.\n");
287 fi;
288
289 FileString("debian.gap2deb/copyright", copyrighttext);
290
291 FileString("debian.gap2deb/links", Concatenation(
292 List(Doc,doc->Concatenation(pkgbase,"/",doc.ArchiveURLSubset[1]," ",
293 docbaseN,"/",doc.ArchiveURLSubset[1],"\n"))));
294
295 FileString("debian.gap2deb/patches/series", "doc-makefile\n");
296 FileString("debian.gap2deb/patches/doc-makefile", Concatenation(
297 "Index: ",srcname,"/doc/Makefile\n",
298 "===================================================================\n",
299 "--- /dev/null 1970-01-01 00:00:00.000000000 +0000\n",
300 "+++ ",srcname,"/doc/Makefile 2013-07-27 23:11:04.365369025 +0200\n",
301 "@@ -0,0 +1,36 @@\n",
302 "+SHELL=/bin/bash\n",
303 "+pkgdocdir=",pkgbase,"/doc\n",
304 "+DOCDIR=$(DESTDIR)$(pkgdocdir)\n",
305 "+MANUAL=main\n",
306 "+DIRS=.\n",
307 "+doc:\n",
308 "+\t./make_doc\n",
309 "+clean:\n",
310 "+\trm -f $(DIRS)/*.{html,txt,css,js}\n",
311 "+\trm -f $(DIRS)/make_manuals.out $(DIRS)/mathjax\n",
312 "+\trm -f $(DIRS)/$(MANUAL).{aux,bbl,blg,brf,idx,ilg,ind,log,out,pnr,tex,toc,toc.gz}\n",
313 "+\trm -f $(DIRS)/manual{,-bw}.{lab,six,six.gz,pdf}\n",
314 "+\trm -f manualbib.xml.bib\n",
315 "+install: install-pdf install-help install-html\n",
316 "+install-pdf:\n",
317 "+\ttest -d $(DOCDIR)/$(DIRS) || install -d $(DOCDIR)/$(DIRS)\n",
318 "+\tset -e; for man in $(DIRS); do \\\n",
319 "+\t install -m 0644 $$man/manual.pdf $(DOCDIR)/$$man;\\\n",
320 "+\tdone\n",
321 "+install-help:\n",
322 "+\ttest -d $(DOCDIR)/$(DIRS) || install -d $(DOCDIR)/$(DIRS)\n",
323 "+\tset -e; for man in $(DIRS); do \\\n",
324 "+\t gzip --best --no-name $$man/manual.six; \\\n",
325 "+\t install -m 0644 $$man/$(MANUAL)bib.xml $(DOCDIR)/$$man; \\\n",
326 "+\t install -m 0644 $$man/$(MANUAL)bib.xml.bib $(DOCDIR)/$$man; \\\n",
327 "+\t install -m 0644 $$man/manual.six.gz $(DOCDIR)/$$man; \\\n",
328 "+\t install -m 0644 $$man/manual.lab $(DOCDIR)/$$man; \\\n",
329 "+\t install -m 0644 $$man/*.txt $(DOCDIR)/$$man; \\\n",
330 "+\tdone\n",
331 "+install-html:\n",
332 "+\ttest -d $(DOCDIR)/$(DIRS) || install -d $(DOCDIR)/$(DIRS)\n",
333 "+\tset -e; for man in $(DIRS); do \\\n",
334 "+\t install -m 0644 $$man/*.{html,css,js} $(DOCDIR)/$$man;\\\n",
335 "+\t ln -s `readlink mathjax` $(DOCDIR)/$$man/mathjax;\\\n",
336 "+\tdone\n",
337 "+.PHONY: clean install install-pdf install-help install-html\n"));
338
339 readme:="";
340 if IsReadableFile("README") then
341 readme:="README";
342 elif IsReadableFile("README.md") then
343 readme:="README.md";
344 elif IsReadableFile("README.txt") then
345 readme:="README.txt";
346 fi;
347 changes:="";
348 if IsReadableFile("CHANGES") then
349 changes:=" CHANGES";
350 elif IsReadableFile("CHANGES.md") then
351 changes:=" CHANGES.md";
352 elif IsReadableFile("CHANGES.txt") then
353 changes:=" CHANGES.txt";
354 fi;
355
356 excludeddir:=["debian","debian.gap2deb","doc","tst","htm"];
357 installdir:=JoinStringsWithSeparator(
358 Difference(Filtered(DirectoryContents("."),
359 x->IsDirectoryPath(x) and x[1] <> '.'), excludeddir), " ");
360
361 testfile:=false;
362 if IsBound(pkg.TestFile) then
363 testfile:=pkg.TestFile;
364 elif IsReadableFile("tst/testinstall.g") then
365 testfile:="tst/testinstall.g";
366 elif IsReadableFile("tst/testall.g") then
367 testfile:="tst/testall.g";
368 fi;
369
370 if testfile = false then
371 dotest:="";
372 cleantest:="";
373 else
374 if rules = "dh" then
375 target:= "execute_after_dh_auto_test:\n";
376 else
377 target:= "";
378 fi;
379 dotest:= Concatenation(
380 "ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))\n",
381 target,
382 "\techo 'SetPackagePath(\"",pkg.PackageName,"\",\".\"); Read(\"",testfile,"\");' \\\n",
383 "\t| gap -q -R -A | tee debian/gap.tst\n",
384 "\tgrep -q \"^#I No errors detected while testing\" debian/gap.tst\n",
385 "endif\n");
386 cleantest:= "\trm -f debian/gap.tst\n";
387 fi;
388
389 docfile := false;
390 if IsReadableFile("makedoc.g") then
391 docfile:="makedoc.g";
392 elif IsReadableFile("makedocrel.g") then
393 docfile:="makedocrel.g";
394 fi;
395
396 if docfile = false then
397 if rules = "dh" then
398 dodoc:="\tmake -C doc\n";
399 else
400 dodoc:="\tmake -C doc && touch build-indep-stamp\n";
401 fi;
402 else
403 if rules = "dh" then
404 target:= "execute_after_dh_auto_build:\n";
405 endrules:="";
406 else
407 target:= "";
408 endrules:= " && touch build-indep-stamp";
409 fi;
410 dodoc:= Concatenation(
411 target,
412 "\techo 'SetPackagePath(\"",pkg.PackageName,"\",\".\"); PushOptions(rec(relativePath:=true)); Read(\"",docfile,"\");' \\\n",
413 "\t| gap -q -R -A",
414 endrules
415 ,"\n");
416 fi;
417
418 if rules = "dh" then
419 FileString("debian.gap2deb/rules", Concatenation(
420 "#!/usr/bin/make -f\n",
421 "# Copyright ",year," ",maint,"\n",
422 "\n",
423 "export SOURCE_DATE_EPOCH = $(shell date -d \"$$(dpkg-parsechangelog -SDate)\" +%s)\n",
424 "export FORCE_SOURCE_DATE = 1\n",
425 "export LC_ALL = C\n",
426 "\n",
427 dotest,
428 "\n",
429 dodoc,
430 "\n",
431 "override_dh_install:\n",
432 "\tdh_install *.g ",installdir," ",pkgbaseN,"\n",
433 "\tmake -C doc install DESTDIR=../debian/",binname,"\n",
434 "\n",
435 "override_dh_installdocs:\n",
436 "\tdh_installdocs ",readme,"\n",
437 "\n",
438 "override_dh_installchangelogs:\n",
439 "\tdh_installchangelogs ",changes,"\n",
440 "\n",
441 "override_dh_clean:\n",
442 "\tmake -C doc clean\n",
443 cleantest,
444 "\tdh_clean\n",
445 "\n",
446 "%:\n",
447 "\tdh $@\n",
448 "\n",
449 ".PHONY: execute_after_dh_auto_test execute_after_dh_auto_build override_dh_install override_dh_clean override_dh_installdocs override_dh_installchangelogs \n"));
450 else
451 FileString("debian.gap2deb/rules", Concatenation(
452 "#!/usr/bin/make -f\n",
453 "# Copyright ",year," ",maint,"\n",
454 "\n",
455 "export SOURCE_DATE_EPOCH = $(shell date -d \"$$(dpkg-parsechangelog -SDate)\" +%s)\n",
456 "export FORCE_SOURCE_DATE = 1\n",
457 "export LC_ALL = C\n",
458 "\n",
459 "build-indep-stamp:\n",
460 dotest,
461 dodoc,
462 "build-indep: build-indep-stamp\n",
463 "build-arch:\n",
464 "build: build-indep\n",
465 "\n",
466 "clean:\n",
467 "\tdh_testdir\n",
468 "\tdh_testroot\n",
469 "\tmake -C doc clean\n",
470 "\trm -f build-indep-stamp\n",
471 cleantest,
472 "\tdh_clean\n",
473 "\n",
474 "install: build\n",
475 "\tdh_testdir\n",
476 "\tdh_testroot\n",
477 "\tdh_prep\n",
478 "\tdh_installdirs\n",
479 "\tdh_install *.g ",installdir," ",pkgbaseN,"\n",
480 "\tmake -C doc install DESTDIR=../debian/",binname,"\n",
481 "binary-arch: build-arch\n",
482 "binary-indep: build-indep install\n",
483 "\tdh_testdir\n",
484 "\tdh_testroot\n",
485 "\tdh_installdocs ",readme,"\n",
486 "\tdh_installexamples\n",
487 "\tdh_installchangelogs",changes,"\n",
488 "\tdh_link\n",
489 "\tdh_compress\n",
490 "\tdh_fixperms\n",
491 "\tdh_installdeb\n",
492 "\tdh_gencontrol\n",
493 "\tdh_md5sums\n",
494 "\tdh_builddeb\n",
495 "\n",
496 "binary: binary-indep binary-arch\n",
497 ".PHONY: build clean binary-indep binary-arch binary install configure\n"));
498 fi;
499
500
501 if not IsDirectoryPath("debian") then
502 Process(DirectoryCurrent(), "/bin/mv", InputTextNone(), OutputTextNone(),
503 ["debian.gap2deb","debian"]);
504 fi;
505
506 QUIT_GAP(0);