home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- # ldso
- # build a .so for C++ modules
- # these may contain *__link structs which contain
- # constructors and destructors, these are packaged
- # in an added module, under a routine called _init()
- # then this module is compiled and included in the ".so"
- # rtld() will, at runtime load the ".so" and call any _init()
- # routines in the .so, so we will get our constructors called.
- #
- # hess@sco.com 4/20/95
- #
- args=$*
- prog=$0
- fail=1
- CC=cc
- CFLAGS=-belf
- INITFILE=_soinit.c
- INITOBJ=_soinit.o
- init=""
- needs_init=0
- LD=ld
-
- Bail() {
- echo "error: $prog: $1"
- exit $fail
- }
- has__link() {
- [ -f $1 ] || Bail "Can't open $1"
- nm -p $1 |grep __link >/dev/null
- return $?
- }
-
- # loop thru the objects to see if we need to build an
- # init module
- for i in $args; do case $i in
- *.o) if has__link $i
- then needs_init=1; break; fi
- ;;
- esac; done
-
- [ $needs_init -eq 1 ] && {
- # _init module is needed, set the var "init" to the object name
- echo "struct __linkl { struct __linkl * next;" > $INITFILE
- echo "void (*ctor)(); void (*dtor)(); };" >> $INITFILE
- echo "void _init() { " >> $INITFILE
- for i in $args; do case $i in
- *.o)
- echo // links from $i
- nm -p $i |grep __link |\
- awk '{
- printf("{ extern struct __linkl %s;\n (*(%s.ctor))(); }\n",$3,$3);
- }'
- ;;
- esac; done >> $INITFILE
- echo "} " >> $INITFILE
- ## compile the init file
- $ECHO $CC $CFLAGS -c $INITFILE
- init=$INITOBJ
- [ -f $init ] || Bail "can't build $init"
- }
-
- # do the link
- $ECHO $LD $init $args
- exit $?
-