Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions ch55xduino/tools/wrapper/sdcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,64 @@ REL=${OBJ%.o}.rel
MARK=$4
shift 4

PREPROCESS=0
DEPFILE=""
ARGS=()
while [ $# -gt 0 ]; do
if [ "$1" == "-E" ]; then
PREPROCESS=1
ARGS+=("$1")
shift
elif [ "$1" == "-MF" ] && [ $# -ge 2 ]; then
DEPFILE=$2
shift 2
else
ARGS+=("$1")
shift
fi
done

PREPROCESS_OBJ=$OBJ
if [ $PREPROCESS -gt 0 ] && [ -n "$DEPFILE" ] && [ "$OBJ" == "/dev/null" ]; then
PREPROCESS_OBJ=${DEPFILE%.d}
fi

if [ $VERBOSE -gt 0 ]; then
>&2 echo -ne "${GREEN}Mark $MARK:${OFF}"
>&2 echo "$SDCC" "$@" "$SRC" -o "$OBJ"
>&2 echo "$SDCC" "${ARGS[@]}" "$SRC" -o "$PREPROCESS_OBJ"
fi

case "$SRC" in
*.cpp)
# use -x c to compile as c, add a reference to main to pull in main.c
"$SDCC" "$@" -x c --include dummy_variable_main.h "$SRC" -o "$OBJ"
if [ $PREPROCESS -gt 0 ]; then
"$SDCC" "${ARGS[@]}" -x c --include dummy_variable_main.h "$SRC" -o "$PREPROCESS_OBJ" > "$OBJ"
else
"$SDCC" "${ARGS[@]}" -x c --include dummy_variable_main.h "$SRC" -o "$OBJ"
fi
ERR=$?
;;
*.c)
# compile a .c file
"$SDCC" "$@" "$SRC" -o "$OBJ"
if [ $PREPROCESS -gt 0 ]; then
"$SDCC" "${ARGS[@]}" "$SRC" -o "$PREPROCESS_OBJ" > "$OBJ"
else
"$SDCC" "${ARGS[@]}" "$SRC" -o "$OBJ"
fi
ERR=$?
;;
esac

# Deqing: For some reason my version of SDCC don't generate rel file, it creates o file directly, so I modified the SDCC command below
# copy the generated .rel files as an .o file to avoid recompiling the next time
# if OBJ is a .o file we copy back
if [[ ${OBJ%.o} != $OBJ ]]
if [ $PREPROCESS -eq 0 ] && [[ ${OBJ%.o} != $OBJ ]]
then
cp -a "${OBJ}" "${REL}"
fi

#check rel file size, if it is odd, add by 1 to align code
if [ -f ${REL} ]; then
if [ $PREPROCESS -eq 0 ] && [ -f ${REL} ]; then
#check CSEG size
CSEG_STR="$(grep -o '^A CSEG size [0-9A-F]\+' ${REL})"
if [[ -z "$CSEG_STR" ]]; then
Expand Down
Loading