#!/bin/sh

INPUTBASE=`basename "$1" .c`
INPUTDIR=`dirname "$1"`
OUTFILE="$INPUTDIR"/"$INPUTBASE".o

if [ -f "$OUTFILE" ] 
then
	rm "$OUTFILE"
fi

# can use -O3 too
arm-elf-gcc -O3 -funroll-all-loops \
 -Wall -Wmissing-prototypes -Wmissing-declarations \
 -nostartfiles -nostdlib -nostdinc -fno-builtin -fPIC -ffixed-r8 -ffixed-r9 \
 -mpic-register=r10 -msingle-pic-base -fsigned-char \
 -IC:/winapp/Metrowerks/CodeWarrior/Palm\ OS\ Support/Incs/Core/System \
 -c "$1" -o "$OUTFILE"

if [ -f "$OUTFILE" ] 
then
#	arm-elf-objdump --disassemble "$OUTFILE"

	SECTIONSIZE=`arm-elf-objdump -h "$OUTFILE" | grep " .data " | cut --characters=19-26`
#	echo $SECTIONSIZE
	if [ ! $SECTIONSIZE = "00000000" ]
	then
	        echo "$1: contains nonzero .data section"
	fi

        SECTIONSIZE=`arm-elf-objdump -h "$OUTFILE" | grep " .bss " | cut --characters=19-26`
        if [ ! $SECTIONSIZE = "00000000" ]
        then
                echo "$1: contains nonzero .bss section"
        fi

        SECTIONSIZE=`arm-elf-objdump -h "$OUTFILE" | grep " .rodata " | cut --characters=19-26`
        if [ ! $SECTIONSIZE = "00000000" ]
        then
                echo "$1: contains nonzero .rodata section"
        fi

	echo "$1: ok"
fi
