Skip to content

Commit dc442ef

Browse files
committed
dlopennote: update documentation and internal variable names
1 parent 69c5528 commit dc442ef

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

include/SDL3/SDL_dlopennote.h

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,23 @@
3232
* this CMake snippet to check for support:
3333
*
3434
* ```cmake
35-
* set(CHECK_ELF_DLNOTES_SRC [==[
36-
* #ifndef __ELF__
37-
* ELF DL notes is only supported on ELF platforms
38-
* #endif
39-
* __attribute__ ((used,aligned(4),section(".note.dlopen"))) static const struct {
40-
* struct { int a; int b; int c; } hdr; char name[4]; __attribute__((aligned(4))) char json[24];
41-
* } dlnote = { { 4, 0x407c0c0aU, 16 }, "FDO", "[\\"a\\":{\\"a\\":\\"1\\",\\"b\\":\\"2\\"}]" };
42-
* int main(int argc, char *argv[]) {
43-
* return argc + dlnote.hdr.a;
44-
* }
45-
* ]==])
46-
* check_c_source_compiles("${CHECK_ELF_DLNOTES_SRC}" COMPILER_SUPPORTS_ELFNOTES)
47-
* if(NOT COMPILER_SUPPORTS_ELFNOTES)
48-
* set(SDL_DISABLE_DLOPEN_NOTES TRUE)
49-
* endif()
35+
* include(CheckCSourceCompiles)
36+
* find_package(SDL3 REQUIRED CONFIG COMPONENTS Headers)
37+
* list(APPEND CMAKE_REQUIRED_LIBRARIES SDL3::Headers)
38+
* check_c_source_compiles([==[
39+
* #include <SDL3/SDL_dlopennote.h>
40+
* SDL_ELF_NOTE_DLOPEN("sdl-video",
41+
* "Support for video through SDL",
42+
* SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
43+
* "libSDL-1.2.so.0", "libSDL-2.0.so.0", "libSDL3.so.0"
44+
* );
45+
* int main(int argc, char *argv[]) {
46+
* return argc + argv[0][1];
47+
* }
48+
* ]==] COMPILER_SUPPORTS_SDL_ELF_NOTE_DLOPEN)
49+
* if(NOT COMPILER_SUPPORTS_SDL_ELF_NOTE_DLOPEN)
50+
* add_compile_definitions(-DSDL_DISABLE_DLOPEN_NOTE)
51+
* endif()
5052
* ```
5153
*/
5254

@@ -141,33 +143,34 @@
141143
#define SDL_ELF_NOTE_INTERNAL(json, variable_name) \
142144
SDL_ELF_NOTE_INTERNAL2(json, variable_name)
143145

144-
#define SDL_SONAME_ARRAY1(N1) "[\"" N1 "\"]"
145-
#define SDL_SONAME_ARRAY2(N1,N2) "[\"" N1 "\",\"" N2 "\"]"
146-
#define SDL_SONAME_ARRAY3(N1,N2,N3) "[\"" N1 "\",\"" N2 "\",\"" N3 "\"]"
147-
#define SDL_SONAME_ARRAY4(N1,N2,N3,N4) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\"]"
148-
#define SDL_SONAME_ARRAY5(N1,N2,N3,N4,N5) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\"]"
149-
#define SDL_SONAME_ARRAY6(N1,N2,N3,N4,N5,N6) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\"]"
150-
#define SDL_SONAME_ARRAY7(N1,N2,N3,N4,N5,N6,N7) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\"]"
151-
#define SDL_SONAME_ARRAY8(N1,N2,N3,N4,N5,N6,N7,N8) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\",\"" N8 "\"]"
152-
#define SDL_SONAME_ARRAY_GET(N1,N2,N3,N4,N5,N6,N7,N8,NAME,...) NAME
153-
#define SDL_SONAME_ARRAY(...) \
154-
SDL_SONAME_ARRAY_GET(__VA_ARGS__, \
155-
SDL_SONAME_ARRAY8, \
156-
SDL_SONAME_ARRAY7, \
157-
SDL_SONAME_ARRAY6, \
158-
SDL_SONAME_ARRAY5, \
159-
SDL_SONAME_ARRAY4, \
160-
SDL_SONAME_ARRAY3, \
161-
SDL_SONAME_ARRAY2, \
162-
SDL_SONAME_ARRAY1 \
146+
#define SDL_DLNOTE_JSON_ARRAY1(N1) "[\"" N1 "\"]"
147+
#define SDL_DLNOTE_JSON_ARRAY2(N1,N2) "[\"" N1 "\",\"" N2 "\"]"
148+
#define SDL_DLNOTE_JSON_ARRAY3(N1,N2,N3) "[\"" N1 "\",\"" N2 "\",\"" N3 "\"]"
149+
#define SDL_DLNOTE_JSON_ARRAY4(N1,N2,N3,N4) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\"]"
150+
#define SDL_DLNOTE_JSON_ARRAY5(N1,N2,N3,N4,N5) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\"]"
151+
#define SDL_DLNOTE_JSON_ARRAY6(N1,N2,N3,N4,N5,N6) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\"]"
152+
#define SDL_DLNOTE_JSON_ARRAY7(N1,N2,N3,N4,N5,N6,N7) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\"]"
153+
#define SDL_DLNOTE_JSON_ARRAY8(N1,N2,N3,N4,N5,N6,N7,N8) "[\"" N1 "\",\"" N2 "\",\"" N3 "\",\"" N4 "\",\"" N5 "\",\"" N6 "\",\"" N7 "\",\"" N8 "\"]"
154+
#define SDL_DLNOTE_JSON_ARRAY_GET(N1,N2,N3,N4,N5,N6,N7,N8,NAME,...) NAME
155+
#define SDL_DLNOTE_JSON_ARRAY(...) \
156+
SDL_DLNOTE_JSON_ARRAY_GET( \
157+
__VA_ARGS__, \
158+
SDL_DLNOTE_JSON_ARRAY8, \
159+
SDL_DLNOTE_JSON_ARRAY7, \
160+
SDL_DLNOTE_JSON_ARRAY6, \
161+
SDL_DLNOTE_JSON_ARRAY5, \
162+
SDL_DLNOTE_JSON_ARRAY4, \
163+
SDL_DLNOTE_JSON_ARRAY3, \
164+
SDL_DLNOTE_JSON_ARRAY2, \
165+
SDL_DLNOTE_JSON_ARRAY1 \
163166
)(__VA_ARGS__)
164167

165168
/* Create "unique" variable name using __LINE__,
166-
* so creating elf notes on the same line is not supported
169+
* so creating multiple elf notes on the same line is not supported
167170
*/
168-
#define SDL_ELF_NOTE_JOIN2(A,B) A##B
169-
#define SDL_ELF_NOTE_JOIN(A,B) SDL_ELF_NOTE_JOIN2(A,B)
170-
#define SDL_ELF_NOTE_UNIQUE_NAME SDL_ELF_NOTE_JOIN(s_SDL_dlopen_note_, __LINE__)
171+
#define SDL_DLNOTE_JOIN2(A,B) A##B
172+
#define SDL_DLNOTE_JOIN(A,B) SDL_DLNOTE_JOIN2(A,B)
173+
#define SDL_DLNOTE_UNIQUE_NAME SDL_DLNOTE_JOIN(s_SDL_dlopen_note_, __LINE__)
171174

172175
/**
173176
* Note that your application has dynamic shared library dependencies.
@@ -206,8 +209,8 @@
206209
"[{\"feature\":\"" feature \
207210
"\",\"description\":\"" description \
208211
"\",\"priority\":\"" priority \
209-
"\",\"soname\":" SDL_SONAME_ARRAY(__VA_ARGS__) "}]", \
210-
SDL_ELF_NOTE_UNIQUE_NAME)
212+
"\",\"soname\":" SDL_DLNOTE_JSON_ARRAY(__VA_ARGS__) "}]", \
213+
SDL_DLNOTE_UNIQUE_NAME)
211214

212215
#elif defined(__GNUC__) && __GNUC__ < 3
213216

0 commit comments

Comments
 (0)