From cc90ec6be513cca34edb3a0f70cb334460bdc8eb Mon Sep 17 00:00:00 2001 From: Paul I Date: Sat, 28 Apr 2018 11:02:55 +0300 Subject: [PATCH] [WIP] Move hardcoded paths to r_userconf.h (#9959) * Move hardcoded paths to r_userconf.h * Add R2_HOME_* macros * Some cleanup --- binr/rabin2/rabin2.c | 2 +- binr/radare2/radare2.c | 26 +++++------ binr/rasm2/rasm2.c | 2 +- libr/anal/anal.c | 5 +-- libr/anal/d/meson.build | 2 +- libr/anal/meson.build | 4 +- libr/anal/sign.c | 6 +-- libr/asm/asm.c | 5 +-- libr/asm/d/meson.build | 2 +- libr/asm/meson.build | 4 +- libr/bin/d/meson.build | 4 +- libr/bin/format/pe/pe.c | 12 +----- libr/bin/meson.build | 4 +- libr/bin/p/bin_any.c | 4 +- libr/bp/meson.build | 4 +- libr/config/meson.build | 4 +- libr/cons/d/meson.build | 2 +- libr/cons/meson.build | 4 +- libr/core/cbin.c | 46 ++++++++------------ libr/core/cconfig.c | 16 +++---- libr/core/cmd.c | 6 +-- libr/core/cmd_eval.c | 17 ++++---- libr/core/cmd_print.c | 15 ++++--- libr/core/cmd_project.c | 2 +- libr/core/core.c | 8 +--- libr/core/file.c | 2 +- libr/core/fortune.c | 4 +- libr/core/libs.c | 4 +- libr/core/meson.build | 4 +- libr/core/visual.c | 6 +-- libr/crypto/meson.build | 4 +- libr/debug/meson.build | 4 +- libr/egg/meson.build | 4 +- libr/flag/meson.build | 4 +- libr/fs/meson.build | 4 +- libr/hash/meson.build | 4 +- libr/include/r_magic.h | 2 - libr/include/r_types.h | 9 +++- libr/include/r_userconf.h.acr | 41 +++++++++++++++--- libr/include/r_userconf.h.in | 43 ++++++++++++++----- libr/io/meson.build | 4 +- libr/lang/meson.build | 4 +- libr/magic/d/meson.build | 2 +- libr/magic/meson.build | 4 +- libr/parse/meson.build | 4 +- libr/reg/meson.build | 4 +- libr/search/meson.build | 4 +- libr/socket/meson.build | 4 +- libr/syscall/d/meson.build | 2 +- libr/syscall/meson.build | 4 +- libr/util/meson.build | 4 +- libr/util/sandbox.c | 2 +- meson.build | 81 +++++++++++++++++++++++++++++------ meson_options.txt | 11 ++++- 54 files changed, 286 insertions(+), 193 deletions(-) diff --git a/binr/rabin2/rabin2.c b/binr/rabin2/rabin2.c index 754ed42258..e9c76f2cb1 100644 --- a/binr/rabin2/rabin2.c +++ b/binr/rabin2/rabin2.c @@ -574,7 +574,7 @@ int main(int argc, char **argv) { bin = core.bin; if (!(tmp = r_sys_getenv ("RABIN2_NOPLUGINS"))) { - char *homeplugindir = r_str_home (R2_HOMEDIR "/plugins"); + char *homeplugindir = r_str_home (R2_HOME_PLUGINS); l = r_lib_new ("radare_plugin"); r_lib_add_handler (l, R_LIB_TYPE_BIN, "bin plugins", &__lib_bin_cb, &__lib_bin_dt, NULL); diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index 357ad86a13..3d65b95c13 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -174,22 +174,22 @@ static int main_help(int line) { " -z, -zz do not load strings or load them even in raw\n"); } if (line == 2) { - char *homedir = r_str_home (R2_HOMEDIR); + char *homedir = r_str_home (R2_HOME_CONFIGDIR); printf ( "Scripts:\n" " system ${R2_PREFIX}/share/radare2/radare2rc\n" - " user ~/.radare2rc ${RHOMEDIR}/radare2/radare2rc (and radare2rc.d/)\n" + " user ~/.radare2rc " R_JOIN_2_PATHS("~", R2_HOME_RC) " (and " R_JOIN_3_PATHS("~", R2_HOME_RC_DIR,"") ")\n" " file ${filename}.r2\n" "Plugins:\n" - " binrc ~/.config/radare2/rc.d/bin-/ (elf, elf64, mach0, ..)\n" + " binrc " R_JOIN_4_PATHS("~", R2_HOME_BINRC, "bin-", "") " (elf, elf64, mach0, ..)\n" " plugins "R2_PREFIX"/lib/radare2/last\n" - " USER_PLUGINS ~/.config/radare2/plugins\n" + " USER_PLUGINS " R_JOIN_2_PATHS("~", R2_HOME_PLUGINS)"\n" " LIBR_PLUGINS "R2_PREFIX"/lib/radare2/"R2_VERSION"\n" - " USER_ZIGNS ~/.config/radare2/zigns\n" + " USER_ZIGNS " R_JOIN_2_PATHS("~", R2_HOME_ZIGNS) "\n" "Environment:\n" " RHOMEDIR %s\n" // TODO: rename to RHOME R2HOME? " RCFILE ~/.radare2rc (user preferences, batch script)\n" // TOO GENERIC - " MAGICPATH "R_MAGIC_PATH"\n" + " MAGICPATH "R2_SDB_MAGIC"\n" " R_DEBUG if defined, show error messages and crash signal\n" " VAPIDIR path to extra vapi directory\n" " R2_NOPLUGINS do not load r2 shared plugins\n" @@ -206,15 +206,15 @@ static int main_help(int line) { static int main_print_var(const char *var_name) { int i = 0; - char *homedir = r_str_home (R2_HOMEDIR); - char *homeplugs = r_str_newf ("%s" R_SYS_DIR "plugins", homedir); - char *homezigns = r_str_newf ("%s" R_SYS_DIR "zigns", homedir); + char *homedir = r_str_home (R2_HOME_CONFIGDIR); + char *homeplugs = r_str_home (R2_HOME_PLUGINS); + char *homezigns = r_str_home (R2_HOME_ZIGNS); struct radare2_var_t { const char *name; const char *value; } r2_vars[] = { { "R2_PREFIX", R2_PREFIX }, - { "MAGICPATH", R_MAGIC_PATH }, + { "MAGICPATH", R2_SDB_MAGIC }, { "PREFIX", R2_PREFIX }, { "INCDIR", R2_INCDIR }, { "LIBDIR", R2_LIBDIR }, @@ -297,7 +297,7 @@ static void radare2_rc(RCore *r) { r_core_cmd_file (r, homerc); } free (homerc); - homerc = r_str_home (".config/radare2/radare2rc"); + homerc = r_str_home (R2_HOME_RC); if (homerc && r_file_is_regular (homerc)) { if (has_debug) { eprintf ("USER CONFIG loaded from %s\n", homerc); @@ -305,7 +305,7 @@ static void radare2_rc(RCore *r) { r_core_cmd_file (r, homerc); } free (homerc); - homerc = r_str_home (".config/radare2/radare2rc.d"); + homerc = r_str_home (R2_HOME_RC_DIR); if (homerc) { if (r_file_is_directory (homerc)) { char *file; @@ -1427,7 +1427,7 @@ int main(int argc, char **argv, char **envp) { } if (mustSaveHistory(r.config)) { - r_line_hist_save (R2_HOMEDIR"/history"); + r_line_hist_save (R2_HOME_HISTORY); } // TODO: kill thread diff --git a/binr/rasm2/rasm2.c b/binr/rasm2/rasm2.c index ac2697f075..815e473e21 100644 --- a/binr/rasm2/rasm2.c +++ b/binr/rasm2/rasm2.c @@ -446,7 +446,7 @@ int main (int argc, char *argv[]) { r_lib_opendir (l, path); if (1) { - char *homeplugindir = r_str_home (R2_HOMEDIR "/plugins"); + char *homeplugindir = r_str_home (R2_HOME_PLUGINS); // eprintf ("OPENDIR (%s)\n", homeplugindir); r_lib_opendir (l, homeplugindir); free (homeplugindir); diff --git a/libr/anal/anal.c b/libr/anal/anal.c index fbc5d7971c..521708601a 100644 --- a/libr/anal/anal.c +++ b/libr/anal/anal.c @@ -229,14 +229,13 @@ R_API bool r_anal_set_reg_profile(RAnal *anal) { } R_API bool r_anal_set_fcnsign(RAnal *anal, const char *name) { -#define FCNSIGNPATH "share/radare2/" R2_VERSION "/fcnsign" const char *dirPrefix = r_sys_prefix (NULL); char *file = NULL; const char *arch = (anal->cur && anal->cur->arch) ? anal->cur->arch : R_SYS_ARCH; if (name && *name) { - file = sdb_fmt ("%s/%s/%s.sdb", dirPrefix, FCNSIGNPATH, name); + file = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "%s.sdb"), dirPrefix, name); } else { - file = sdb_fmt ("%s/%s/%s-%s-%d.sdb", dirPrefix, FCNSIGNPATH, + file = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "%s-%s-%d.sdb"), dirPrefix, anal->os, arch, anal->bits); } if (r_file_exists (file)) { diff --git a/libr/anal/d/meson.build b/libr/anal/d/meson.build index e00df46a3c..da2321cf86 100644 --- a/libr/anal/d/meson.build +++ b/libr/anal/d/meson.build @@ -35,6 +35,6 @@ foreach file : sdb_files build_by_default: true, build_always: false, install: true, - install_dir: join_paths(get_option('datadir'), 'radare2', r2version, 'fcnsign') + install_dir: join_paths(get_option('datadir'), 'radare2', r2_version, 'fcnsign') ) endforeach diff --git a/libr/anal/meson.build b/libr/anal/meson.build index d78316d221..11b8c17469 100644 --- a/libr/anal/meson.build +++ b/libr/anal/meson.build @@ -113,13 +113,13 @@ r_anal = library('r_anal', files, ], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_anal], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_anal', filebase: 'r_anal', requires: [ diff --git a/libr/anal/sign.c b/libr/anal/sign.c index af9ea64ed8..97b124a5ff 100644 --- a/libr/anal/sign.c +++ b/libr/anal/sign.c @@ -1171,7 +1171,7 @@ R_API char *r_sign_path(RAnal *a, const char *file) { } free (abs); } else { - char *home = r_str_home (".config/radare2/zigns/"); + char *home = r_str_home (R2_HOME_ZIGNS); abs = r_str_newf ("%s%s%s", home, R_SYS_DIR, file); free (home); if (r_file_is_regular (abs)) { @@ -1180,9 +1180,7 @@ R_API char *r_sign_path(RAnal *a, const char *file) { free (abs); } - /// XXX mixed / and R_SYS_DIR - const char *pfx = "/share/radare2/" R2_VERSION "/zigns"; - abs = r_str_newf ("%s%s%s%s", r_sys_prefix (NULL), pfx, R_SYS_DIR, file); + abs = r_str_newf (R_JOIN_3_PATHS("%s", R2_ZIGNS, "%s"), r_sys_prefix (NULL), file); if (r_file_is_regular (abs)) { return abs; } diff --git a/libr/asm/asm.c b/libr/asm/asm.c index 412c089456..47886c02aa 100644 --- a/libr/asm/asm.c +++ b/libr/asm/asm.c @@ -8,8 +8,6 @@ #include #include -#define R_ASM_OPCODES_PATH "/share/radare2/" R2_VERSION "/opcodes" - R_LIB_VERSION (r_asm); char *directives[] = { @@ -315,7 +313,8 @@ R_API int r_asm_use(RAsm *a, const char *name) { if (!a->cur || (a->cur && strcmp (a->cur->arch, h->arch))) { //const char *dop = r_config_get (core->config, "dir.opcodes"); // TODO: allow configurable path for sdb files - snprintf (file, sizeof (file), "%s/"R_ASM_OPCODES_PATH"/%s.sdb", dirPrefix, h->arch); + snprintf (file, sizeof (file), R_JOIN_3_PATHS("%s", R2_SDB_OPCODES, "%s.sdb"), + dirPrefix, h->arch); sdb_free (a->pair); r_asm_set_cpu (a, NULL); a->pair = sdb_new (NULL, file, 0); diff --git a/libr/asm/d/meson.build b/libr/asm/d/meson.build index b09d78f953..9d7f0be6f4 100644 --- a/libr/asm/d/meson.build +++ b/libr/asm/d/meson.build @@ -38,6 +38,6 @@ foreach file : sdb_files build_by_default: true, build_always: false, install: true, - install_dir: join_paths(get_option('datadir'), 'radare2', r2version, 'opcodes') + install_dir: join_paths(get_option('datadir'), 'radare2', r2_version, 'opcodes') ) endforeach diff --git a/libr/asm/meson.build b/libr/asm/meson.build index 793bef6d89..a9669a06e9 100644 --- a/libr/asm/meson.build +++ b/libr/asm/meson.build @@ -168,13 +168,13 @@ r_asm = library('r_asm', files, ], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_asm], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_asm', filebase: 'r_asm', requires: [ diff --git a/libr/bin/d/meson.build b/libr/bin/d/meson.build index 65f8a207ed..43beedd7e7 100644 --- a/libr/bin/d/meson.build +++ b/libr/bin/d/meson.build @@ -55,7 +55,7 @@ foreach file : sdb_files build_by_default: true, build_always: false, install: true, - install_dir: join_paths(get_option('datadir'), 'radare2', r2version, 'format/dll') + install_dir: join_paths(get_option('datadir'), 'radare2', r2_version, 'format/dll') ) endforeach @@ -70,5 +70,5 @@ format_files = [ ] install_data(format_files, - install_dir: join_paths(get_option('datadir'), 'radare2', r2version, 'format') + install_dir: join_paths(get_option('datadir'), 'radare2', r2_version, 'format') ) diff --git a/libr/bin/format/pe/pe.c b/libr/bin/format/pe/pe.c index 761ac0a7e1..f206d2d7a1 100644 --- a/libr/bin/format/pe/pe.c +++ b/libr/bin/format/pe/pe.c @@ -433,17 +433,9 @@ static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin, if (r_file_exists (filename)) { db = sdb_new (NULL, filename, 0); } else { -#if __WINDOWS__ - char invoke_dir[MAX_PATH]; - if (r_sys_get_src_dir_w32 (invoke_dir)) { - filename = sdb_fmt ("%s\\share\\radare2\\"R2_VERSION "\\format\\dll\\%s.sdb", invoke_dir, symdllname); - } else { - filename = sdb_fmt ("share/radare2/"R2_VERSION "/format/dll/%s.sdb", symdllname); - } -#else const char *dirPrefix = r_sys_prefix (NULL); - filename = sdb_fmt ("%s/share/radare2/" R2_VERSION "/format/dll/%s.sdb", dirPrefix, symdllname); -#endif + filename = sdb_fmt (R_JOIN_4_PATHS("%s", R2_SDB_FORMAT, "dll", "%s.sdb"), + dirPrefix, symdllname); if (r_file_exists (filename)) { db = sdb_new (NULL, filename, 0); } diff --git a/libr/bin/meson.build b/libr/bin/meson.build index fe4bc25b80..01eac9bc4b 100644 --- a/libr/bin/meson.build +++ b/libr/bin/meson.build @@ -123,13 +123,13 @@ r_bin = library('r_bin', files, link_with: [r_util, r_io, r_socket, r_magic, libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_bin], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_bin', filebase: 'r_bin', requires: [ diff --git a/libr/bin/p/bin_any.c b/libr/bin/p/bin_any.c index c72ac0e359..c82aaf948b 100644 --- a/libr/bin/p/bin_any.c +++ b/libr/bin/p/bin_any.c @@ -19,8 +19,8 @@ static char *get_filetype(RBinFile *bf) { if (ck && bf && bf->buf) { const char *tmp = NULL; // TODO: dir.magic not honored here - char *pfx = r_str_newf ("%s/%s", r_sys_prefix (NULL), R_MAGIC_PATH); - r_magic_load (ck, R_MAGIC_PATH); + char *pfx = r_str_newf (R_JOIN_2_PATHS("%s", R2_SDB_MAGIC), r_sys_prefix (NULL)); + r_magic_load (ck, R2_SDB_MAGIC); r_buf_read_at (bf->buf, 0, buf, sizeof (buf)); tmp = r_magic_buffer (ck, buf, sizeof (buf)); if (tmp) { diff --git a/libr/bp/meson.build b/libr/bp/meson.build index ee19e85394..c6b89f2f6c 100644 --- a/libr/bp/meson.build +++ b/libr/bp/meson.build @@ -18,13 +18,13 @@ r_bp = library('r_bp', files, link_with: [r_util], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_bp], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_bp', filebase: 'r_bp', requires: [ diff --git a/libr/config/meson.build b/libr/config/meson.build index 272a4796f5..fdc1c624dc 100644 --- a/libr/config/meson.build +++ b/libr/config/meson.build @@ -8,13 +8,13 @@ r_config = library('r_config', files, link_with: [r_util, libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_config], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_config', filebase: 'r_config', requires: [ diff --git a/libr/cons/d/meson.build b/libr/cons/d/meson.build index bb4016c32b..f7a56c4ff2 100644 --- a/libr/cons/d/meson.build +++ b/libr/cons/d/meson.build @@ -1,4 +1,4 @@ install_subdir('.', - install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'radare2', r2version, 'cons'), + install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'radare2', r2_version, 'cons'), exclude_files: ['Makefile', 'meson.build'] ) diff --git a/libr/cons/meson.build b/libr/cons/meson.build index b66b8c2366..11562ec3c7 100644 --- a/libr/cons/meson.build +++ b/libr/cons/meson.build @@ -22,13 +22,13 @@ r_cons = library('r_cons', files, link_with: [r_util, libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_cons], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_cons', filebase: 'r_cons', requires: [ diff --git a/libr/core/cbin.c b/libr/core/cbin.c index 523ddcad48..07a1ed8c50 100644 --- a/libr/core/cbin.c +++ b/libr/core/cbin.c @@ -3,7 +3,6 @@ #include #include "r_util.h" -#define DBSPATH "/share/radare2/" R2_VERSION "/fcnsign" #define is_in_range(at, from, sz) ((at) >= (from) && (at) < ((from) + (sz))) #define VA_FALSE 0 @@ -497,35 +496,42 @@ R_API void r_core_anal_type_init(RCore *core) { anal_arch = r_config_get (core->config, "anal.arch"); os = r_config_get (core->config, "asm.os"); // spaguetti ahead - dbpath = sdb_fmt ("%s/"DBSPATH"/types.sdb", dir_prefix); + dbpath = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "types.sdb"), dir_prefix); if (r_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } - dbpath = sdb_fmt ("%s/"DBSPATH"/types-%s.sdb", dir_prefix, anal_arch); + dbpath = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "types-%s.sdb"), + dir_prefix, anal_arch); if (r_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } - dbpath = sdb_fmt ("%s/"DBSPATH"/types-%s.sdb", dir_prefix, os); + dbpath = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "types-%s.sdb"), + dir_prefix, os); if (r_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } - dbpath = sdb_fmt ("%s/"DBSPATH"/types-%d.sdb", dir_prefix, bits); + dbpath = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "types-%d.sdb"), + dir_prefix, bits); if (r_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } - dbpath = sdb_fmt ("%s/"DBSPATH"/types-%s-%d.sdb", dir_prefix, os, bits); + dbpath = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "types-%s-%d.sdb"), + dir_prefix, os, bits); if (r_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } - dbpath = sdb_fmt ("%s/"DBSPATH"/types-%s-%d.sdb", dir_prefix, anal_arch, bits); + dbpath = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "types-%s-%d.sdb"), + dir_prefix, anal_arch, bits); if (r_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } - dbpath = sdb_fmt ("%s/"DBSPATH"/types-%s-%s.sdb", dir_prefix, anal_arch, os); + dbpath = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "types-%s-%s.sdb"), + dir_prefix, anal_arch, os); if (r_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } - dbpath = sdb_fmt ("%s/"DBSPATH"/types-%s-%s-%d.sdb", dir_prefix, anal_arch, os, bits); + dbpath = sdb_fmt (R_JOIN_3_PATHS("%s", R2_SDB_FCNSIGN, "types-%s-%s-%d.sdb"), + dir_prefix, anal_arch, os, bits); if (r_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } @@ -562,7 +568,7 @@ R_API void r_core_anal_cc_init(RCore *core) { bits = 32; } - char *dbpath = sdb_fmt ("%s/"DBSPATH"/cc-%s-%d.sdb", dir_prefix, anal_arch, bits); + char *dbpath = sdb_fmt ("%s/"R2_SDB_FCNSIGN"/cc-%s-%d.sdb", dir_prefix, anal_arch, bits); if (r_file_exists (dbpath)) { sdb_concat_by_path (core->anal->sdb_cc, dbpath); } @@ -583,7 +589,6 @@ R_API void r_core_anal_cc_init(RCore *core) { sdb_close (sdbs[0]); sdb_free (sdbs[0]); } -#undef DBSPATH static int bin_info(RCore *r, int mode) { int i, j, v; @@ -1242,24 +1247,11 @@ static void set_bin_relocs(RCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char if (r_file_exists (filename)) { *db = sdb_new (NULL, filename, 0); } else { - // XXX. we have dir.prefix, windows shouldnt work different - filename = sdb_fmt ("%s/share/radare2/" R2_VERSION"/format/dll/%s.sdb", r_config_get (r->config, "dir.prefix"), module); + const char *dirPrefix = r_sys_prefix (NULL); + filename = sdb_fmt (R_JOIN_4_PATHS("%s", R2_SDB_FORMAT, "dll", "%s.sdb"), + dirPrefix, module); if (r_file_exists (filename)) { *db = sdb_new (NULL, filename, 0); -#if __WINDOWS__ - } else { - char invoke_dir[MAX_PATH]; - if (r_sys_get_src_dir_w32 (invoke_dir)) { - filename = sdb_fmt ("%s/share/radare2/"R2_VERSION "/format/dll/%s.sdb", invoke_dir, module); - } else { - filename = sdb_fmt ("share/radare2/"R2_VERSION"/format/dll/%s.sdb", module); - } -#else - filename = sdb_fmt ("%s/share/radare2/" R2_VERSION"/format/dll/%s.sdb", r_config_get (r->config, "dir.prefix"), module); - if (r_file_exists (filename)) { - *db = sdb_new (NULL, filename, 0); - } -#endif } } } diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index 0534efb3c3..2c7d0beed9 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -2295,7 +2295,7 @@ R_API int r_core_config_init(RCore *core) { SETPREF ("pdb.useragent", "Microsoft-Symbol-Server/6.11.0001.402", "User agent for Microsoft symbol server"); SETPREF ("pdb.server", "https://msdl.microsoft.com/download/symbols", "Base URL for Microsoft symbol server"); { - char *pdb_path = r_str_home(R2_HOMEDIR R_SYS_DIR "pdb"); + char *pdb_path = r_str_home(R2_HOME_PDB); SETPREF("pdb.symstore", pdb_path, "Path to downstream symbol store"); R_FREE(pdb_path); } @@ -2591,7 +2591,7 @@ R_API int r_core_config_init(RCore *core) { SETPREF ("zign.bytes", "true", "Use bytes patterns for matching"); SETPREF ("zign.offset", "true", "Use original offset for matching"); SETPREF ("zign.refs", "true", "Use references for matching"); - SETPREF ("zign.autoload", "false", "Autoload all zignatures located in ~/.config/radare2/zigns"); + SETPREF ("zign.autoload", "false", "Autoload all zignatures located in " R_JOIN_2_PATHS("~", R2_HOME_ZIGNS)); /* diff */ SETCB ("diff.sort", "addr", &cb_diff_sort, "Specify function diff sorting column see (e diff.sort=?)"); @@ -2603,7 +2603,7 @@ R_API int r_core_config_init(RCore *core) { /* dir */ SETCB ("dir.dbgsnap", ".", &cb_dbgsnap, "Path to session dump files"); { - char *path = r_str_newf ("%s/" R_MAGIC_PATH, r_config_get (core->config, "dir.prefix")); + char *path = r_str_newf (R_JOIN_2_PATHS("%s", R2_SDB_MAGIC), r_config_get (core->config, "dir.prefix")); SETPREF ("dir.magic", path, "Path to r_magic files"); free (path); } @@ -2616,12 +2616,10 @@ R_API int r_core_config_init(RCore *core) { SETPREF ("dir.types", "/usr/include", "Default path to look for cparse type files"); #if __ANDROID__ SETPREF ("dir.projects", "/data/data/org.radare.radare2installer/radare2/projects", "Default path for projects"); -#elif __WINDOWS__ - SETPREF ("dir.projects", "~\\"R2_HOMEDIR"\\projects", "Default path for projects"); #else - SETPREF ("dir.projects", "~/"R2_HOMEDIR"/projects", "Default path for projects"); + SETPREF ("dir.projects", R_JOIN_2_PATHS("~", R2_HOME_PROJECTS), "Default path for projects"); #endif - SETCB ("dir.zigns", "~/"R2_HOMEDIR"/zigns", &cb_dirzigns, "Default path for zignatures (see zo command)"); + SETCB ("dir.zigns", R_JOIN_2_PATHS("~", R2_HOME_ZIGNS), &cb_dirzigns, "Default path for zignatures (see zo command)"); SETPREF ("stack.bytes", "true", "Show bytes instead of words in stack"); SETPREF ("stack.anotated", "false", "Show anotated hexdump in visual debug"); SETI ("stack.size", 64, "Size in bytes of stack hexdump in visual debug"); @@ -2776,11 +2774,9 @@ R_API int r_core_config_init(RCore *core) { #endif SETI ("http.maxsize", 0, "Maximum file size for upload"); SETPREF ("http.bind", "localhost", "Server address"); - SETPREF ("http.homeroot", "~/.config/radare2/www", "http home root directory"); + SETPREF ("http.homeroot", R_JOIN_2_PATHS("~", R2_HOME_WWWROOT), "http home root directory"); #if __ANDROID__ SETPREF ("http.root", "/data/data/org.radare.radare2installer/www", "http root directory"); -#elif __WINDOWS__ - SETPREF ("http.root", "www", "http root directory"); #else SETPREF ("http.root", R2_WWWROOT, "http root directory"); #endif diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 87f327afa1..3874a5c433 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -1410,7 +1410,7 @@ static int cmd_system(void *data, const char *input) { case '-': if (input[1]) { r_line_hist_free(); - r_line_hist_save (R2_HOMEDIR"/history"); + r_line_hist_save (R2_HOME_HISTORY); } else { r_line_hist_free(); } @@ -1442,8 +1442,8 @@ static int cmd_system(void *data, const char *input) { free (cmd); } //else eprintf ("Error setting up system environment\n"); } else { - eprintf ("History saved to "R2_HOMEDIR"/history\n"); - r_line_hist_save (R2_HOMEDIR"/history"); + eprintf ("History saved to "R2_HOME_HISTORY"\n"); + r_line_hist_save (R2_HOME_HISTORY); } break; case '\0': diff --git a/libr/core/cmd_eval.c b/libr/core/cmd_eval.c index 11decb4a25..d9f7eb3878 100644 --- a/libr/core/cmd_eval.c +++ b/libr/core/cmd_eval.c @@ -46,7 +46,7 @@ static const char *help_msg_ec[] = { "", " ", "", "colors:", "", "rgb:000, red, green, blue, #ff0000, ...", "e scr.color", "=0", "use more colors (0: no color 1: ansi 16, 2: 256, 3: 16M)", - "$DATADIR/radare2/cons", "", "~/.config/radare2/cons ./", + "$DATADIR/radare2/cons", "", R_JOIN_2_PATHS("~", R2_HOME_THEMES) " ./", NULL }; @@ -118,13 +118,13 @@ R_API RList *r_core_list_themes(RCore *core) { RList *list = r_list_newf (free); getNext = false; - char *path = r_str_home (".config/radare2/cons/"); + char *path = r_str_home (R2_HOME_THEMES R_SYS_DIR); if (path) { list_themes_in_path (list, path); R_FREE (path); } - path = r_str_r2_prefix ("share/radare2/"R2_VERSION"/cons/"); + path = r_str_r2_prefix (R2_THEMES R_SYS_DIR); if (path) { list_themes_in_path (list, path); R_FREE (path); @@ -139,7 +139,7 @@ static void nextpal(RCore *core, int mode) { RListIter *iter; const char *fn; int ctr = 0; - char *home = r_str_home (".config/radare2/cons/"); + char *home = r_str_home (R2_HOME_THEMES R_SYS_DIR); getNext = false; if (mode == 'j') { @@ -179,7 +179,7 @@ static void nextpal(RCore *core, int mode) { R_FREE (home); } - char *path = r_str_r2_prefix ("share/radare2/"R2_VERSION"/cons/"); + char *path = r_str_r2_prefix (R2_THEMES R_SYS_DIR); if (path) { files = r_sys_dir (path); r_list_foreach (files, iter, fn) { @@ -310,11 +310,11 @@ static int cmd_eval(void *data, const char *input) { bool failed = false; char *home, *path, *tmp; - tmp = r_str_newf (".config/radare2/cons/%s", input + 3); + tmp = r_str_newf (R_JOIN_2_PATHS(R2_HOME_THEMES, "%s"), input + 3); home = tmp ? r_str_home (tmp) : NULL; free (tmp); - tmp = r_str_newf ("share/radare2/"R2_VERSION"/cons/%s", input + 3); + tmp = r_str_newf (R_JOIN_2_PATHS(R2_THEMES, "%s"), input + 3); path = tmp ? r_str_r2_prefix (tmp) : NULL; free (tmp); @@ -339,7 +339,8 @@ static int cmd_eval(void *data, const char *input) { eprintf ("Something went wrong\n"); } } else if (input[2] == '?') { - eprintf ("Usage: eco [themename] ;load theme from %s/share/radare2/"R2_VERSION"/cons/ (see dir.prefix)\n", + eprintf ("Usage: eco [themename] ;load theme from " + R_JOIN_3_PATHS("%s", R2_THEMES, "") " (see dir.prefix)\n", r_sys_prefix (NULL)); } else { diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index f4c0d4e201..36fc01acf7 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -880,14 +880,15 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, if (input[1] == 'o') { // "pfo" if (input[2] == '?') { eprintf ("|Usage: pfo [format-file]\n" - " ~/.config/radare2/format\n" - " %s/radare2/"R2_VERSION "/format/\n", + " " R_JOIN_3_PATHS("~", R2_HOME_SDB_FORMAT, "") "\n" + " " R_JOIN_3_PATHS("%s", R2_SDB_FORMAT, "") "\n", r_sys_prefix (NULL)); } else if (input[2] == ' ') { char *home, *path, tmp[512]; - snprintf (tmp, sizeof (tmp), ".config/radare2/format/%s", input + 3); + snprintf (tmp, sizeof (tmp), + R_JOIN_2_PATHS(R2_HOME_SDB_FORMAT, "%s"), input + 3); home = r_str_home (tmp); - snprintf (tmp, sizeof (tmp), "share/radare2/"R2_VERSION"/format/%s", input + 3); + snprintf (tmp, sizeof (tmp), R_JOIN_2_PATHS(R2_SDB_FORMAT, "%s"), input + 3); path = r_str_r2_prefix (tmp); if (!r_core_cmd_file (core, home) && !r_core_cmd_file (core, path)) { if (!r_core_cmd_file (core, input + 3)) { @@ -900,7 +901,7 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, RList *files; RListIter *iter; const char *fn; - char *home = r_str_home (".config/radare2/format/"); + char *home = r_str_home (R2_HOME_SDB_FORMAT R_SYS_DIR); if (home) { files = r_sys_dir (home); r_list_foreach (files, iter, fn) { @@ -911,7 +912,7 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, r_list_free (files); free (home); } - char *path = r_str_r2_prefix ("share/radare2/"R2_VERSION"/format/"); + char *path = r_str_r2_prefix (R2_SDB_FORMAT R_SYS_DIR); if (path) { files = r_sys_dir (path); r_list_foreach (files, iter, fn) { @@ -4664,7 +4665,7 @@ static int cmd_print(void *data, const char *input) { "| foo@0x40 # use 'foo' magic file on address 0x40\n" "| @0x40 # use current magic file on address 0x40\n" "| \\n # append newline\n" - "| e dir.magic # defaults to "R_MAGIC_PATH "\n" + "| e dir.magic # defaults to "R2_SDB_MAGIC "\n" "| /m # search for magic signatures\n" ); } else { diff --git a/libr/core/cmd_project.c b/libr/core/cmd_project.c index 2d9474f5d0..15165bfa94 100644 --- a/libr/core/cmd_project.c +++ b/libr/core/cmd_project.c @@ -18,7 +18,7 @@ static const char *help_msg_P[] = { "PS", " [file]", "save script file", "P-", " [file]", "delete project (alias for Pd)", "NOTE:", "", "See 'e??prj.'", - "NOTE:", "", "project are stored in ~/.config/radare2/projects", + "NOTE:", "", "project are stored in " R_JOIN_2_PATHS("~", R2_HOME_PROJECTS), NULL }; diff --git a/libr/core/core.c b/libr/core/core.c index 298e7b8683..f00542a66f 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1710,11 +1710,7 @@ R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, bool verbo static void r_core_setenv (RCore *core) { char *e = r_sys_getenv ("PATH"); -#if __WINDOWS__ && !__CYGWIN__ - char *h = r_str_home (".config\\radare2\\prefix\\bin;"); -#else - char *h = r_str_home (".config/radare2/prefix/bin:"); -#endif + char *h = r_str_home (R2_HOME_BIN R_SYS_ENVSEP); char *n = r_str_newf ("%s%s", h, e); r_sys_setenv ("PATH", n); free (n); @@ -1825,7 +1821,7 @@ R_API bool r_core_init(RCore *core) { core->cons->user_fgets = (void *)r_core_fgets; #endif //r_line_singleton()->user = (void *)core; - r_line_hist_load (R2_HOMEDIR"/history"); + r_line_hist_load (R2_HOME_HISTORY); } core->print->cons = core->cons; r_cons_bind (&core->print->consbind); diff --git a/libr/core/file.c b/libr/core/file.c index 8b0df83129..929d10ed36 100644 --- a/libr/core/file.c +++ b/libr/core/file.c @@ -502,7 +502,7 @@ static void load_scripts_for(RCore *core, const char *name) { // TODO: char *file; RListIter *iter; - char *hdir = r_str_newf (R2_HOMEDIR "/rc.d/bin-%s", name); + char *hdir = r_str_newf (R_JOIN_2_PATHS(R2_HOME_BINRC, "bin-%s"), name); char *path = r_str_home (hdir); RList *files = r_sys_dir (path); if (!r_list_empty (files)) { diff --git a/libr/core/fortune.c b/libr/core/fortune.c index d6c46f6dc7..f2bc0ec796 100644 --- a/libr/core/fortune.c +++ b/libr/core/fortune.c @@ -5,8 +5,8 @@ static const char *fortunes[] = { }; static char *getFortuneFile(RCore *core, const char *type) { - return r_str_newf ("%s/share/doc/radare2/fortunes.%s", - r_config_get (core->config, "dir.prefix"), type); + return r_str_newf (R_JOIN_3_PATHS("%s", R2_FORTUNES, "fortunes.%s"), + r_sys_prefix (NULL), type); } R_API void r_core_fortune_list_types(void) { diff --git a/libr/core/libs.c b/libr/core/libs.c index fa2cac20f0..fb5fd311dc 100644 --- a/libr/core/libs.c +++ b/libr/core/libs.c @@ -86,7 +86,7 @@ R_API int r_core_loadlibs(RCore *core, int where, const char *path) { free (p); } if (where & R_CORE_LOADLIBS_HOME) { - char *homeplugindir = r_str_home (R2_HOMEDIR "/plugins"); + char *homeplugindir = r_str_home (R2_HOME_PLUGINS); // eprintf ("OPENDIR (%s)\n", homeplugindir); r_lib_opendir (core->lib, homeplugindir); free (homeplugindir); @@ -103,7 +103,7 @@ R_API int r_core_loadlibs(RCore *core, int where, const char *path) { } #endif // load script plugins - char *homeplugindir = r_str_home (R2_HOMEDIR "/plugins"); + char *homeplugindir = r_str_home (R2_HOME_PLUGINS); RList *files = r_sys_dir (homeplugindir); RListIter *iter; char *file; diff --git a/libr/core/meson.build b/libr/core/meson.build index a339d02d1a..94f25b1383 100644 --- a/libr/core/meson.build +++ b/libr/core/meson.build @@ -80,13 +80,13 @@ r_core = library('r_core', files, dependencies: [platform_deps], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_core], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_core', filebase: 'r_core', requires: [ diff --git a/libr/core/visual.c b/libr/core/visual.c index 50bf2b817e..8fbdb50ca1 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -198,10 +198,10 @@ static int zoom = 0; R_API int r_core_visual_hud(RCore *core) { const char *c = r_config_get (core->config, "hud.path"); - char *f = r_str_newf ("%s/share/radare2/" R2_VERSION "/hud/main", - r_config_get (core->config, "dir.prefix")); + char *f = r_str_newf (R_JOIN_3_PATHS("%s", R2_HUD, "main"), + r_sys_prefix (NULL)); int use_color = core->print->flags & R_PRINT_FLAGS_COLOR; - char *homehud = r_str_home (R2_HOMEDIR "/hud"); + char *homehud = r_str_home (R2_HOME_HUD); char *res = NULL; char *p = 0; r_cons_singleton ()->color = use_color; diff --git a/libr/crypto/meson.build b/libr/crypto/meson.build index 6a9a702440..0cd06a3d60 100644 --- a/libr/crypto/meson.build +++ b/libr/crypto/meson.build @@ -26,13 +26,13 @@ r_crypto = library('r_crypto', files, c_args: ['-DCORELIB=1'], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkg = import('pkgconfig') pkg.generate(libraries: [r_crypto], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_crypto', filebase: 'r_crypto', requires: [ diff --git a/libr/debug/meson.build b/libr/debug/meson.build index 7acdb3ff94..6cf657f954 100644 --- a/libr/debug/meson.build +++ b/libr/debug/meson.build @@ -70,13 +70,13 @@ r_debug = library('r_debug', files, ], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_debug], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_debug', filebase: 'r_debug', requires: [ diff --git a/libr/egg/meson.build b/libr/egg/meson.build index d268bcd7eb..372e23be08 100644 --- a/libr/egg/meson.build +++ b/libr/egg/meson.build @@ -21,13 +21,13 @@ r_egg = library('r_egg', files, link_with: [r_util, r_asm, r_syscall, libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_egg], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_egg', filebase: 'r_egg', requires: [ diff --git a/libr/flag/meson.build b/libr/flag/meson.build index 611b523e6e..894d961235 100644 --- a/libr/flag/meson.build +++ b/libr/flag/meson.build @@ -10,13 +10,13 @@ r_flag = library('r_flag', files, link_with: [r_util, libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_flag], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_flag', filebase: 'r_flag', requires: [ diff --git a/libr/fs/meson.build b/libr/fs/meson.build index fa6d4416c1..bf7b1b5dda 100644 --- a/libr/fs/meson.build +++ b/libr/fs/meson.build @@ -35,13 +35,13 @@ r_fs = library('r_fs', files, link_with: [r_util, libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_fs], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_fs', filebase: 'r_fs', requires: [ diff --git a/libr/hash/meson.build b/libr/hash/meson.build index 8dafcc9f00..f8e427a2b1 100644 --- a/libr/hash/meson.build +++ b/libr/hash/meson.build @@ -20,13 +20,13 @@ r_hash = library('r_hash', files, link_with: [r_util], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_hash], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_hash', filebase: 'r_hash', requires: [ diff --git a/libr/include/r_magic.h b/libr/include/r_magic.h index 8d310173d1..2c11570345 100644 --- a/libr/include/r_magic.h +++ b/libr/include/r_magic.h @@ -15,8 +15,6 @@ R_LIB_VERSION_HEADER(r_magic); #define MAGICFILE "/etc/magic" #endif -#define R_MAGIC_PATH "/share/radare2/" R2_VERSION "/magic" - #if USE_LIB_MAGIC #include diff --git a/libr/include/r_types.h b/libr/include/r_types.h index 4f1c8356f2..d6a389844a 100644 --- a/libr/include/r_types.h +++ b/libr/include/r_types.h @@ -181,15 +181,20 @@ extern "C" { #if __WINDOWS__ #define FS "\\" #define R_SYS_DIR "\\" +#define R_SYS_ENVSEP ";" #define R_SYS_HOME "USERPROFILE" -#define R2_HOMEDIR ".config\\radare2" #else #define FS "/" #define R_SYS_DIR "/" +#define R_SYS_ENVSEP ":" #define R_SYS_HOME "HOME" -#define R2_HOMEDIR ".config/radare2" #endif +#define R_JOIN_2_PATHS(p1, p2) p1 R_SYS_DIR p2 +#define R_JOIN_3_PATHS(p1, p2, p3) p1 R_SYS_DIR p2 R_SYS_DIR p3 +#define R_JOIN_4_PATHS(p1, p2, p3, p4) p1 R_SYS_DIR p2 R_SYS_DIR p3 R_SYS_DIR p4 +#define R_JOIN_5_PATHS(p1, p2, p3, p4, p5) p1 R_SYS_DIR p2 R_SYS_DIR p3 R_SYS_DIR p4 R_SYS_DIR p5 + #ifndef __packed #define __packed __attribute__((__packed__)) #endif diff --git a/libr/include/r_userconf.h.acr b/libr/include/r_userconf.h.acr index 7aeaa44372..6041fb3351 100644 --- a/libr/include/r_userconf.h.acr +++ b/libr/include/r_userconf.h.acr @@ -8,16 +8,49 @@ #if __WINDOWS__ || __CYGWIN__ || MINGW32 || _MSC_VER || CUTTER #define R2_PREFIX "." -#define R2_LIBDIR "./lib" -#define R2_INCDIR "./include/libr" -#define R2_DATDIR "./share" +#define R2_LIBDIR "lib" +#define R2_INCDIR "include\\libr" +#define R2_DATDIR "share" +#define R2_WWWROOT "www" #else #define R2_PREFIX "@PREFIX@" #define R2_LIBDIR "@LIBDIR@" #define R2_INCDIR "@INCLUDEDIR@/libr" #define R2_DATDIR "@DATADIR@" +#define R2_WWWROOT R2_DATDIR "/radare2/" R2_VERSION "/www" #endif +#define R2_SDB R_JOIN_3_PATHS("share", "radare2", R2_VERSION) +#define R2_ZIGNS R_JOIN_4_PATHS("share", "radare2", R2_VERSION, "zigns") +#define R2_THEMES R_JOIN_4_PATHS("share", "radare2", R2_VERSION, "cons") +#define R2_FORTUNES R_JOIN_3_PATHS("share", "doc", "radare2") +#define R2_HUD R_JOIN_4_PATHS("share", "radare2", R2_VERSION, "hud") + +#define R2_SDB_FCNSIGN R_JOIN_2_PATHS(R2_SDB, "fcnsign") +#define R2_SDB_OPCODES R_JOIN_2_PATHS(R2_SDB, "opcodes") +#define R2_SDB_MAGIC R_JOIN_2_PATHS(R2_SDB, "magic") +#define R2_SDB_FORMAT R_JOIN_2_PATHS(R2_SDB, "format") + +#define R2_HOME_CONFIGDIR R_JOIN_2_PATHS(".config", "radare2") +#define R2_HOME_DATADIR R_JOIN_3_PATHS(".local", "share", "radare2") +#define R2_HOME_CACHEDIR R_JOIN_2_PATHS(".cache", "radare2") + +#define R2_HOME_THEMES R_JOIN_2_PATHS(R2_HOME_DATADIR, "cons") +#define R2_HOME_PLUGINS R_JOIN_2_PATHS(R2_HOME_DATADIR, "plugins") +#define R2_HOME_ZIGNS R_JOIN_2_PATHS(R2_HOME_DATADIR, "zigns") +#define R2_HOME_PDB R_JOIN_2_PATHS(R2_HOME_DATADIR, "pdb") +#define R2_HOME_PROJECTS R_JOIN_2_PATHS(R2_HOME_DATADIR, "projects") +#define R2_HOME_WWWROOT R_JOIN_2_PATHS(R2_HOME_DATADIR, "www") +#define R2_HOME_SDB_FORMAT R_JOIN_2_PATHS(R2_HOME_DATADIR, "format") +#define R2_HOME_HUD R_JOIN_2_PATHS(R2_HOME_DATADIR, "hud") +#define R2_HOME_BINRC R_JOIN_2_PATHS(R2_HOME_DATADIR, "rc.d") +#define R2_HOME_BIN R_JOIN_3_PATHS(R2_HOME_DATADIR, "prefix", "bin") + +#define R2_HOME_RC R_JOIN_2_PATHS(R2_HOME_CONFIGDIR, "radare2rc") +#define R2_HOME_RC_DIR R_JOIN_2_PATHS(R2_HOME_CONFIGDIR, "radare2rc.d") + +#define R2_HOME_HISTORY R_JOIN_2_PATHS(R2_HOME_CACHEDIR, "history") + #define HAVE_LIB_MAGIC @HAVE_LIB_MAGIC@ #define USE_LIB_MAGIC @USE_LIB_MAGIC@ #ifndef HAVE_LIB_SSL @@ -28,8 +61,6 @@ #define WITH_GPL @WITH_GPL@ -#define R2_WWWROOT R2_DATDIR "/radare2/" R2_VERSION "/www" - #if __APPLE__ && __POWERPC__ #define HAVE_JEMALLOC 0 #else diff --git a/libr/include/r_userconf.h.in b/libr/include/r_userconf.h.in index c1437ad58a..b82c158bb1 100644 --- a/libr/include/r_userconf.h.in +++ b/libr/include/r_userconf.h.in @@ -6,17 +6,42 @@ #define DEBUGGER @DEBUGGER@ #define HAVE_DECL_ADDR_NO_RANDOMIZE @HAVE_DECL_ADDR_NO_RANDOMIZE@ -#if __WINDOWS__ || __CYGWIN__ || MINGW32 || _MSC_VER || CUTTER -#define R2_PREFIX "." -#define R2_LIBDIR "./lib" -#define R2_INCDIR "./include/libr" -#define R2_DATDIR "./share" -#else #define R2_PREFIX "@PREFIX@" #define R2_LIBDIR "@LIBDIR@" -#define R2_INCDIR "@INCLUDEDIR@/libr" +#define R2_INCDIR "@INCLUDEDIR@" #define R2_DATDIR "@DATADIR@" -#endif +#define R2_WWWROOT "@WWWROOT@" + +#define R2_SDB "@SDB@" +#define R2_ZIGNS "@ZIGNS@" +#define R2_THEMES "@THEMES@" +#define R2_FORTUNES "@FORTUNES@" +#define R2_HUD "@HUD@" + +#define R2_SDB_FCNSIGN R_JOIN_2_PATHS(R2_SDB, "fcnsign") +#define R2_SDB_OPCODES R_JOIN_2_PATHS(R2_SDB, "opcodes") +#define R2_SDB_MAGIC R_JOIN_2_PATHS(R2_SDB, "magic") +#define R2_SDB_FORMAT R_JOIN_2_PATHS(R2_SDB, "format") + +#define R2_HOME_CONFIGDIR R_JOIN_2_PATHS(".config", "radare2") +#define R2_HOME_DATADIR R_JOIN_3_PATHS(".local", "share", "radare2") +#define R2_HOME_CACHEDIR R_JOIN_2_PATHS(".cache", "radare2") + +#define R2_HOME_THEMES R_JOIN_2_PATHS(R2_HOME_DATADIR, "cons") +#define R2_HOME_PLUGINS R_JOIN_2_PATHS(R2_HOME_DATADIR, "plugins") +#define R2_HOME_ZIGNS R_JOIN_2_PATHS(R2_HOME_DATADIR, "zigns") +#define R2_HOME_PDB R_JOIN_2_PATHS(R2_HOME_DATADIR, "pdb") +#define R2_HOME_PROJECTS R_JOIN_2_PATHS(R2_HOME_DATADIR, "projects") +#define R2_HOME_WWWROOT R_JOIN_2_PATHS(R2_HOME_DATADIR, "www") +#define R2_HOME_SDB_FORMAT R_JOIN_2_PATHS(R2_HOME_DATADIR, "format") +#define R2_HOME_HUD R_JOIN_2_PATHS(R2_HOME_DATADIR, "hud") +#define R2_HOME_BINRC R_JOIN_2_PATHS(R2_HOME_DATADIR, "rc.d") +#define R2_HOME_BIN R_JOIN_3_PATHS(R2_HOME_DATADIR, "prefix", "bin") + +#define R2_HOME_RC R_JOIN_2_PATHS(R2_HOME_CONFIGDIR, "radare2rc") +#define R2_HOME_RC_DIR R_JOIN_2_PATHS(R2_HOME_CONFIGDIR, "radare2rc.d") + +#define R2_HOME_HISTORY R_JOIN_2_PATHS(R2_HOME_CACHEDIR, "history") #define HAVE_LIB_MAGIC @HAVE_LIB_MAGIC@ #define USE_LIB_MAGIC @USE_LIB_MAGIC@ @@ -28,8 +53,6 @@ #define WITH_GPL @WITH_GPL@ -#define R2_WWWROOT R2_DATDIR "/radare2/" R2_VERSION "/www" - #define HAVE_JEMALLOC @HAVE_JEMALLOC@ #endif diff --git a/libr/io/meson.build b/libr/io/meson.build index 815e9244d0..af9079abd2 100644 --- a/libr/io/meson.build +++ b/libr/io/meson.build @@ -73,13 +73,13 @@ r_io = library('r_io', files, c_args: ['-DCORELIB=1'], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_io], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_io', filebase: 'r_io', requires: [ diff --git a/libr/lang/meson.build b/libr/lang/meson.build index 8eeaf73a8d..83bc559449 100644 --- a/libr/lang/meson.build +++ b/libr/lang/meson.build @@ -14,13 +14,13 @@ r_lang = library('r_lang', files, link_with: [r_util, r_cons], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_lang], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_lang', filebase: 'r_lang', requires: [ diff --git a/libr/magic/d/meson.build b/libr/magic/d/meson.build index 054bd8a9c5..d1e1eb3208 100644 --- a/libr/magic/d/meson.build +++ b/libr/magic/d/meson.build @@ -1,4 +1,4 @@ install_subdir('default', - install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'radare2', r2version, 'magic'), + install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'radare2', r2_version, 'magic'), strip_directory: true ) diff --git a/libr/magic/meson.build b/libr/magic/meson.build index 1acd1f4617..8ec0037e67 100644 --- a/libr/magic/meson.build +++ b/libr/magic/meson.build @@ -15,13 +15,13 @@ r_magic = library('r_magic', files, link_with: [r_util], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_magic], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_magic', filebase: 'r_magic', requires: [ diff --git a/libr/parse/meson.build b/libr/parse/meson.build index c09619d3e3..f0eb5be66d 100644 --- a/libr/parse/meson.build +++ b/libr/parse/meson.build @@ -28,13 +28,13 @@ r_parse = library('r_parse', files, link_with: [r_util, r_flag, r_syscall, r_reg, libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_parse], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_parse', filebase: 'r_parse', requires: [ diff --git a/libr/reg/meson.build b/libr/reg/meson.build index 67b8d1b6f8..09fc49058a 100644 --- a/libr/reg/meson.build +++ b/libr/reg/meson.build @@ -12,13 +12,13 @@ r_reg = library('r_reg', files, link_with: [r_util], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_reg], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_reg', filebase: 'r_reg', requires: [ diff --git a/libr/search/meson.build b/libr/search/meson.build index 6cb8e8281e..49b710a995 100644 --- a/libr/search/meson.build +++ b/libr/search/meson.build @@ -15,13 +15,13 @@ r_search = library('r_search', files, link_with: [r_util], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_search], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_search', filebase: 'r_search', requires: [ diff --git a/libr/socket/meson.build b/libr/socket/meson.build index 0c918e546e..a178839301 100644 --- a/libr/socket/meson.build +++ b/libr/socket/meson.build @@ -16,13 +16,13 @@ r_socket = library('r_socket', files, c_args: ['-DCORELIB=1'], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_socket], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_socket', filebase: 'r_socket', requires: [ diff --git a/libr/syscall/d/meson.build b/libr/syscall/d/meson.build index 52b4a6355b..21e17d3fb3 100644 --- a/libr/syscall/d/meson.build +++ b/libr/syscall/d/meson.build @@ -31,6 +31,6 @@ foreach file : sdb_files build_by_default: true, build_always: false, install: true, - install_dir: join_paths(get_option('datadir'), 'radare2', r2version, 'syscall') + install_dir: join_paths(get_option('datadir'), 'radare2', r2_version, 'syscall') ) endforeach diff --git a/libr/syscall/meson.build b/libr/syscall/meson.build index d9243b1812..1691765fd7 100644 --- a/libr/syscall/meson.build +++ b/libr/syscall/meson.build @@ -8,12 +8,12 @@ r_syscall = library('r_syscall', files, link_with: [r_util, libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate(libraries: [r_syscall], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_syscall', filebase: 'r_syscall', requires: [ diff --git a/libr/util/meson.build b/libr/util/meson.build index 12d722d1fe..e965ddd90d 100644 --- a/libr/util/meson.build +++ b/libr/util/meson.build @@ -91,13 +91,13 @@ r_util = library('r_util', files, link_with: [libr_shlr], install: true, implicit_include_directories: false, - soversion: r2libversion + soversion: r2_libversion ) pkgconfig_mod.generate( libraries: [r_util], subdirs: 'libr', - version: r2version, + version: r2_version, name: 'r_util', filebase: 'r_util', description: 'radare foundation libraries' diff --git a/libr/util/sandbox.c b/libr/util/sandbox.c index e5456ecd34..15703d5c65 100644 --- a/libr/util/sandbox.c +++ b/libr/util/sandbox.c @@ -12,7 +12,7 @@ static bool disabled = false; static bool inHomeWww(const char *path) { bool ret = false; - char *homeWww = r_str_home (".config/radare2/www/"); + char *homeWww = r_str_home (R2_HOME_WWWROOT R_SYS_DIR); if (homeWww) { if (!strncmp (path, homeWww, strlen (homeWww))) { ret = true; diff --git a/meson.build b/meson.build index aa2725e6fc..ff15508a04 100644 --- a/meson.build +++ b/meson.build @@ -6,11 +6,11 @@ pkgconfig_mod = import('pkgconfig') glob_cmd = [py3_exe, '-c', 'from sys import argv; print(";".join(__import__("glob").glob(argv[1])))'] # Get r2 version -r2version = run_command(py3_exe, 'sys/version.py') -if r2version.returncode() != 0 - r2version = 'unknown-error' +r2_version = run_command(py3_exe, 'sys/version.py') +if r2_version.returncode() != 0 + r2_version = 'unknown-error' else - r2version = r2version.stdout().strip() + r2_version = r2_version.stdout().strip() endif repo = '.' @@ -62,7 +62,7 @@ else r2birth = r2birth.stdout().strip() endif -r2libversion = host_machine.system() == 'windows' ? '' : r2version +r2_libversion = host_machine.system() == 'windows' ? '' : r2_version # system dependencies cc = meson.get_compiler('c') @@ -86,6 +86,53 @@ if get_option('static_runtime') endif endif +if host_machine.system() == 'windows' + r2_prefix = '.' + r2_libdir = 'lib' + r2_incdir = 'include/libr' + r2_datdir = 'share' + + opts1 = ['r2_libdir', 'r2_incdir', 'r2_datdir'] + foreach opt : opts1 + val = get_option(opt) + if val != '' + set_variable(opt, val) + endif + endforeach + + r2_wwwroot = join_paths(r2_datdir, 'radare2', r2_version, 'www') + r2_sdb = join_paths(r2_datdir, 'radare2', r2_version) + r2_zigns = join_paths(r2_datdir, 'radare2', r2_version, 'zigns') + r2_themes = join_paths(r2_datdir, 'radare2', r2_version, 'cons') + r2_fortunes = join_paths(r2_datdir, 'doc/radare2') + r2_hud = join_paths(r2_datdir, 'radare2', r2_version, 'hud') + + opts2 = ['r2_wwwroot', 'r2_sdb', 'r2_zigns', 'r2_themes', 'r2_fortunes', 'r2_hud'] + foreach opt : opts2 + val = get_option(opt) + if val != '' + set_variable(opt, val) + endif + endforeach + + foreach opt : opts1 + opts2 + val = get_variable(opt) + val = '\\\\'.join(val.split('/')) + set_variable(opt, val) + endforeach +else + r2_prefix = get_option('prefix') + r2_libdir = join_paths(r2_prefix, get_option('libdir')) + r2_incdir = join_paths(r2_prefix, get_option('includedir'), 'libr') + r2_datdir = join_paths(r2_prefix, get_option('datadir')) + r2_wwwroot = join_paths(r2_datdir, 'radare2', r2_version, 'www') + r2_sdb = join_paths(get_option('datadir'), 'radare2', r2_version) + r2_zigns = join_paths(get_option('datadir'), 'radare2', r2_version, 'zigns') + r2_themes = join_paths(get_option('datadir'), 'radare2', r2_version, 'cons') + r2_fortunes = join_paths(get_option('datadir'), 'doc/radare2') + r2_hud = join_paths(get_option('datadir'), 'radare2', r2_version, 'hud') +endif + # load plugin configuration subdir('libr') @@ -110,10 +157,16 @@ config_h = configure_file( userconf = configuration_data() userconf.set('DEBUGGER', 1) -userconf.set('PREFIX', get_option('prefix')) -userconf.set('LIBDIR', join_paths(get_option('prefix'), get_option('libdir'))) -userconf.set('INCLUDEDIR', join_paths(get_option('prefix'), get_option('includedir'))) -userconf.set('DATADIR', join_paths(get_option('prefix'), get_option('datadir'))) +userconf.set('PREFIX', r2_prefix) +userconf.set('LIBDIR', r2_libdir) +userconf.set('INCLUDEDIR', r2_incdir) +userconf.set('DATADIR', r2_datdir) +userconf.set('WWWROOT', r2_wwwroot) +userconf.set('SDB', r2_sdb) +userconf.set('ZIGNS', r2_zigns) +userconf.set('THEMES', r2_themes) +userconf.set('FORTUNES', r2_fortunes) +userconf.set('HUD', r2_hud) userconf.set('HAVE_LIB_MAGIC', 0) userconf.set('USE_LIB_MAGIC', 0) userconf.set('HAVE_OPENSSL', 0) @@ -138,7 +191,7 @@ r_userconf_h = configure_file( versionconf = configuration_data() versionconf.set('VERSIONCOMMIT', version_commit) -versionconf.set('R2_VERSION', r2version) +versionconf.set('R2_VERSION', r2_version) versionconf.set('R2_GITTAP', gittap) versionconf.set('R2_GITTIP', gittip) versionconf.set('R2_BIRTH', r2birth) @@ -155,7 +208,7 @@ run_command(py3_exe, '-c', '__import__("shutil").copyfile("shlr/spp/config.def.h pcconf = configuration_data() pcconf.set('PREFIX', get_option('prefix')) pcconf.set('LIBDIR', join_paths(get_option('prefix'), get_option('libdir'))) -pcconf.set('VERSION', r2version) +pcconf.set('VERSION', r2_version) libr_pc = configure_file( input: 'libr/libr.pc.acr', output: 'libr.pc', @@ -218,12 +271,12 @@ else libr2_dep = declare_dependency( link_with: libr2_lib, include_directories: libr2_inc, - version: r2version + version: r2_version ) endif install_subdir('shlr/www', - install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'radare2', r2version) + install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'radare2', r2_version) ) fortunes_files = run_command(glob_cmd + ['doc/fortunes.*']).stdout().strip().split(';') @@ -242,6 +295,6 @@ install_data(man7_files, ) install_data('doc/hud', - install_dir: join_paths(get_option('datadir'), 'radare2', r2version, 'hud'), + install_dir: join_paths(get_option('datadir'), 'radare2', r2_version, 'hud'), rename: 'main' ) diff --git a/meson_options.txt b/meson_options.txt index a5c9c17955..b042aaa414 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,10 @@ -option('static_runtime', type: 'boolean', value: false) \ No newline at end of file +option('static_runtime', type: 'boolean', value: false) +option('r2_libdir', type: 'string', value: '') +option('r2_incdir', type: 'string', value: '') +option('r2_datdir', type: 'string', value: '') +option('r2_wwwroot', type: 'string', value: '') +option('r2_sdb', type: 'string', value: '') +option('r2_zigns', type: 'string', value: '') +option('r2_themes', type: 'string', value: '') +option('r2_fortunes', type: 'string', value: '') +option('r2_hud', type: 'string', value: '')