@@ -47,7 +47,7 @@ gboolean main_option_time_save = FALSE;
4747gboolean main_option_profile = FALSE;
4848gboolean main_option_no_load_menus = FALSE;
4949
50- static const char * main_argv0 = NULL ; /* argv[0] */
50+ const char * main_argv0 = NULL ; /* argv[0] */
5151
5252static char prefix_buffer [VIPS_PATH_MAX ];
5353static gboolean prefix_valid = FALSE;
@@ -70,9 +70,36 @@ const char *
7070get_prefix (void )
7171{
7272 if (!prefix_valid ) {
73+ g_autofree char * basename = g_path_get_basename (main_argv0 );
74+ g_autofree char * argv0_path = NULL ;
75+
7376 const char * prefix ;
7477
75- if (!(prefix = vips_guess_prefix (main_argv0 , "VIPSHOME" ))) {
78+ prefix = vips_guess_prefix (main_argv0 , "VIPSHOME" );
79+
80+ if (!prefix ||
81+ !existsf ("%s/share/nip4" , prefix )) {
82+ /* The libvips guesser failed to find our install area ... try
83+ * searching the path for our exe name.
84+ *
85+ * This can happen with homebrew, for example, where the
86+ * compile-time libvips prefix will not match the nip4 prefix.
87+ */
88+ GSList * path = path_parse (g_getenv ("PATH" ));
89+ argv0_path =
90+ (char * ) path_map (path , basename , (path_map_fn ) g_strdup , NULL );
91+ g_slist_free_full (g_steal_pointer (& path ), g_free );
92+
93+ g_autofree char * trailing = g_strjoin ("/" , "bin" , basename , NULL );
94+ if (argv0_path &&
95+ is_postfix (trailing , argv0_path ))
96+ argv0_path [strlen (argv0_path ) - strlen (trailing )] = '\0' ;
97+
98+ prefix = argv0_path ;
99+ }
100+
101+ if (!prefix ||
102+ !existsf ("%s/share/nip4" , prefix )) {
76103 error_top (_ ("Unable to find install area" ));
77104 error_vips ();
78105
0 commit comments