#!/usr/bin/env bash # Ask the compiler the implementation specific type for a standard typedeffed type # (int64_t, size_t etc.). Operates by test compiling and using the demangling ABI call. # # This works for gcc and clang on Unix. full_type_of () { prog=$(mktemp) trap "rm $prog" EXIT ${CXX:-g++} -x c++ -o $prog - < #include #include #include #include int main() { int status; char* printable_type = __cxxabiv1::__cxa_demangle(typeid($1).name(), 0, 0, &status); if (printable_type) { std::cout << printable_type; } else { std::cout << "$1"; } ::free(printable_type); } END-FILE $prog } rc=0 syms_desired=$(mktemp) syms_library=$(mktemp) syms_missing=$(mktemp) syms_extra=$(mktemp) trap 'rm $syms_desired $syms_library $syms_missing $syms_extra' EXIT CXX=$1 export CXX # Extract exported symbols from library nm -DC --defined-only -f s $2 | cut -f1 -d'|' -s | sort -u > $syms_library # Process API syms (substitute in some typedefs etc.) sed $3 -e " s/uint64_t/$(full_type_of uint64_t)/ s/uint32_t/unsigned int/ s/uint16_t/unsigned short/ s/uint8_t/unsigned char/ s/size_t/$(full_type_of size_t)/ s/int64_t/$(full_type_of int64_t)/ s/int32_t/int/ s/int16_t/short/ s/int8_t/signed char/ s/qpid::types::Variant::Map/std::map, std::allocator > >/ s/qpid::types::Variant::List/std::list >/ /^\$/d /^#.*\$/d " | sort -u > $syms_desired comm -23 $syms_desired $syms_library > $syms_missing comm -13 $syms_desired $syms_library > $syms_extra if [ -n "$(cat $syms_missing)" ] ; then (echo "Not exported from library (should be)" echo "=====================================" cat $syms_missing ) 1>&2 rc=1 fi if [ -n "$(cat $syms_extra)" ]; then (echo "Exported by library but not in spec" echo "===================================" cat $syms_extra ) 1>&2 fi exit $rc