2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include <architecture_private.h>
15 #include <directories.h>
16 #include <find_directory_private.h>
17 #include <runtime_loader.h>
20 static const char* const kArchitecture
= B_HAIKU_ABI_NAME
;
21 static const char* const kPrimaryArchitecture
= __HAIKU_PRIMARY_PACKAGING_ARCH
;
23 #ifdef __HAIKU_ARCH_X86
24 static const char* const kSiblingArchitectures
[] = {"x86_gcc2", "x86"};
26 static const char* const kSiblingArchitectures
[] = {};
29 static const size_t kSiblingArchitectureCount
30 = sizeof(kSiblingArchitectures
) / sizeof(const char*);
34 has_secondary_architecture(const char* architecture
)
36 if (strcmp(architecture
, kPrimaryArchitecture
) == 0)
39 char path
[B_PATH_NAME_LENGTH
];
40 snprintf(path
, sizeof(path
), kSystemLibDirectory
"/%s/libroot.so",
44 return lstat(path
, &st
) == 0;
59 __get_primary_architecture()
61 return kPrimaryArchitecture
;
66 __get_secondary_architectures(const char** architectures
, size_t count
)
70 // If this is an architecture that could be a primary or secondary
71 // architecture, check for which architectures a libroot.so is present.
72 if (kSiblingArchitectureCount
> 0) {
73 for (size_t i
= 0; i
< kSiblingArchitectureCount
; i
++) {
74 const char* architecture
= kSiblingArchitectures
[i
];
75 if (!has_secondary_architecture(architecture
))
79 architectures
[index
] = architecture
;
89 __get_architectures(const char** architectures
, size_t count
)
92 return __get_secondary_architectures(NULL
, 0) + 1;
94 architectures
[0] = __get_primary_architecture();
95 return __get_secondary_architectures(architectures
+ 1, count
-1) + 1;
100 __guess_architecture_for_path(const char* path
)
102 if (kSiblingArchitectureCount
== 0)
103 return kPrimaryArchitecture
;
105 // ask the runtime loader
106 const char* architecture
;
107 if (__gRuntimeLoader
->get_executable_architecture(path
, &architecture
)
109 // verify that it is one of the sibling architectures
110 for (size_t i
= 0; i
< kSiblingArchitectureCount
; i
++) {
111 if (strcmp(architecture
, kSiblingArchitectures
[i
]) == 0)
112 return kSiblingArchitectures
[i
];
116 // guess from the given path
117 architecture
= __guess_secondary_architecture_from_path(path
,
118 kSiblingArchitectures
, kSiblingArchitectureCount
);
120 return architecture
!= NULL
&& has_secondary_architecture(architecture
)
121 ? architecture
: kPrimaryArchitecture
;
125 B_DEFINE_WEAK_ALIAS(__get_architecture
, get_architecture
);
126 B_DEFINE_WEAK_ALIAS(__get_primary_architecture
, get_primary_architecture
);
127 B_DEFINE_WEAK_ALIAS(__get_secondary_architectures
, get_secondary_architectures
);
128 B_DEFINE_WEAK_ALIAS(__get_architectures
, get_architectures
);
129 B_DEFINE_WEAK_ALIAS(__guess_architecture_for_path
, guess_architecture_for_path
);