diff options
| author | Simon Ser <contact@emersion.fr> | 2020-12-15 20:35:25 +0100 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2021-05-10 22:08:45 +0000 |
| commit | f452e41264387dee4fd737cbf1af58b34b53941b (patch) | |
| tree | 9d5e425408d00363fc6b650fe5d82799da43989b /src | |
| parent | src: Add missing new lines to log messages (diff) | |
| download | wayland-f452e41264387dee4fd737cbf1af58b34b53941b.tar wayland-f452e41264387dee4fd737cbf1af58b34b53941b.tar.gz wayland-f452e41264387dee4fd737cbf1af58b34b53941b.tar.bz2 wayland-f452e41264387dee4fd737cbf1af58b34b53941b.tar.lz wayland-f452e41264387dee4fd737cbf1af58b34b53941b.tar.xz wayland-f452e41264387dee4fd737cbf1af58b34b53941b.tar.zst wayland-f452e41264387dee4fd737cbf1af58b34b53941b.zip | |
build: replace assembly embedding with Python script
This allows Meson to properly track dependencies and re-build the scanner when
editing the dtd. We also stop depending on GNU as' .incbin and make the
embedding less obscure.
Signed-off-by: Simon Ser <contact@emersion.fr>
Diffstat (limited to 'src')
| -rw-r--r-- | src/dtddata.S | 50 | ||||
| -rw-r--r-- | src/embed.py | 45 | ||||
| -rw-r--r-- | src/meson.build | 12 | ||||
| -rw-r--r-- | src/scanner.c | 10 |
4 files changed, 58 insertions, 59 deletions
diff --git a/src/dtddata.S b/src/dtddata.S deleted file mode 100644 index 2405066..0000000 --- a/src/dtddata.S +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2015 Collabora, Ltd. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * Avoid executable stack. - * from: https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart - */ -#if defined(__linux__) && defined(__ELF__) -.section .note.GNU-stack,"",%progbits -#endif - -/* from: http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967#comment-348129 */ - -.macro binfile name file - .p2align 2 - .globl \name\()_begin -\name\()_begin: - .incbin "\file" -\name\()_end: - .byte 0 - .p2align 2 - .globl \name\()_len -\name\()_len: - .int (\name\()_end - \name\()_begin) -.endm - -.section .rodata -binfile DTD_DATA src/wayland.dtd.embed diff --git a/src/embed.py b/src/embed.py new file mode 100644 index 0000000..abebb15 --- /dev/null +++ b/src/embed.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +""" +Simple C data embedder + +License: MIT + +Copyright (c) 2020 Simon Ser + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + +import sys + +if len(sys.argv) != 3: + print('usage: ' + sys.argv[0] + ' <filename> <ident>', file=sys.stderr) + sys.exit(1) + +filename = sys.argv[1] +ident = sys.argv[2] + +with open(filename, 'rb') as f: + buf = f.read() + +print('static const char ' + ident + '[] = {\n\t', end='') +for i in range(len(buf)): + ch = buf[i:i+1] + print('0x' + ch.hex() + ', ', end='') +print('\n};') diff --git a/src/meson.build b/src/meson.build index b6b248c..ec00d81 100644 --- a/src/meson.build +++ b/src/meson.build @@ -34,13 +34,17 @@ if get_option('scanner') scanner_args += '-DHAVE_LIBXML=1' endif - configure_file( + prog_embed = find_program('embed.py', native: true) + + embed_dtd = custom_target( + 'wayland.dtd.h', input: '../protocol/wayland.dtd', - output: 'wayland.dtd.embed', - copy: true + output: 'wayland.dtd.h', + command: [ prog_embed, '@INPUT@', 'wayland_dtd' ], + capture: true ) - wayland_scanner_sources = [ 'scanner.c', 'dtddata.S' ] + wayland_scanner_sources = [ 'scanner.c', embed_dtd ] wayland_scanner_includes = [ root_inc, protocol_inc ] wayland_scanner = executable( diff --git a/src/scanner.c b/src/scanner.c index 36ac905..46bdfc2 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -41,9 +41,9 @@ #if HAVE_LIBXML #include <libxml/parser.h> -/* Embedded wayland.dtd file, see dtddata.S */ -extern char DTD_DATA_begin; -extern int DTD_DATA_len; +/* Embedded wayland.dtd file */ +/* static const char wayland_dtd[]; wayland.dtd */ +#include "wayland.dtd.h" #endif /* Expat must be included after libxml as both want to declare XMLCALL; see @@ -112,8 +112,8 @@ is_dtd_valid(FILE *input, const char *filename) if (!ctx || !dtdctx) abort(); - buffer = xmlParserInputBufferCreateMem(&DTD_DATA_begin, - DTD_DATA_len, + buffer = xmlParserInputBufferCreateMem(wayland_dtd, + sizeof(wayland_dtd), XML_CHAR_ENCODING_UTF8); if (!buffer) { fprintf(stderr, "Failed to init buffer for DTD.\n"); |
