diff --git a/Makefile.host b/Makefile.host index 3220f7add..66f3ccce0 100644 --- a/Makefile.host +++ b/Makefile.host @@ -15,12 +15,7 @@ FALSE = false CFLAGS ?= -Wall -Werror -O3 CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES) -ifneq (,$(PM3_BIN_PATH)) - CFLAGS += -DPM3_BIN_PATH=\"$(PM3_BIN_PATH)\" -endif -ifneq (,$(PM3_SHARE_PATH)) - CFLAGS += -DPM3_SHARE_PATH=\"$(PM3_SHARE_PATH)\" -endif +PREFIX ?= /usr/local platform = $(shell uname) diff --git a/client/Makefile b/client/Makefile index ccf7d5ab8..4a2e12329 100644 --- a/client/Makefile +++ b/client/Makefile @@ -66,12 +66,7 @@ INCLUDES_CLIENT = -I. -I../include -I../common -Iuart $(LIBS) CFLAGS ?= -Wall -Werror -g -O3 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(INCLUDES_CLIENT) -ifneq (,$(PM3_BIN_PATH)) - PM3CFLAGS += -DPM3_BIN_PATH=\"$(PM3_BIN_PATH)\" -endif -ifneq (,$(PM3_SHARE_PATH)) - PM3CFLAGS += -DPM3_SHARE_PATH=\"$(PM3_SHARE_PATH)\" -endif +PREFIX ?= /usr/local ifneq (,$(findstring MINGW,$(platform))) PM3CFLAGS += -mno-ms-bitfields -fexec-charset=cp850 endif diff --git a/client/fileutils.c b/client/fileutils.c index 3c98b345a..1c0403294 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -855,9 +855,11 @@ int searchAndList(const char *pm3dir, const char *ext) { filelist(script_directory_path, ext, false, false); } // try pm3 dirs in pm3 installation dir (install mode) - { - char script_directory_path[strlen(PM3_SHARE_PATH) + strlen(pm3dir) + 1]; - strcpy(script_directory_path, PM3_SHARE_PATH); + const char *exec_path = get_my_executable_directory(); + if (exec_path != NULL) { + char script_directory_path[strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(pm3dir) + 1]; + strcpy(script_directory_path, exec_path); + strcat(script_directory_path, PM3_SHARE_RELPATH); strcat(script_directory_path, pm3dir); filelist(script_directory_path, ext, true, false); } @@ -975,10 +977,11 @@ static int searchFinalFile(char **foundpath, const char *pm3dir, const char *sea } // try pm3 dirs in pm3 installation dir (install mode) { - char *path = calloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); + char *path = calloc(strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; - strcpy(path, PM3_SHARE_PATH); + strcpy(path, exec_path); + strcat(path, PM3_SHARE_RELPATH); strcat(path, pm3dir); strcat(path, filename); if ((g_debugMode == 2) && (!silent)) { diff --git a/client/scripting.c b/client/scripting.c index 6c2dbb07c..33e7c6c42 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -1175,7 +1175,7 @@ int set_pm3_libraries(lua_State *L) { } char *user_path = getenv("HOME"); if (user_path != NULL) { - // from the ~/.proxmark3/luascripts/ directory + // from the $HOME/.proxmark3/luascripts/ directory char scripts_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(scripts_path, user_path); strcat(scripts_path, PM3_USER_DIRECTORY); @@ -1183,7 +1183,7 @@ int set_pm3_libraries(lua_State *L) { strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); - // from the ~/.proxmark3/lualib/ directory + // from the $HOME/.proxmark3/lualib/ directory char libraries_path[strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; strcpy(libraries_path, user_path); strcat(libraries_path, PM3_USER_DIRECTORY); @@ -1192,16 +1192,18 @@ int set_pm3_libraries(lua_State *L) { setLuaPath(L, libraries_path); } - if (strlen(PM3_SHARE_PATH) != 0 || strlen(LUA_SCRIPTS_SUBDIR) != 0 || strlen(LUA_LIBRARIES_WILDCARD) != 0) { - // from the /usr/local/share/proxmark3/luascripts/ directory - char scripts_path[strlen(PM3_SHARE_PATH) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(scripts_path, PM3_SHARE_PATH); + if (exec_path != NULL) { + // from the $PREFIX/share/proxmark3/luascripts/ directory + char scripts_path[strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(LUA_SCRIPTS_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(scripts_path, exec_path); + strcat(scripts_path, PM3_SHARE_RELPATH); strcat(scripts_path, LUA_SCRIPTS_SUBDIR); strcat(scripts_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, scripts_path); - // from the /usr/local/share/proxmark3/lualib/ directory - char libraries_path[strlen(PM3_SHARE_PATH) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; - strcpy(libraries_path, PM3_SHARE_PATH); + // from the $PREFIX/share/proxmark3/lualib/ directory + char libraries_path[strlen(exec_path) + strlen(PM3_SHARE_RELPATH) + strlen(LUA_LIBRARIES_SUBDIR) + strlen(LUA_LIBRARIES_WILDCARD) + 1]; + strcpy(libraries_path, exec_path); + strcat(libraries_path, PM3_SHARE_RELPATH); strcat(libraries_path, LUA_LIBRARIES_SUBDIR); strcat(libraries_path, LUA_LIBRARIES_WILDCARD); setLuaPath(L, libraries_path); diff --git a/include/common.h b/include/common.h index c4c5d6370..bdda44aae 100644 --- a/include/common.h +++ b/include/common.h @@ -16,22 +16,19 @@ #include #include -// brew prefixes are a bit weird so we've to split bin & share to be prepared: -#ifndef PM3_BIN_PATH -# define PM3_BIN_PATH "/usr/local/bin/" -#endif -#ifndef PM3_SHARE_PATH -# define PM3_SHARE_PATH "/usr/local/share/proxmark3/" -#endif -// PM3_USER_DIRECTORY will be expanded as if with a "~" upfront, e.g. ~/.proxmark3/ -#define PM3_USER_DIRECTORY "/.proxmark3/" +#define PATHSEP "/" +// PM3 share path relative to executable when installed +#define PM3_SHARE_RELPATH ".." PATHSEP "share" PATHSEP "proxmark3" PATHSEP + +// PM3_USER_DIRECTORY will be expanded from $HOME, e.g. ~/.proxmark3/ +#define PM3_USER_DIRECTORY PATHSEP ".proxmark3" PATHSEP // PM3 subdirectories: -#define DICTIONARIES_SUBDIR "dictionaries/" -#define LUA_LIBRARIES_SUBDIR "lualibs/" -#define LUA_SCRIPTS_SUBDIR "luascripts/" -#define RESOURCES_SUBDIR "resources/" -#define TRACES_SUBDIR "traces/" +#define DICTIONARIES_SUBDIR "dictionaries" PATHSEP +#define LUA_LIBRARIES_SUBDIR "lualibs" PATHSEP +#define LUA_SCRIPTS_SUBDIR "luascripts" PATHSEP +#define RESOURCES_SUBDIR "resources" PATHSEP +#define TRACES_SUBDIR "traces" PATHSEP #define PACKED __attribute__((packed))