#!/bin/sh
#
# usage: dde_kit_find_initcalls <list of object files>
#

tempfile="/tmp/dde_kit-$(date +%s)"

nm -C "$@" | grep "dde_kit_initcall_" > $tempfile
sed -i "s/^.* \(dde_kit_initcall_.*\)/\1/" $tempfile

echo "/*"
echo " * Automatically generated by \"os/tool/dde_kit_find_initcalls $@\"."
echo " */"
cat $tempfile | sed "s/\(.*\)/extern int (*\1)(void);/" | sort | uniq
echo
echo "void do_initcalls(void)"
echo "{"
cat $tempfile | sed "s/\(.*\)/	\1();/" | sort | uniq
echo "}"
echo "/*"
echo " * End of automatically generated code."
echo " */"

rm $tempfile
