$OpenBSD: patch-tools_build_src_engine_jam_cpp,v 1.3 2021/09/19 05:23:29 rsadowski Exp $

[PATCH] Add a default exec path logic.

This adds default/fallback logic to determine the b2 exec absolute path
as possible. It uses the arg0 and current dir or path to construct the
liekliest path.

* Fix `b2` executable path determination for platforms that don't have a
  native method of getting the path to executables, like OpenBSD.

Index: tools/build/src/engine/jam.cpp
--- tools/build/src/engine/jam.cpp.orig
+++ tools/build/src/engine/jam.cpp
@@ -707,76 +707,3 @@ int main( int argc, char * * argv )
 
     return status ? EXITBAD : EXITOK;
 }
-
-
-/*
- * executable_path()
- */
-
-#if defined(_WIN32)
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-char * executable_path( char const * argv0 )
-{
-    char buf[ 1024 ];
-    DWORD const ret = GetModuleFileNameA( NULL, buf, sizeof( buf ) );
-    return ( !ret || ret == sizeof( buf ) ) ? NULL : strdup( buf );
-}
-#elif defined(__APPLE__)  /* Not tested */
-# include <mach-o/dyld.h>
-char *executable_path( char const * argv0 )
-{
-    char buf[ 1024 ];
-    uint32_t size = sizeof( buf );
-    return _NSGetExecutablePath( buf, &size ) ? NULL : strdup( buf );
-}
-#elif defined(sun) || defined(__sun)  /* Not tested */
-# include <stdlib.h>
-char * executable_path( char const * argv0 )
-{
-    const char * execname = getexecname();
-    return execname ? strdup( execname ) : NULL;
-}
-#elif defined(__FreeBSD__)
-# include <sys/sysctl.h>
-char * executable_path( char const * argv0 )
-{
-    int mib[ 4 ] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
-    char buf[ 1024 ];
-    size_t size = sizeof( buf );
-    sysctl( mib, 4, buf, &size, NULL, 0 );
-    return ( !size || size == sizeof( buf ) ) ? NULL : strndup( buf, size );
-}
-#elif defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__)
-# include <unistd.h>
-char * executable_path( char const * argv0 )
-{
-    char buf[ 1024 ];
-    ssize_t const ret = readlink( "/proc/self/exe", buf, sizeof( buf ) );
-    return ( !ret || ret == sizeof( buf ) ) ? NULL : strndup( buf, ret );
-}
-#elif defined(OS_VMS)
-# include <unixlib.h>
-char * executable_path( char const * argv0 )
-{
-    char * vms_path = NULL;
-    char * posix_path = NULL;
-    char * p;
-
-    /* On VMS argv[0] shows absolute path to the image file.
-     * So, just remove VMS file version and translate path to POSIX-style.
-     */
-    vms_path = strdup( argv0 );
-    if ( vms_path && ( p = strchr( vms_path, ';') ) ) *p = '\0';
-    posix_path = decc$translate_vms( vms_path );
-    if ( vms_path ) free( vms_path );
-
-    return posix_path > 0 ? strdup( posix_path ) : NULL;
-}
-#else
-char * executable_path( char const * argv0 )
-{
-    /* If argv0 is an absolute path, assume it is the right absolute path. */
-    return argv0[ 0 ] == '/' ? strdup( argv0 ) : NULL;
-}
-#endif
