Publish precompiled tp6.c blob (lots of dirty hacks)

This commit is contained in:
mkrsym1
2023-07-05 23:59:27 +03:00
parent 94efee7496
commit df1f611199
6 changed files with 102 additions and 42 deletions

View File

@ -1,20 +1,41 @@
#!/usr/bin/env bash
# I hate this.
linker="x86_64-w64-mingw32-ld"
# Output config (terrible)
if [ "x$1" = "x--header" ]; then
gen_header=1
shift
fi
if [ "x$1" = "x--object" ]; then
gen_object=1
shift
fi
# Read project directory
proj_dir=`realpath "$1"`
shift
# Read output file destinations
resources_o=`realpath "$1"`
shift
resources_h=`realpath "$1"`
shift
if [ "x${gen_object}" = "x1" ]; then
resources_o=`realpath "$1"`
shift
fi
if [ "x${gen_header}" = "x1" ]; then
resources_h=`realpath "$1"`
shift
fi
# Make sure that the header does not exist
rm -f "${resources_h}"
rm -f "${resources_o}"
# Make sure that output files do not exist
if [ "x${gen_header}" = "x1" ]; then
rm -f "${resources_h}"
fi
if [ "x${gen_object}" = "x1" ]; then
rm -f "${resources_o}"
fi
# Recomupte relative paths to parameters
idx=0
@ -26,24 +47,28 @@ do
idx="$(("${idx}" + 1))"
done
# Create the object file
pushd "${proj_dir}" >> /dev/null
$linker -r -b binary -o "${resources_o}" "${resource_files[@]}"
popd >> /dev/null
if [ "x${gen_object}" = "x1" ]; then
# Create the object file
pushd "${proj_dir}" >> /dev/null
$linker -r -b binary -o "${resources_o}" "${resource_files[@]}"
popd >> /dev/null
fi
# Include stddef.h in the resources header (for size_t)
echo "#include <stddef.h>" >> "${resources_h}"
if [ "x${gen_header}" = "x1" ]; then
# Include stddef.h in the resources header (for size_t)
echo "#include <stddef.h>" >> "${resources_h}"
for resource in "${resource_files[@]}"
do
# Use relative path to the resource as the variable name
var_name="_binary_${resource}"
for resource in "${resource_files[@]}"
do
# Use relative path to the resource as the variable name
var_name="_binary_${resource}"
# Replace all non-alphanumeric characters with underscores
var_name=`printf "${var_name}" | sed "s/[^a-zA-Z0-9]/_/g"`
# Replace all non-alphanumeric characters with underscores
var_name=`printf "${var_name}" | sed "s/[^a-zA-Z0-9]/_/g"`
# Define externs in the header
echo "extern void *${var_name}_start;" >> "${resources_h}"
echo "extern void *${var_name}_size;" >> "${resources_h}"
echo "" >> "${resources_h}"
done
# Define externs in the header
echo "extern void *${var_name}_start;" >> "${resources_h}"
echo "extern void *${var_name}_size;" >> "${resources_h}"
echo "" >> "${resources_h}"
done
fi