#!/usr/bin/env bash linker="x86_64-w64-mingw32-ld" # Read project directory proj_dir=`realpath "$1"` shift # Read output file destinations resources_o=`realpath "$1"` shift resources_h=`realpath "$1"` shift # Make sure that the header does not exist rm -f "${resources_h}" rm -f "${resources_o}" # Recomupte relative paths to parameters idx=0 resource_files=() for path in "$@" do resource_files["${idx}"]=`realpath --relative-to="${proj_dir}" "${path}"` 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 # Include stddef.h in the resources header (for size_t) echo "#include " >> "${resources_h}" 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"` # 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