mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-29 05:40:16 -04:00
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>
This commit is contained in:
parent
e475decf1d
commit
f452e41264
4 changed files with 58 additions and 59 deletions
|
|
@ -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
|
||||
45
src/embed.py
Normal file
45
src/embed.py
Normal file
|
|
@ -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};')
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue