The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
7.1 KiB
164 lines
7.1 KiB
10 years ago
|
# Copyright 2015 The Meson development team
|
||
|
|
||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
# you may not use this file except in compliance with the License.
|
||
|
# You may obtain a copy of the License at
|
||
|
|
||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
# Unless required by applicable law or agreed to in writing, software
|
||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
# See the License for the specific language governing permissions and
|
||
|
# limitations under the License.
|
||
|
|
||
|
'''This module provides helper functions for RPM related
|
||
10 years ago
|
functionality such as generating template RPM spec file.'''
|
||
10 years ago
|
|
||
9 years ago
|
from .. import build
|
||
|
from .. import compilers
|
||
|
from .. import datetime
|
||
|
from .. import mlog
|
||
|
from .. import modules.gnome
|
||
10 years ago
|
import os
|
||
10 years ago
|
|
||
|
class RPMModule:
|
||
|
|
||
10 years ago
|
def generate_spec_template(self, state, args, kwargs):
|
||
10 years ago
|
compiler_deps = set()
|
||
|
for compiler in state.compilers:
|
||
10 years ago
|
if isinstance(compiler, compilers.GnuCCompiler):
|
||
|
compiler_deps.add('gcc')
|
||
|
elif isinstance(compiler, compilers.GnuCPPCompiler):
|
||
|
compiler_deps.add('gcc-c++')
|
||
|
elif isinstance(compiler, compilers.ValaCompiler):
|
||
10 years ago
|
compiler_deps.add('vala')
|
||
|
elif isinstance(compiler, compilers.GnuFortranCompiler):
|
||
|
compiler_deps.add('gcc-gfortran')
|
||
|
elif isinstance(compiler, compilers.GnuObjCCompiler):
|
||
|
compiler_deps.add('gcc-objc')
|
||
|
elif compiler == compilers.GnuObjCPPCompiler:
|
||
|
compiler_deps.add('gcc-objc++')
|
||
|
else:
|
||
|
mlog.log('RPM spec file will not created, generating not allowed for:',
|
||
|
mlog.bold(compiler.get_id()))
|
||
|
return
|
||
10 years ago
|
proj = state.project_name.replace(' ', '_').replace('\t', '_')
|
||
10 years ago
|
so_installed = False
|
||
|
devel_subpkg = False
|
||
10 years ago
|
files = set()
|
||
|
files_devel = set()
|
||
|
to_delete = set()
|
||
10 years ago
|
for target in state.targets.values():
|
||
|
if isinstance(target, build.Executable) and target.need_install:
|
||
10 years ago
|
files.add('%%{_bindir}/%s' % target.get_filename())
|
||
10 years ago
|
elif isinstance(target, build.SharedLibrary) and target.need_install:
|
||
10 years ago
|
files.add('%%{_libdir}/%s' % target.get_filename())
|
||
10 years ago
|
for alias in target.get_aliaslist():
|
||
|
if alias.endswith('.so'):
|
||
10 years ago
|
files_devel.add('%%{_libdir}/%s' % alias)
|
||
10 years ago
|
else:
|
||
10 years ago
|
files.add('%%{_libdir}/%s' % alias)
|
||
10 years ago
|
so_installed = True
|
||
|
elif isinstance(target, build.StaticLibrary) and target.need_install:
|
||
10 years ago
|
to_delete.add('%%{buildroot}%%{_libdir}/%s' % target.get_filename())
|
||
10 years ago
|
mlog.log('Warning, removing', mlog.bold(target.get_filename()),
|
||
|
'from package because packaging static libs not recommended')
|
||
10 years ago
|
elif isinstance(target, modules.gnome.GirTarget) and target.should_install():
|
||
|
files_devel.add('%%{_datadir}/gir-1.0/%s' % target.get_filename()[0])
|
||
|
elif isinstance(target, modules.gnome.TypelibTarget) and target.should_install():
|
||
|
files.add('%%{_libdir}/girepository-1.0/%s' % target.get_filename()[0])
|
||
10 years ago
|
for header in state.headers:
|
||
10 years ago
|
if len(header.get_install_subdir()) > 0:
|
||
10 years ago
|
files_devel.add('%%{_includedir}/%s/' % header.get_install_subdir())
|
||
10 years ago
|
else:
|
||
|
for hdr_src in header.get_sources():
|
||
10 years ago
|
files_devel.add('%%{_includedir}/%s' % hdr_src)
|
||
10 years ago
|
for man in state.man:
|
||
|
for man_file in man.get_sources():
|
||
10 years ago
|
files.add('%%{_mandir}/man%u/%s.*' % (int(man_file.split('.')[-1]), man_file))
|
||
10 years ago
|
for pkgconfig in state.pkgconfig_gens:
|
||
|
files_devel.add('%%{_libdir}/pkgconfig/%s.pc' % pkgconfig.filebase)
|
||
10 years ago
|
if len(files_devel) > 0:
|
||
|
devel_subpkg = True
|
||
10 years ago
|
fn = open('%s.spec' % os.path.join(state.environment.get_build_dir(), proj), 'w+')
|
||
10 years ago
|
fn.write('Name: %s\n' % proj)
|
||
10 years ago
|
fn.write('Version: # FIXME\n')
|
||
|
fn.write('Release: 1%{?dist}\n')
|
||
|
fn.write('Summary: # FIXME\n')
|
||
|
fn.write('License: # FIXME\n')
|
||
|
fn.write('\n')
|
||
|
fn.write('Source0: %{name}-%{version}.tar.xz # FIXME\n')
|
||
10 years ago
|
fn.write('\n')
|
||
10 years ago
|
for compiler in compiler_deps:
|
||
|
fn.write('BuildRequires: %s\n' % compiler)
|
||
10 years ago
|
for dep in state.environment.coredata.deps:
|
||
|
fn.write('BuildRequires: pkgconfig(%s)\n' % dep)
|
||
|
for lib in state.environment.coredata.ext_libs.values():
|
||
|
fn.write('BuildRequires: %s # FIXME\n' % lib.fullpath)
|
||
|
mlog.log('Warning, replace', mlog.bold(lib.fullpath), 'with real package.',
|
||
|
'You can use following command to find package which contains this lib:',
|
||
|
mlog.bold('dnf provides %s' % lib.fullpath))
|
||
|
for prog in state.environment.coredata.ext_progs.values():
|
||
10 years ago
|
if not prog.found():
|
||
|
fn.write('BuildRequires: /usr/bin/%s # FIXME\n' % prog.get_name())
|
||
|
else:
|
||
|
fn.write('BuildRequires: %s\n' % ' '.join(prog.fullpath))
|
||
10 years ago
|
fn.write('BuildRequires: meson\n')
|
||
|
fn.write('\n')
|
||
10 years ago
|
fn.write('%description\n')
|
||
|
fn.write('\n')
|
||
|
if devel_subpkg:
|
||
|
fn.write('%package devel\n')
|
||
10 years ago
|
fn.write('Summary: Development files for %{name}\n')
|
||
10 years ago
|
fn.write('Requires: %{name}%{?_isa} = %{version}-%{release}\n')
|
||
|
fn.write('\n')
|
||
|
fn.write('%description devel\n')
|
||
10 years ago
|
fn.write('Development files for %{name}.\n')
|
||
10 years ago
|
fn.write('\n')
|
||
10 years ago
|
fn.write('%prep\n')
|
||
|
fn.write('%autosetup\n')
|
||
10 years ago
|
fn.write('rm -rf rpmbuilddir && mkdir rpmbuilddir\n')
|
||
10 years ago
|
fn.write('\n')
|
||
|
fn.write('%build\n')
|
||
10 years ago
|
fn.write('pushd rpmbuilddir\n')
|
||
10 years ago
|
fn.write(' %meson ..\n')
|
||
10 years ago
|
fn.write(' ninja-build -v\n')
|
||
|
fn.write('popd\n')
|
||
|
fn.write('\n')
|
||
10 years ago
|
fn.write('%install\n')
|
||
10 years ago
|
fn.write('pushd rpmbuilddir\n')
|
||
10 years ago
|
fn.write(' DESTDIR=%{buildroot} ninja-build -v install\n')
|
||
|
fn.write('popd\n')
|
||
10 years ago
|
if len(to_delete) > 0:
|
||
|
fn.write('rm -rf %s\n' % ' '.join(to_delete))
|
||
10 years ago
|
fn.write('\n')
|
||
10 years ago
|
fn.write('%check\n')
|
||
|
fn.write('pushd rpmbuilddir\n')
|
||
|
fn.write(' ninja-build -v test\n')
|
||
|
fn.write('popd\n')
|
||
|
fn.write('\n')
|
||
10 years ago
|
fn.write('%files\n')
|
||
10 years ago
|
for f in files:
|
||
|
fn.write('%s\n' % f)
|
||
|
fn.write('\n')
|
||
|
if devel_subpkg:
|
||
|
fn.write('%files devel\n')
|
||
|
for f in files_devel:
|
||
|
fn.write('%s\n' % f)
|
||
10 years ago
|
fn.write('\n')
|
||
10 years ago
|
if so_installed:
|
||
10 years ago
|
fn.write('%post -p /sbin/ldconfig\n')
|
||
|
fn.write('\n')
|
||
|
fn.write('%postun -p /sbin/ldconfig\n')
|
||
10 years ago
|
fn.write('\n')
|
||
10 years ago
|
fn.write('%changelog\n')
|
||
|
fn.write('* %s meson <meson@example.com> - \n' % datetime.date.today().strftime('%a %b %d %Y'))
|
||
|
fn.write('- \n')
|
||
|
fn.write('\n')
|
||
10 years ago
|
fn.close()
|
||
10 years ago
|
mlog.log('RPM spec template written to %s.spec.\n' % proj)
|
||
10 years ago
|
|
||
|
def initialize():
|
||
|
return RPMModule()
|