aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--epan/wslua/init_wslua.c19
-rw-r--r--epan/wslua/wslua_dir.c3
-rw-r--r--epan/wslua/wslua_util.c20
-rw-r--r--wsutil/CMakeLists.txt7
-rw-r--r--wsutil/filesystem.c15
5 files changed, 43 insertions, 21 deletions
diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c
index 878b38ca55..ce60aa8644 100644
--- a/epan/wslua/init_wslua.c
+++ b/epan/wslua/init_wslua.c
@@ -894,18 +894,17 @@ void wslua_init(register_cb cb, gpointer client_data) {
WSLUA_REG_GLOBAL_NUMBER(L,"DESEGMENT_ONE_MORE_SEGMENT",DESEGMENT_ONE_MORE_SEGMENT);
/* load system's init.lua */
- if (running_in_build_directory()) {
- /* Running from build directory, try the source directory (Autotools) */
+ filename = get_datafile_path("init.lua");
+ /*
+ * CMake will normally always succeed with get_datafile_path (see also
+ * comments in wslua_get_actual_filename() and get_datafile_dir()), but for
+ * autotools we need to look in the build directory for an autogenerated
+ * epan/wslua/init.lua file.
+ */
+ if (!file_exists(filename) && running_in_build_directory()) {
+ g_free(filename);
filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "epan" G_DIR_SEPARATOR_S "wslua"
G_DIR_SEPARATOR_S "init.lua", get_progfile_dir());
- if (( ! file_exists(filename))) {
- /* Try the CMake output directory */
- g_free(filename);
- filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "init.lua",
- get_progfile_dir());
- }
- } else {
- filename = get_datafile_path("init.lua");
}
if (( file_exists(filename))) {
diff --git a/epan/wslua/wslua_dir.c b/epan/wslua/wslua_dir.c
index 708683e124..c467132706 100644
--- a/epan/wslua/wslua_dir.c
+++ b/epan/wslua/wslua_dir.c
@@ -308,8 +308,7 @@ WSLUA_CONSTRUCTOR Dir_global_config_path(lua_State* L) {
if (( ! file_exists(filename))) {
/* Try the CMake output directory */
g_free(filename);
- filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
- get_progfile_dir(), fname);
+ filename = get_datafile_path(fname);
}
} else {
filename = get_datafile_path(fname);
diff --git a/epan/wslua/wslua_util.c b/epan/wslua/wslua_util.c
index 644106a89d..d51150b8f1 100644
--- a/epan/wslua/wslua_util.c
+++ b/epan/wslua/wslua_util.c
@@ -223,22 +223,28 @@ char* wslua_get_actual_filename(const char* fname) {
}
g_free(filename);
+ /*
+ * Try to look in global data directory, nothing extraordinary for normal
+ * installations. For executions from the build dir, it will look for files
+ * copied to DATAFILE_DIR (cmake). In case autotools was used, files were
+ * not copied to that directory, so the next line will return a non-existing
+ * file.
+ */
filename = get_datafile_path(fname_clean);
if ( file_exists(filename) ) {
return filename;
}
g_free(filename);
+ /*
+ * Fallback for autotools: assume that this is not an autogenerated file
+ * (like init.lua) but something that is available in the source tree (e.g.
+ * epan/wslua/console.lua). Assume that get_datafile_dir() returns the path
+ * to the source tree (TOP_SRCDIR).
+ */
if (running_in_build_directory()) {
- /* Running in build directory, try the source directory (Autotools) */
filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "epan" G_DIR_SEPARATOR_S "wslua"
G_DIR_SEPARATOR_S "%s", get_datafile_dir(), fname_clean);
- if (( ! file_exists(filename))) {
- /* Try the CMake output directory */
- g_free(filename);
- filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s",
- get_progfile_dir(), fname_clean);
- }
if ( file_exists(filename) ) {
return filename;
}
diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt
index 8b9cf011d8..84a3e1465e 100644
--- a/wsutil/CMakeLists.txt
+++ b/wsutil/CMakeLists.txt
@@ -249,7 +249,12 @@ if(NOT ${ENABLE_STATIC})
)
endif()
-add_definitions( -DTOP_SRCDIR=\"${CMAKE_SOURCE_DIR}\" )
+# Export build-time datadir (note: the macro "DATAFILE_DIR" is defined in
+# config.h and points to the install-time data directory, hence the different
+# name).
+set_property(SOURCE filesystem.c APPEND PROPERTY
+ COMPILE_DEFINITIONS BUILD_TIME_DATAFILE_DIR="${DATAFILE_DIR}"
+)
CHECKAPI(
NAME
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c
index a7b2329f90..4fffcd4016 100644
--- a/wsutil/filesystem.c
+++ b/wsutil/filesystem.c
@@ -886,7 +886,20 @@ get_datafile_dir(void)
* Use the top-level source directory as the datafile directory
* because most of our data files (radius/, COPYING) are there.
*/
- datafile_dir = g_strdup(TOP_SRCDIR);
+#ifdef TOP_SRCDIR
+ /*
+ * When TOP_SRCDIR is defined, assume autotools where files are not
+ * copied to the build directory. This fallback location is relied on by
+ * wslua_get_actual_filename().
+ */
+ datafile_dir = TOP_SRCDIR;
+#else
+ /*
+ * Otherwise assume CMake. Here, data files (console.lua, radius/, etc.)
+ * are copied to the build directory during the build.
+ */
+ datafile_dir = BUILD_TIME_DATAFILE_DIR;
+#endif
return datafile_dir;
} else {
if (g_getenv("WIRESHARK_DATA_DIR") && !started_with_special_privs()) {