1 #!/bin/ksh 2 # vim: set ts=8 sts=8 sw=8 noet: 3 4 set -o errexit 5 set -o pipefail 6 7 function usage 8 { 9 printf "Usage: $0 %s %s %s %s[...]\n" "<build_dir>" \ 10 "<ctf_object_dir>" "<container_version>" "<program>" >&2 11 exit 1 12 } 13 14 # Process input arguments: 15 BUILD_DIR="$1" 16 CTF_OBJECT_DIR="$2" 17 CONTAINER_VERSION="$3" 18 if [[ ! -d "${BUILD_DIR}" || -z "${CTF_OBJECT_DIR}" || \ 19 -z "${CONTAINER_VERSION}" ]]; then 20 usage 21 fi 22 shift 3 23 24 # Process input program list: 25 if (( $# < 1 )); then 26 usage 27 fi 28 PROGRAMS="$*" 29 30 # Read from environment: 31 if [[ -z "${DESTDIR}" ]]; then 32 printf "Must set DESTDIR in the environment\n" >&2 33 exit 1 34 fi 35 36 # These may contain wildcards, so expand: 37 CTFMERGE="$(echo $CTFMERGE)" 38 CTFCONVERT="$(echo $CTFCONVERT)" 39 if [[ ! -n "${CTFMERGE}" || ! -n "${CTFCONVERT}" ]]; then 40 printf "You must set CTFMERGE and CTFCONVERT in the environment.\n" >&2 41 exit 1 42 fi 43 if [[ ! -x "${CTFMERGE}" ]]; then 44 printf "Could not find CTFMERGE at '%s'\n" "${CTFMERGE}" >&2 45 exit 1 46 fi 47 if [[ ! -x "${CTFCONVERT}" ]]; then 48 printf "Could not find CTFCONVERT at '%s'\n" "${CTFCONVERT}" >&2 49 exit 1 50 fi 51 52 # Convert DWARF to CTF in every object file we can find: 53 rm -rf "${CTF_OBJECT_DIR}" 54 mkdir -p "${CTF_OBJECT_DIR}" 55 (cd "${BUILD_DIR}" && find * -name '*.o' -type f) | \ 56 sort | while read objf; do 57 printf " CTFCONVERT %s\n" "${objf}" >&2 58 ctff="$(echo "$objf" | sed -e 's,/,%,g' -e 's/\.o$/\.ctf/')" 59 ${CTFCONVERT} -l "${CONTAINER_VERSION}" \ 60 -o "${CTF_OBJECT_DIR}/${ctff}" \ 61 "${BUILD_DIR}/${objf}" 62 done 63 64 # Merge the CTF into the set of programs we ship: 65 for program in ${PROGRAMS}; do 66 program_path="${DESTDIR}${program}" 67 printf " CTFMERGE %s\n" "${program_path}" >&2 68 chmod u+w "${program_path}" 69 ${CTFMERGE} -l "${CONTAINER_VERSION}" \ 70 -o "${program_path}" \ 71 ${CTF_OBJECT_DIR}/*.ctf 72 done