#!/bin/sh12# Convert standard input to a C char array, write to a file, then create an3# MD5 sum of that file and append said MD5 sum as char array to the file.45[ -n "$1" ] || exit 167# Filter out whitespace, empty lines, and comments.8sanitize() {9sed 's/^[[:space:]]*//; /^$/d; /^\/\//d'10}1112# Convert stdin to a \0-terminated char array.13dump() {14echo "static const char $1[] = {"15od -v -A n -t x1 | sed 's/[[:space:]]*\([[:alnum:]]\{2\}\)/0x\1, /g'16echo '0x00 };'17}1819# Print MD5 hash w/o newline character to not embed the character in the array.20hash() {21# md5sum is not standard, so try different platform-specific alternatives.22{ md5sum "$1" || md5 -q "$1" || digest -a md5 "$1"; } 2>/dev/null |23cut -b -32 | tr -d '\n\r'24}2526trap 'rm -f "$1.temp"' EXIT2728sanitize | tee "$1.temp" |29dump 'x264_opencl_source' > "$1"3031hash "$1.temp" |32dump 'x264_opencl_source_hash' >> "$1"333435