ObjFW  objfw-embed at [0a26fb51df]

File utils/objfw-embed artifact 0311eeeecc part of check-in 0a26fb51df


#!/bin/sh
#
#  Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
#
#  All rights reserved.
#
#  This file is part of ObjFW. It may be distributed under the terms of the
#  Q Public License 1.0, which can be found in the file LICENSE.QPL included in
#  the packaging of this file.
#
#  Alternatively, it may be distributed under the terms of the GNU General
#  Public License, either version 2 or 3, which can be found in the file
#  LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
#  file.
#

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
# import <ObjFW/OFEmbeddedIRIHandler.h>
#endif

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

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