Skip to content

Commit

Permalink
Port to Meson (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed May 20, 2017
1 parent 6084f2f commit 1316e28
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 6 deletions.
19 changes: 19 additions & 0 deletions config.h.meson
@@ -0,0 +1,19 @@
/* config.h.in. Generated from configure.ac by autoheader. */

/* Define to 1 if OS is Android based. */
#mesondefine HAVE_ANDROID

/* Define to 1 if OS is Darwin based. */
#mesondefine HAVE_DARWIN

/* Define to 1 if OS is iOS. */
#mesondefine HAVE_IOS

/* Define to 1 if OS is Linux based. */
#mesondefine HAVE_LINUX

/* Define to 1 if OS is macOS. */
#mesondefine HAVE_MACOS

/* Define to 1 if OS is QNX based. */
#mesondefine HAVE_QNX
98 changes: 98 additions & 0 deletions meson.build
@@ -0,0 +1,98 @@
project('frida-python', 'c', version: '1.0.0')

host_os_family = ''
host_os = host_machine.system()
host_is_64bit = host_machine.cpu_family() == 'x86_64' or host_machine.cpu_family() == 'arm64'

if not meson.is_cross_build()
target_conditionals_prefix = '#include <TargetConditionals.h>'

is_macos_src = target_conditionals_prefix + '''
#if !TARGET_OS_OSX
# error Not macOS
#endif
'''
if cc.compiles(is_macos_src, name: 'compiling for macOS')
host_os = 'macos'
endif

is_ios_src = target_conditionals_prefix + '''
#if !TARGET_OS_IOS
# error Not iOS
#endif
'''
if cc.compiles(is_ios_src, name: 'compiling for iOS')
host_os = 'ios'
endif

if cc.has_header('android/api-level.h')
host_os = 'android'
endif
endif

os_families = [
['windows', 'windows'],
['macos', 'darwin'],
['linux', 'linux'],
['ios', 'darwin'],
['android', 'linux'],
['qnx', 'qnx'],
]
foreach f : os_families
if f.get(0) == host_os
host_os_family = f.get(1)
endif
endforeach

if host_os_family == ''
error('Unsupported OS')
endif

python = get_option('with-python')
if python == ''
python = find_program('python3', required: false)
if not python.found()
python = find_program('python')
endif
endif

result = run_command(python, '-c',
'import sys; sys.stdout.write("%d.%d" % (sys.version_info[0], sys.version_info[1]))')
if result.returncode() != 0
error('Unable to detect Python version: ' + result.stdout() + result.stderr())
endif
python_version = result.stdout()

python_name = 'python' + python_version
python_site_packages = join_paths(get_option('libdir'), python_name, 'site-packages')

result = run_command(python, '-c',
'from distutils import sysconfig; import sys; sys.stdout.write(sysconfig.get_python_inc())')
if result.returncode() != 0
error('Unable to detect Python include directory: ' + result.stdout() + result.stderr())
endif
python_incdir = result.stdout()

result = run_command(python, '-c', 'import sys;\n' +
'sys.stdout.write("PyInit__frida" if sys.version_info[0] >= 3 else "init_frida")')
if result.returncode() != 0
error('Unable to detect Python plugin export name: ' + result.stdout() + result.stderr())
endif
python_plugin_export_name = result.stdout()

cc = meson.get_compiler('c')

cdata = configuration_data()

cdata.set('HAVE_' + host_os_family.to_upper(), 1)
if host_os != host_os_family
cdata.set('HAVE_' + host_os.to_upper(), 1)
endif

frida_core_dep = dependency('frida-core-1.0')

configure_file(input: 'config.h.meson',
output: 'config.h',
configuration: cdata)

subdir('src')
1 change: 1 addition & 0 deletions meson_options.txt
@@ -0,0 +1 @@
option('with-python', type: 'string', description: 'Python interpreter to build for')
8 changes: 8 additions & 0 deletions src/_frida.version
@@ -0,0 +1,8 @@
FRIDA_PYTHON {
global:
PyInit__frida;
init_frida;

local:
*;
};
13 changes: 13 additions & 0 deletions src/frida/meson.build
@@ -0,0 +1,13 @@
frida_sources = [
'__init__.py',
'application.py',
'core.py',
'discoverer.py',
'kill.py',
'lsd.py',
'ps.py',
'repl.py',
'tracer.py',
]

install_data(frida_sources, install_dir: join_paths(python_site_packages, 'frida'))
19 changes: 19 additions & 0 deletions src/meson.build
@@ -0,0 +1,19 @@
subdir('frida')
subdir('scripts')

extra_link_args = []
if host_os_family == 'darwin'
extra_link_args += ['-Wl,-exported_symbol,_' + python_plugin_export_name]
elif host_os_family != 'windows'
extra_link_args += ['-Wl,--version-script,' + join_paths(meson.current_source_dir(), '_frida.version')]
endif

extension = shared_module('_frida', '_frida.c',
name_prefix: '',
name_suffix: 'so',
include_directories: include_directories(python_incdir),
link_args: extra_link_args,
dependencies: [frida_core_dep],
install: true,
install_dir: python_site_packages,
)
3 changes: 2 additions & 1 deletion src/scripts/frida-discover.in
@@ -1,7 +1,8 @@
#!@PYTHON@

from os.path import dirname, join, realpath
import sys
sys.path.insert(1, '@pythondir@')
sys.path.insert(1, join(dirname(dirname(realpath(__file__))), '@pythondir@'))

import frida
import frida.discoverer
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/frida-kill.in
@@ -1,7 +1,8 @@
#!@PYTHON@

from os.path import dirname, join, realpath
import sys
sys.path.insert(1, '@pythondir@')
sys.path.insert(1, join(dirname(dirname(realpath(__file__))), '@pythondir@'))

import frida.kill

Expand Down
3 changes: 2 additions & 1 deletion src/scripts/frida-ls-devices.in
@@ -1,7 +1,8 @@
#!@PYTHON@

from os.path import dirname, join, realpath
import sys
sys.path.insert(1, '@pythondir@')
sys.path.insert(1, join(dirname(dirname(realpath(__file__))), '@pythondir@'))

import frida.lsd

Expand Down
3 changes: 2 additions & 1 deletion src/scripts/frida-ps.in
@@ -1,7 +1,8 @@
#!@PYTHON@

from os.path import dirname, join, realpath
import sys
sys.path.insert(1, '@pythondir@')
sys.path.insert(1, join(dirname(dirname(realpath(__file__))), '@pythondir@'))

import frida.ps

Expand Down
3 changes: 2 additions & 1 deletion src/scripts/frida-trace.in
@@ -1,7 +1,8 @@
#!@PYTHON@

from os.path import dirname, join, realpath
import sys
sys.path.insert(1, '@pythondir@')
sys.path.insert(1, join(dirname(dirname(realpath(__file__))), '@pythondir@'))

import frida
import frida.tracer
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/frida.in
@@ -1,7 +1,8 @@
#!@PYTHON@

from os.path import dirname, join, realpath
import sys
sys.path.insert(1, '@pythondir@')
sys.path.insert(1, join(dirname(dirname(realpath(__file__))), '@pythondir@'))

import frida.repl

Expand Down
24 changes: 24 additions & 0 deletions src/scripts/meson.build
@@ -0,0 +1,24 @@
scripts = [
'frida',
'frida-discover',
'frida-kill',
'frida-ls-devices',
'frida-ps',
'frida-trace',
]

cdata = configuration_data()
cdata.set('PYTHON', python)
cdata.set('pythondir', python_site_packages)

foreach s : scripts
generated_script = configure_file(
input: s + '.in',
output: s,
configuration: cdata,
)
install_data(generated_script,
install_dir: get_option('bindir'),
install_mode: 'rwxr-xr-x',
)
endforeach

0 comments on commit 1316e28

Please sign in to comment.