#!/bin/bash srcdir=$1 outdir=$2 mkdir -p ${outdir}/src mkdir -p ${outdir}/include rm -f ${outdir}/src/errno.c echo "#include " >> ${outdir}/src/errno.c echo "#include " >> ${outdir}/src/errno.c cat >> ${outdir}/src/errno.c <<'EOF' /* * These names belong to the library's own reserved band, and this runs from * akerr_init(), which has no caller to raise into -- so it goes through * __akerr_name_library_status(), which reports a refusal and terminates rather * than leaving every later stack trace to print "Unknown Error" for an errno. * Keeping the branch in src/error.c also keeps this generated file free of * control flow no test can reach. */ EOF echo "void akerr_init_errno(void) {" >> ${outdir}/src/errno.c maxval=$(errno --list | cut -d ' ' -f 2 | sort -g | tail -n 1) errno --list | while read LINE; do define=$(echo "$LINE" | cut -d ' ' -f 1); value=$(echo "$LINE" | cut -d ' ' -f 2); desc=$(echo "$LINE" | cut -d ' ' -f 3-); echo " __akerr_name_library_status(${define}, \"${desc}\");" >> ${outdir}/src/errno.c ; done; echo "}" >> ${outdir}/src/errno.c sed "s/#define AKERR_LAST_ERRNO_VALUE .*/#define AKERR_LAST_ERRNO_VALUE ${maxval}/" ${srcdir}/include/akerror.tmpl.h > ${outdir}/include/akerror.h