Skip to content

Commit

Permalink
Initial support for subproject's (acr|meson)-wrap files ##build
Browse files Browse the repository at this point in the history
* Use sdb.wrap from meson instead of shlr/sdb
  • Loading branch information
trufae authored Nov 29, 2024
1 parent 3315f8e commit 965a5c0
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 108 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ shlr/sdb/src/sdb
shlr/sdb/src/.sdb
shlr/sdb/src/sdb.exe
shlr/sdb/src/.sdb.exe
shlr/sdb/include/sdb/version.h
shlr/sdb/src/sdb-version.h
shlr/sdb/src/sdb_version.h
shlr/sdb/include/sdb/version.h
shlr/sdb/src/libsdb.so*
shlr/spp/config.h
shlr/.cs_tmp.zip
Expand Down
2 changes: 1 addition & 1 deletion libr/esil/esil.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ R_API bool r_esil_init(REsil *esil, int stacksize, bool iotrap,
ut32 addrsize, REsilRegInterface *reg_if, REsilMemInterface *mem_if) {
R_RETURN_VAL_IF_FAIL (esil && reg_if && reg_if->is_reg && reg_if->reg_read &&
reg_if->reg_write && reg_if->reg_size && mem_if && mem_if->mem_read &&
mem_if->mem_write && (stacksize > 2), NULL);
mem_if->mem_write && (stacksize > 2), false);
//do not check for mem_switch, as that is optional
esil->stack = calloc (sizeof (char *), stacksize);
if (R_UNLIKELY (!esil->stack)) {
Expand Down
182 changes: 79 additions & 103 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
project('radare2', 'c', license : 'LGPL3', meson_version : '>=0.50', version : '5.9.9')

# Global Arguments First

# system dependencies
cc = meson.get_compiler('c')

if get_option('wasan')
add_global_arguments('/DEBUG', language: 'c')
add_global_arguments('/MD', language: 'c')
add_global_arguments('/fsanitize=address', language: 'c')
# add_global_arguments('/Zi', language: 'c') # generate .pdb iirc
# add_global_arguments('/Z7', language: 'c') # generate .symbols instead of .pdb
# add_global_arguments('/guard:cf', language: 'c')
endif

if cc.get_id() == 'msvc'
# add_project_arguments('/Zc:preprocessor', language: 'c')
if get_option('static_runtime')
add_global_arguments('/MT', language: 'c')
endif
endif

if cc.get_id() == 'clang-cl'
add_global_arguments('-D__STDC__=1', language: 'c')
add_global_arguments('-D_CRT_DECLARE_NONSTDC_NAMES ', language: 'c')
add_global_arguments('-D_CRT_SECURE_NO_WARNINGS', language: 'c')
add_global_arguments('-D_CRT_NONSTDC_NO_DEPRECATE', language: 'c')
endif

if get_option('default_library') == 'shared'
if host_machine.system() != 'windows' or cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
add_global_arguments('-fvisibility=hidden', language: 'c')
endif
endif


py3_exe = import('python').find_installation('python3')
gen_py = '@0@/libr/syscall/d/gen.py'.format(meson.current_source_dir())
git_exe = find_program('git', required: false)
Expand Down Expand Up @@ -96,8 +131,6 @@ endif
r2_libversion = host_machine.system() == 'windows' ? '' : r2_version
message('r2 lib version: ' + r2_libversion)

# system dependencies
cc = meson.get_compiler('c')
# required for linux
ldl = cc.find_library('dl', required: false)
pth = dependency('threads', required: false)
Expand All @@ -117,41 +150,12 @@ endif
platform_inc = include_directories(platform_inc)


if cc.get_id() == 'msvc'
# add_project_arguments('/Zc:preprocessor', language: 'c')
if get_option('static_runtime')
add_project_arguments('/MT', language: 'c')
endif
endif

if get_option('threadsafety')
r2_critical_enabled = 1
else
r2_critical_enabled = 0
endif

if get_option('wasan')
add_project_arguments('/DEBUG', language: 'c')
add_project_arguments('/MD', language: 'c')
add_project_arguments('/fsanitize=address', language: 'c')
# add_project_arguments('/Zi', language: 'c') # generate .pdb iirc
# add_project_arguments('/Z7', language: 'c') # generate .symbols instead of .pdb
# add_project_arguments('/guard:cf', language: 'c')
endif

if cc.get_id() == 'clang-cl'
add_project_arguments('-D__STDC__=1', language: 'c')
add_project_arguments('-D_CRT_DECLARE_NONSTDC_NAMES ', language: 'c')
add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language: 'c')
add_project_arguments('-D_CRT_NONSTDC_NO_DEPRECATE', language: 'c')
endif

if get_option('default_library') == 'shared'
if host_machine.system() != 'windows' or cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
add_project_arguments('-fvisibility=hidden', language: 'c')
endif
endif

library_cflags = ['-DR2_PLUGIN_INCORE=1']

if host_machine.system() == 'windows'
Expand Down Expand Up @@ -275,6 +279,8 @@ if sys_magic.found() and get_option('use_sys_magic')
use_syslib_magic = true
endif

# dep_sdb = dependency('sdb', fallback: ['sdb'], required: true)

# handle xxhash library
sys_xxhash = dependency('libxxhash', required: false)
use_sys_xxhash = false
Expand Down Expand Up @@ -485,37 +491,36 @@ subdir('shlr/zip')
# NOTE: copying most of the stuff from sdb to here for the moment, since we
# should use subpackages to handle this well
sdb_files = [
'shlr/sdb/src/array.c',
'shlr/sdb/src/base64.c',
'shlr/sdb/src/set.c',
'shlr/sdb/src/cdb.c',
'shlr/sdb/src/cdb_make.c',
'shlr/sdb/src/dict.c',
'shlr/sdb/src/diff.c',
'shlr/sdb/src/disk.c',
'shlr/sdb/src/fmt.c',
'shlr/sdb/src/ht_uu.c',
'shlr/sdb/src/ht_up.c',
'shlr/sdb/src/ht_pp.c',
'shlr/sdb/src/ht_pu.c',
'shlr/sdb/src/ht_su.c',
'shlr/sdb/src/journal.c',
'shlr/sdb/src/json.c',
'shlr/sdb/src/lock.c',
'shlr/sdb/src/ls.c',
'shlr/sdb/src/match.c',
'shlr/sdb/src/ns.c',
'shlr/sdb/src/num.c',
'shlr/sdb/src/query.c',
'shlr/sdb/src/sdb.c',
'shlr/sdb/src/main.c',
'shlr/sdb/src/heap.c',
'shlr/sdb/src/ht.c',
'shlr/sdb/src/util.c',
'shlr/sdb/src/text.c'
'subprojects/sdb/src/array.c',
'subprojects/sdb/src/base64.c',
'subprojects/sdb/src/set.c',
'subprojects/sdb/src/cdb.c',
'subprojects/sdb/src/cdb_make.c',
'subprojects/sdb/src/dict.c',
'subprojects/sdb/src/diff.c',
'subprojects/sdb/src/disk.c',
'subprojects/sdb/src/fmt.c',
'subprojects/sdb/src/ht_uu.c',
'subprojects/sdb/src/ht_up.c',
'subprojects/sdb/src/ht_pp.c',
'subprojects/sdb/src/ht_pu.c',
'subprojects/sdb/src/ht_su.c',
'subprojects/sdb/src/journal.c',
'subprojects/sdb/src/json.c',
'subprojects/sdb/src/lock.c',
'subprojects/sdb/src/ls.c',
'subprojects/sdb/src/match.c',
'subprojects/sdb/src/ns.c',
'subprojects/sdb/src/num.c',
'subprojects/sdb/src/query.c',
'subprojects/sdb/src/sdb.c',
'subprojects/sdb/src/main.c',
'subprojects/sdb/src/heap.c',
'subprojects/sdb/src/ht.c',
'subprojects/sdb/src/util.c',
'subprojects/sdb/src/text.c'
]

sdb_inc = [platform_inc, include_directories(join_paths('shlr','sdb','include'))]

# XXX we have sdb/meson.build for this!! dont dup
# Create sdb_version.h
Expand All @@ -525,33 +530,9 @@ if r.returncode() == 0
else
sdb_version = 'unknown'
endif
run_command(py3_exe, '-c', 'with open("shlr/sdb/include/sdb/version.h", "w") as f: f.write("#define SDB_VERSION \"' + sdb_version + '\"")')

sdb_inc_files = [
'shlr/sdb/include/sdb/buffer.h',
'shlr/sdb/include/sdb/cdb.h',
'shlr/sdb/include/sdb/cdb_make.h',
'shlr/sdb/include/sdb/config.h',
'shlr/sdb/include/sdb/dict.h',
'shlr/sdb/include/sdb/heap.h',
'shlr/sdb/include/sdb/ht.h',
'shlr/sdb/include/sdb/ht_inc.h',
'shlr/sdb/include/sdb/ht_pp.h',
'shlr/sdb/include/sdb/ht_pu.h',
'shlr/sdb/include/sdb/ht_up.h',
'shlr/sdb/include/sdb/ht_uu.h',
'shlr/sdb/include/sdb/ls.h',
'shlr/sdb/include/sdb/rangstr.h',
'shlr/sdb/include/sdb/sdb.h',
'shlr/sdb/include/sdb/set.h',
'shlr/sdb/include/sdb/types.h',
'shlr/sdb/include/sdb/version.h',
'shlr/sdb/include/sdb/asserts.h',
'shlr/sdb/include/sdb/cwisstable.h',
'shlr/sdb/include/sdb/gcc_stdatomic.h',
'shlr/sdb/include/sdb/msvc_stdatomic.h',
]
install_headers(sdb_inc_files, install_dir: join_paths(r2_incdir, 'sdb'))
run_command(py3_exe, '-c', 'with open("subprojects/sdb/include/sdb/version.h", "w") as f: f.write("#define SDB_VERSION \"' + sdb_version + '\"")')

# install_headers(sdb_inc_files, install_dir: join_paths(r2_incdir, 'sdb'))

script_files = [
'scripts/il2cpp.r2.js',
Expand All @@ -565,24 +546,19 @@ script_files = [
]
install_data(script_files, install_dir: r2_scripts)

libr2sdb = static_library('r2sdb', sdb_files,
include_directories: sdb_inc,
implicit_include_directories: false,
c_args: host_machine.system() == 'windows' ? '-DSDB_IPI= -DSDB_API=__declspec(dllexport)' : [],
)
dep_sdb = subproject('sdb')
# sdb_dep = dep_sdb.get_variable('sdb_dep')
libsdb = dep_sdb.get_variable('libsdb')
libsdb_includes = dep_sdb.get_variable('sdb_inc')
sdb_inc = libsdb_includes
libsdb_static = libsdb.get_static_lib()

sdb_dep = declare_dependency(
link_whole: libr2sdb,
include_directories: sdb_inc
link_whole: libsdb_static,
include_directories: libsdb_includes
)

sdb_exe = executable('sdb', ['shlr/sdb/src/entry.c'] + sdb_files,
include_directories: [
include_directories('shlr/sdb/include')
],
implicit_include_directories: false,
native: true,
)
sdb_exe = dep_sdb.get_variable('sdb_exe')

sdb_gen_cmd_cgen = [
sdb_exe,
Expand Down Expand Up @@ -617,8 +593,8 @@ spp_files = [
spp_inc = [platform_inc, include_directories(join_paths('shlr','spp'))]

libr2spp = static_library('r2spp', spp_files,
dependencies: sdb_dep,
include_directories: spp_inc,
link_with: [ libsdb ], # libsdb_static,
include_directories: [ sdb_inc, spp_inc ],
c_args: ['-DHAVE_R_UTIL', '-DUSE_R2=1'],
implicit_include_directories: false
)
Expand Down
1 change: 1 addition & 0 deletions shlr/sdb/include/sdb/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define SDB_VERSION "2.0.1"
9 changes: 9 additions & 0 deletions subprojects/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DEPS=sdb capstone-v5

all: $(DEPS)

clean:
rm -rf $(DEPS)

include sdb.mk
include capstone-v5.mk
9 changes: 9 additions & 0 deletions subprojects/autogen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
ACR_WRAP=/tmp/acr-wrap
#ACR_WRAP=acr-wrap

for i in *.wrap ; do
o=`echo $i | sed -e 's,.wrap,.mk,'`
echo "[ACR] Wrapping $i"
${ACR_WRAP} $i > $o
done
19 changes: 19 additions & 0 deletions subprojects/capstone-v5.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is autogenerated by acr-wrap

WRAP_wrap_git_url:=https://github.com/capstone-engine/capstone.git
# revision = v5
WRAP_wrap_git_revision:=8455b3c5a53b02e524494c7e72a3946a32518170
# patch_directory = capstone-5.0.1
WRAP_wrap_git_directory:=capstone-v5
WRAP_wrap_git_depth:=1

capstone-v5_all: capstone-v5
@echo "Nothing to do"

capstone-v5:
git clone --no-checkout --depth=1 https://github.com/capstone-engine/capstone.git capstone-v5
cd capstone-v5 && git fetch --depth=1 origin 8455b3c5a53b02e524494c7e72a3946a32518170
cd capstone-v5 && git checkout

capstone-v5_clean:
rm -rf capstone-v5
7 changes: 7 additions & 0 deletions subprojects/capstone-v5.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[wrap-git]
url = https://github.com/capstone-engine/capstone.git
# revision = v5
revision = 8455b3c5a53b02e524494c7e72a3946a32518170
# patch_directory = capstone-5.0.1
directory = capstone-v5
depth = 1
18 changes: 18 additions & 0 deletions subprojects/sdb.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is autogenerated by acr-wrap

WRAP_wrap_git_url:=https://github.com/radareorg/sdb.git
WRAP_wrap_git_revision:=2e24eb0616dfce5e28130660313b56db9252dd5c
# revision = 2.0.1
WRAP_wrap_git_directory:=sdb
WRAP_wrap_git_depth:=1

sdb_all: sdb
@echo "Nothing to do"

sdb:
git clone --no-checkout --depth=1 https://github.com/radareorg/sdb.git sdb
cd sdb && git fetch --depth=1 origin 2e24eb0616dfce5e28130660313b56db9252dd5c
cd sdb && git checkout

sdb_clean:
rm -rf sdb
6 changes: 6 additions & 0 deletions subprojects/sdb.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-git]
url = https://github.com/radareorg/sdb.git
revision = 2e24eb0616dfce5e28130660313b56db9252dd5c
# revision = 2.0.1
directory = sdb
depth = 1

0 comments on commit 965a5c0

Please sign in to comment.