File: build.m

package info (click to toggle)
octave 4.4.1-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 114,832 kB
  • sloc: cpp: 310,009; ansic: 54,616; fortran: 22,631; yacc: 8,706; sh: 8,231; objc: 7,972; lex: 3,897; perl: 1,540; java: 1,309; awk: 1,070; makefile: 415; xml: 59
file content (94 lines) | stat: -rw-r--r-- 3,427 bytes parent folder | download | duplicates (3)
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
## Copyright (C) 2016-2018 Carnë Draug
##
## This file is part of Octave.
##
## Octave 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 3 of the License, or
## (at your option) any later version.
##
## Octave 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.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <https://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {} build (@var{builddir}, @var{tarballs}, @var{verbose})
## Prepare binary packages from Octave source packages.
##
## Boils down to (for each in @var{tarballs}):
##
## @enumerate
## @item untar the tarball in @var{builddir};
##
## @item build anything necessary (configure and make);
##
## @item repackage specifying the build arch in the tarball filename.
## @end enumerate
##
## @end deftypefn

function build (builddir, tarballs, verbose)

  if (nargin != 3)
    print_usage ();
  endif

  if (! exist (builddir, "dir"))
    warning ("creating build directory %s", builddir);
    [status, msg] = mkdir (builddir);
    if (status != 1)
      error ("could not create installation directory: %s", msg);
    endif
  endif

  for i = 1:numel(tarballs)
    filelist = unpack (tarballs{i}, builddir);

    ## We want the path for the package root but we can't assume that
    ## exists in the filelist (see patch #9030).  So we deduce it from
    ## the path of the DESCRIPTION file (smallest in case there's another
    ## file named DESCRIPTION somewhere).
    desc_pos = regexp (filelist, "DESCRIPTION$");
    desc_mask = ! cellfun ("isempty", desc_pos);
    [~, desc_r_idx] = min ([desc_pos{desc_mask}]);
    desc_path = fullfile (builddir, filelist(desc_mask){desc_r_idx});
    build_root = desc_path(1:end-12); # do not include the last filesep

    desc = get_description (desc_path);

    ## If there is no configure or Makefile within src/, there is nothing
    ## to do to prepare a "binary" package.  We only repackage to add more
    ## info to the tarball filename (version and arch).
    if (! exist (fullfile (build_root, "src", "configure"), "file")
        && ! exist (fullfile (build_root, "src", "Makefile"), "file"))
      arch_abi = "any-none";
    else
      arch_abi = getarch ();
      configure_make (desc, build_root, verbose);
      unlink (fullfile (build_root, "src", "configure"));
      unlink (fullfile (build_root, "src", "Makefile"));
    endif
    tar_name = [desc.name "-" desc.version "-" arch_abi ".tar"];
    tar_path = fullfile (builddir, tar_name);

    ## Figure out the directory name of the build.  Note that fileparts
    ## gets confused with the version string (the periods makes it think
    ## it's a file extension).
    [~, package_root, package_ext] = fileparts (build_root);
    package_root = [package_root, package_ext];

    tar (tar_path, package_root, builddir);
    gzip (tar_path, builddir);
    rmdir (build_root, "s");

    ## Currently does nothing because gzip() removes the original tar
    ## file but that should change in the future (bug #43431).
    unlink (tar_path);
  endfor

endfunction