#!/bin/bash
CFLAGS="--pipe -B/home/saeed/rtems/b-sparc/sparc-rtems4.12/sis/lib/ -specs bsp_specs -qrtems   -Wall  -O2 -g -ffunction-sections -fdata-sections    -mcpu=cypress"
rm -f dl.exe
mkdir -p dl/bin
sparc-rtems4.12-gcc ${CFLAGS} -o dl/bin/hello.o -c hello.c 
tar -cf dl_tarfile dl/
sparc-rtems4.12-ld -r --accept-unknown-input-arch -b binary -o dl_tarfile.o.tmp dl_tarfile 
sparc-rtems4.12-objcopy --rename-section .data=.rodata,alloc,load,readonly,data,contents dl_tarfile.o.tmp dl_tarfile.o
sparc-rtems4.12-gcc ${CFLAGS} -o init.o -c init.c 
if [[ $? -eq 0 ]]; then
	sparc-rtems4.12-gcc ${CFLAGS} -Wl,--gc-sections init.o dl_tarfile.o -lm -o dl.pre
	rtems-syms -e -c "sparc-rtems4.12-gcc ${CFLAGS}" -S dl-sym.c -o dl-sym.o dl.pre 
	sparc-rtems4.12-gcc ${CFLAGS} -Wl,--gc-sections init.o dl_tarfile.o dl-sym.o -L. -lm -o dl.exe
fi
rm -rf dl dl.pre dl-* dl_* *.o init
