File: objfw-embed

package info (click to toggle)
objfw 1.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,644 kB
  • sloc: objc: 101,491; asm: 5,083; sh: 4,092; makefile: 1,574; ansic: 709; xml: 367; pascal: 214
file content (54 lines) | stat: -rwxr-xr-x 1,358 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
#
#  Copyright (c) 2008-2025 Jonathan Schleifer <js@nil.im>
#
#  All rights reserved.
#
#  This program is free software: you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License version 3.0 only,
#  as published by the Free Software Foundation.
#
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
#  version 3.0 for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  version 3.0 along with this program. If not, see
#  <https://www.gnu.org/licenses/>.
#

if test $# != 3; then
	echo "Usage: $0 source_file filename output.m" 1>&2
	exit 1
fi

exec 1>$3

cat <<EOF
#include <stddef.h>
#include <stdint.h>

#ifdef OF_COMPILING_OBJFW
# import "OFEmbeddedIRIHandler.h"
#else
# if defined(__has_feature) && __has_feature(modules)
@import ObjFW;
# else
#  import <ObjFW/OFEmbeddedIRIHandler.h>
# endif
#endif

static const uint8_t bytes[] = {
EOF
od -vtx1 "$1" | cut -d' ' -sf2- | \
    sed '/^ *$/d;s/^ *//;s/ *$//;s/  */ /g;s/^/0x/;s/ /, 0x/g;s/$/,/'
cat <<EOF
};

static void __attribute__((__constructor__))
ctor(void)
{
	OFRegisterEmbeddedFile(@"$2", bytes, sizeof(bytes));
}
EOF