build-pkg: take target common files to a package

There are documentation and other shared files installed,
which we don't need [1]. Some packages install files to same
paths. There is a list of all packages which overlap and
shared files [2].

Create a list of packages which have common files across
targets. Some of them are a part of compiler chain (gcc-*),
some are built natively intentionally:

 * gcc-isl
 * gcc-mpc
 * gcc-gmp
 * gcc-mpfr
 * gcc
 * yasm
 * ncurses
 * pkgconf

[1] https://lists.nongnu.org/archive/html/mingw-cross-env-list/2015-06/msg00011.html
[2] https://gist.github.com/starius/59625347cd68a21d9cc9

close #763
close #757
pull/792/head
Boris Nagaev 9 years ago
parent 45cf672636
commit 1989e48348

@ -20,6 +20,42 @@ local BLACKLIST = {
'^usr/share/', '^usr/share/',
} }
local COMMON_FILES = {
['gcc-isl'] = {
'^usr/include/isl/',
'^usr/lib/libisl%.',
'^usr/lib/pkgconfig/isl.pc$',
},
['gcc-mpc'] = {
'^usr/include/mpc.h$',
'^usr/lib/libmpc%.',
},
['gcc-gmp'] = {
'^usr/include/gmp.h$',
'^usr/lib/libgmp%.',
},
['gcc-mpfr'] = {
'^usr/include/mpf2mpfr.h$',
'^usr/include/mpfr.h$',
'^usr/lib/libmpfr%.',
},
['gcc'] = {
'^usr/lib/libcc1%.',
},
['yasm'] = {
'^usr/include/libyasm',
'^usr/lib/libyasm.a$',
},
['ncurses'] = {
'^usr/lib/pkgconfig/',
},
['pkgconf'] = {
'^usr/bin/config.guess$',
},
}
local ARCH_FOR_COMMON = 'i686-w64-mingw32.static'
local target -- used by many functions local target -- used by many functions
local function log(...) local function log(...)
@ -135,8 +171,8 @@ local function sortForBuild(pkgs, pkg2deps)
return build_list return build_list
end end
local function isBlacklisted(file) local function isListed(file, list)
for _, pattern in ipairs(BLACKLIST) do for _, pattern in ipairs(list) do
if file:match(pattern) then if file:match(pattern) then
return true return true
end end
@ -144,6 +180,10 @@ local function isBlacklisted(file)
return false return false
end end
local function isBlacklisted(file)
return isListed(file, BLACKLIST)
end
-- return set of all filepaths under ./usr/ -- return set of all filepaths under ./usr/
local function findFiles() local function findFiles()
local files = {} local files = {}
@ -173,9 +213,9 @@ local function buildPackage(pkg)
return new_files return new_files
end end
local function nameToDebian(pkg) local function nameToDebian(pkg, t)
local name = 'mxe-%s-%s' local name = 'mxe-%s-%s'
name = name:format(target, pkg) name = name:format(t or target, pkg)
name = name:gsub('_', '-') name = name:gsub('_', '-')
return name return name
end end
@ -206,7 +246,7 @@ Description: MXE package %s for %s
This package contains the files for MXE package %s. This package contains the files for MXE package %s.
]] ]]
local function makeDeb(pkg, list_path, deps, ver) local function makeDeb(pkg, list_path, deps, ver, add_common)
local deb_pkg = nameToDebian(pkg) local deb_pkg = nameToDebian(pkg)
local dirname = ('%s_%s'):format(deb_pkg, local dirname = ('%s_%s'):format(deb_pkg,
protectVersion(ver)) protectVersion(ver))
@ -225,6 +265,9 @@ local function makeDeb(pkg, list_path, deps, ver)
for _, dep in ipairs(deps) do for _, dep in ipairs(deps) do
table.insert(deb_deps, nameToDebian(dep)) table.insert(deb_deps, nameToDebian(dep))
end end
if add_common then
table.insert(deb_deps, nameToDebian(pkg, 'common'))
end
local deb_deps_str = table.concat(deb_deps, ', ') local deb_deps_str = table.concat(deb_deps, ', ')
-- make DEBIAN/control file -- make DEBIAN/control file
os.execute(('mkdir -p %s/DEBIAN'):format(dirname)) os.execute(('mkdir -p %s/DEBIAN'):format(dirname))
@ -240,8 +283,15 @@ local function makeDeb(pkg, list_path, deps, ver)
os.execute(('rm -fr %s deb.fakeroot'):format(dirname)) os.execute(('rm -fr %s deb.fakeroot'):format(dirname))
end end
local function saveFileList(pkg, list) local function readFileList(list_file)
local list_file = pkg .. '.list' local list = {}
for installed_file in io.lines(list_file) do
table.insert(list, installed_file)
end
return list
end
local function saveFileList(list_file, list)
local file = io.open(list_file, 'w') local file = io.open(list_file, 'w')
for _, installed_file in ipairs(list) do for _, installed_file in ipairs(list) do
file:write(installed_file .. '\n') file:write(installed_file .. '\n')
@ -265,7 +315,7 @@ local function buildPackages(pkgs, pkg2deps)
if not brokenDep(pkg) then if not brokenDep(pkg) then
local files = buildPackage(pkg) local files = buildPackage(pkg)
if #files > 0 then if #files > 0 then
saveFileList(pkg, files) saveFileList(pkg .. '.list', files)
table.insert(unbroken, pkg) table.insert(unbroken, pkg)
else else
-- broken package -- broken package
@ -280,11 +330,48 @@ local function buildPackages(pkgs, pkg2deps)
return unbroken return unbroken
end end
local function filterFiles(pkg, filter_common)
local list = readFileList(pkg .. '.list')
local list2 = {}
local common_list = COMMON_FILES[pkg]
for _, installed_file in ipairs(list) do
local listed = isListed(installed_file, common_list)
if listed == filter_common then
table.insert(list2, installed_file)
end
end
return list2
end
local function excludeCommon(pkg)
local noncommon_files = filterFiles(pkg, false)
saveFileList(pkg .. '.list', noncommon_files)
end
local function makeCommonDeb(pkg, ver)
local common_files = filterFiles(pkg, true)
local list_path = pkg .. '.common-list'
saveFileList(list_path, common_files)
local orig_target = target
target = 'common'
makeDeb(pkg, list_path, {}, ver)
target = orig_target
end
local function makeDebs(pkgs, pkg2deps, pkg2ver) local function makeDebs(pkgs, pkg2deps, pkg2ver)
for _, pkg in ipairs(pkgs) do for _, pkg in ipairs(pkgs) do
local deps = assert(pkg2deps[pkg], pkg) local deps = assert(pkg2deps[pkg], pkg)
local ver = assert(pkg2ver[pkg], pkg) local ver = assert(pkg2ver[pkg], pkg)
makeDeb(pkg, pkg .. '.list', deps, ver) local list_path = pkg .. '.list'
local add_common = false
if COMMON_FILES[pkg] then
if target == ARCH_FOR_COMMON then
makeCommonDeb(pkg, ver)
end
add_common = true
excludeCommon(pkg)
end
makeDeb(pkg, list_path, deps, ver, add_common)
end end
end end

Loading…
Cancel
Save