aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjpakkane <jpakkane@gmail.com>2015-03-21 14:25:42 +0200
committerjpakkane <jpakkane@gmail.com>2015-03-21 14:25:42 +0200
commita5f30e73c626b4c9284a390669322317a07a6f91 (patch)
tree3c8f68dabeca71ae7e0b51c71d2daefec8ad0c64
parentdd519525ecfc6253b2472b6810213568f05a5c4b (diff)
parentb71d248b28203a294ba6e3ba32ed9c6d36d3209b (diff)
downloadmeson-a5f30e73c626b4c9284a390669322317a07a6f91.zip
meson-a5f30e73c626b4c9284a390669322317a07a6f91.tar.gz
meson-a5f30e73c626b4c9284a390669322317a07a6f91.tar.bz2
Merge pull request #52 from ignatenkobrain/wip/rpm
add RPM module (Closes #49)
-rw-r--r--authors.txt1
-rwxr-xr-xinstall_meson.py6
-rw-r--r--interpreter.py6
-rw-r--r--macros.meson11
-rw-r--r--manual tests/5 rpm/lib.c6
-rw-r--r--manual tests/5 rpm/lib.h1
-rw-r--r--manual tests/5 rpm/main.c8
-rw-r--r--manual tests/5 rpm/meson.build13
-rw-r--r--modules/rpm.py155
9 files changed, 207 insertions, 0 deletions
diff --git a/authors.txt b/authors.txt
index 85a4770..8b0396c 100644
--- a/authors.txt
+++ b/authors.txt
@@ -10,3 +10,4 @@ Masashi Fujita
Juhani Simola
Robin McCorkell
Axel Waggershauser
+Igor Gnatenko
diff --git a/install_meson.py b/install_meson.py
index 6a1efdf..298de96 100755
--- a/install_meson.py
+++ b/install_meson.py
@@ -54,6 +54,7 @@ in_guimanfile = 'man/mesongui.1'
out_guimanfile = os.path.join(man_dir, 'mesongui.1.gz')
in_confmanfile = 'man/mesonconf.1'
out_confmanfile = os.path.join(man_dir, 'mesonconf.1.gz')
+rpmmacros_dir = os.path.join(install_root, 'lib/rpm/macros.d')
symlink_value = os.path.relpath(bin_script, os.path.dirname(bin_name))
guisymlink_value = os.path.relpath(gui_script, os.path.dirname(gui_name))
@@ -105,3 +106,8 @@ if os.path.exists('modules/__pycache__'):
if os.path.exists(module_dir):
shutil.rmtree(module_dir)
shutil.copytree('modules', module_dir)
+
+print('Installing RPM macros to %s.' % rpmmacros_dir)
+outfilename = os.path.join(rpmmacros_dir, 'macros.meson')
+shutil.copyfile('macros.meson', outfilename)
+shutil.copystat('macros.meson', outfilename)
diff --git a/interpreter.py b/interpreter.py
index 98875ce..9aae7a4 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -616,6 +616,12 @@ class ModuleHolder(InterpreterObject):
self.interpreter.environment.get_build_dir())
state.subdir = self.interpreter.subdir
state.environment = self.interpreter.environment
+ state.project_name = self.interpreter.build.project_name
+ state.compilers = self.interpreter.build.compilers
+ state.targets = self.interpreter.build.targets
+ state.headers = self.interpreter.build.get_headers()
+ state.man = self.interpreter.build.get_man()
+ state.pkgconfig_gens = self.interpreter.build.pkgconfig_gens
value = fn(state, args, kwargs)
return self.interpreter.module_method_callback(value)
diff --git a/macros.meson b/macros.meson
new file mode 100644
index 0000000..42ad949
--- /dev/null
+++ b/macros.meson
@@ -0,0 +1,11 @@
+%__meson /usr/bin/meson
+
+%meson \
+ CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
+ CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
+ FFLAGS="${FFLAGS:-%optflags%{?_fmoddir: -I%_fmoddir}}" ; export FFLAGS ; \
+ FCFLAGS="${FCFLAGS:-%optflags%{?_fmoddir: -I%_fmoddir}}" ; export FCFLAGS ; \
+ %{?__global_ldflags:LDFLAGS="${LDFLAGS:-%__global_ldflags}" ; export LDFLAGS ;} \
+ %__meson \\\
+ --prefix=%{_prefix} \\\
+ --buildtype=plain
diff --git a/manual tests/5 rpm/lib.c b/manual tests/5 rpm/lib.c
new file mode 100644
index 0000000..efc230a
--- /dev/null
+++ b/manual tests/5 rpm/lib.c
@@ -0,0 +1,6 @@
+#include"lib.h"
+
+char *meson_print(void)
+{
+ return "Hello, world!";
+}
diff --git a/manual tests/5 rpm/lib.h b/manual tests/5 rpm/lib.h
new file mode 100644
index 0000000..08fc961
--- /dev/null
+++ b/manual tests/5 rpm/lib.h
@@ -0,0 +1 @@
+char *meson_print(void);
diff --git a/manual tests/5 rpm/main.c b/manual tests/5 rpm/main.c
new file mode 100644
index 0000000..5c46721
--- /dev/null
+++ b/manual tests/5 rpm/main.c
@@ -0,0 +1,8 @@
+#include<lib.h>
+#include<stdio.h>
+int main(int argc, char **argv)
+{
+ char *t = meson_print();
+ printf("%s", t);
+ return 0;
+}
diff --git a/manual tests/5 rpm/meson.build b/manual tests/5 rpm/meson.build
new file mode 100644
index 0000000..ebbbdfd
--- /dev/null
+++ b/manual tests/5 rpm/meson.build
@@ -0,0 +1,13 @@
+project('test spec', 'c')
+
+rpm = import('rpm')
+dependency('zlib')
+
+lib = shared_library('mesontest_shared', ['lib.c', 'lib.h'],
+ version : '0.1', soversion : '0',
+ install : true)
+executable('mesontest-bin', 'main.c',
+ link_with : lib,
+ install : true)
+
+rpm.generate_spec_template()
diff --git a/modules/rpm.py b/modules/rpm.py
new file mode 100644
index 0000000..57c1de5
--- /dev/null
+++ b/modules/rpm.py
@@ -0,0 +1,155 @@
+# 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
+functionality such as generating template RPM spec file.'''
+
+import build
+import compilers
+import datetime
+import mlog
+import os
+
+class RPMModule:
+
+ def generate_spec_template(self, state, args, kwargs):
+ compiler_deps = set()
+ for compiler in state.compilers:
+ if isinstance(compiler, compilers.ValaCompiler):
+ 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++')
+ elif isinstance(compiler, (compilers.GnuCCompiler, compilers.GnuCPPCompiler)):
+ # Installed by default
+ pass
+ else:
+ mlog.log('RPM spec file will not created, generating not allowed for:',
+ mlog.bold(compiler.get_id()))
+ return
+ proj = state.project_name.replace(' ', '_').replace('\t', '_')
+ so_installed = False
+ devel_subpkg = False
+ files = set()
+ files_devel = set()
+ to_delete = set()
+ for target in state.targets.values():
+ if isinstance(target, build.Executable) and target.need_install:
+ files.add('%%{_bindir}/%s' % target.get_filename())
+ elif isinstance(target, build.SharedLibrary) and target.need_install:
+ files.add('%%{_libdir}/%s' % target.get_filename())
+ for alias in target.get_aliaslist():
+ if alias.endswith('.so'):
+ files_devel.add('%%{_libdir}/%s' % alias)
+ else:
+ files.add('%%{_libdir}/%s' % alias)
+ so_installed = True
+ elif isinstance(target, build.StaticLibrary) and target.need_install:
+ to_delete.add('%%{buildroot}%%{_libdir}/%s' % target.get_filename())
+ mlog.log('Warning, removing', mlog.bold(target.get_filename()),
+ 'from package because packaging static libs not recommended')
+ for header in state.headers:
+ if len(header.get_install_subdir()) > 0:
+ files_devel.add('%%{_includedir}/%s/' % header.get_install_subdir())
+ else:
+ for hdr_src in header.get_sources():
+ files_devel.add('%%{_includedir}/%s' % hdr_src)
+ for man in state.man:
+ for man_file in man.get_sources():
+ files.add('%%{_mandir}/man%u/%s.*' % (int(man_file.split('.')[-1]), man_file))
+ for pkgconfig in state.pkgconfig_gens:
+ files_devel.add('%%{_libdir}/pkgconfig/%s.pc' % pkgconfig.filebase)
+ if len(files_devel) > 0:
+ devel_subpkg = True
+ fn = open('%s.spec' % os.path.join(state.environment.get_build_dir(), proj),
+ 'w+')
+ fn.write('Name: %s\n' % proj)
+ 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')
+ fn.write('\n')
+ for compiler in compiler_deps:
+ fn.write('BuildRequires: %s\n' % compiler)
+ 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():
+ fn.write('BuildRequires: %s\n' % ' '.join(prog.fullpath))
+ fn.write('BuildRequires: meson\n')
+ fn.write('\n')
+ fn.write('%description\n')
+ fn.write('\n')
+ if devel_subpkg:
+ fn.write('%package devel\n')
+ fn.write('Summary: Development files for %{name}\n')
+ fn.write('Requires: %{name}%{?_isa} = %{version}-%{release}\n')
+ fn.write('\n')
+ fn.write('%description devel\n')
+ fn.write('Development files for %{name}.\n')
+ fn.write('\n')
+ fn.write('%prep\n')
+ fn.write('%autosetup\n')
+ fn.write('rm -rf rpmbuilddir && mkdir rpmbuilddir\n')
+ fn.write('\n')
+ fn.write('%build\n')
+ fn.write('pushd rpmbuilddir\n')
+ fn.write(' %meson ..\n')
+ fn.write(' ninja-build -v\n')
+ fn.write('popd\n')
+ fn.write('\n')
+ fn.write('%install\n')
+ fn.write('pushd rpmbuilddir\n')
+ fn.write(' DESTDIR=%{buildroot} ninja-build -v install\n')
+ fn.write('popd\n')
+ if len(to_delete) > 0:
+ fn.write('rm -rf %s\n' % ' '.join(to_delete))
+ fn.write('\n')
+ fn.write('%check\n')
+ fn.write('pushd rpmbuilddir\n')
+ fn.write(' ninja-build -v test\n')
+ fn.write('popd\n')
+ fn.write('\n')
+ fn.write('%files\n')
+ 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)
+ fn.write('\n')
+ if so_installed:
+ fn.write('%post -p /sbin/ldconfig\n')
+ fn.write('\n')
+ fn.write('%postun -p /sbin/ldconfig\n')
+ fn.write('\n')
+ 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')
+ fn.close()
+ mlog.log('Please, look at RPM spec file and fix FIXME\'s')
+
+def initialize():
+ return RPMModule()