Skip to content

Commit

Permalink
Merge branch 'busybox' into development (fix #61)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenbaht committed Dec 10, 2018
2 parents 8678dc5 + 3c6900c commit 5d454b6
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- using busybox as command shell for windows to run the wrapper scripts


## [0.4.0 - 2018-12-07]
Expand Down
5 changes: 3 additions & 2 deletions sduino/hardware/sduino/stm8/platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification

name=STM8S Boards
version=0.4.0-pre1
version=0.4.0

# General folder structure variables
# ----------------------------------
Expand Down Expand Up @@ -37,7 +37,8 @@ compiler.warning_flags.all=-Wp-Wall -V
# Default "compiler.path" is correct, change only if you want to override the initial value
compiler.path={runtime.tools.sdcc.path}/bin
compiler.wrapper.path={runtime.tools.STM8Tools.path}/wrapper
compiler.wrapper.path.windows={runtime.tools.STM8Tools.path}/win/bash" "{runtime.tools.STM8Tools.path}/wrapper
compiler.wrapper.path.windows={runtime.tools.STM8Tools.path}/win/busybox"
ash "{runtime.tools.STM8Tools.path}/wrapper
compiler.tools.path={runtime.tools.avr-gcc.path}/bin

compiler.c.cmd=sdcc
Expand Down
Binary file added sduino/hardware/sduino/tools/win/busybox.exe
Binary file not shown.
Binary file added sduino/hardware/sduino/tools/win/stm8flash.exe
Binary file not shown.
Binary file added sduino/hardware/sduino/tools/win/stm8gal.exe
Binary file not shown.
149 changes: 101 additions & 48 deletions sduino/hardware/sduino/tools/wrapper/sdcc-link.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@
#!/bin/bash

# usage: sdcc-link [.lib and .rel files] re5 [other flags and files]
# usage: sdcc-link [options] [.lib and .rel files] re5 [other flags and files]
#
# possible script options (options in this order only):
# -v: verbose
# -d: debug mode (more verbose), includes coloring the output
# -c: color the output


### local functions ######################################################

# verbose print
#
# usage: vprint min_level msg
#
# prints a message if the verbosity level is equal or higher than the required
# min_level
#
vprint ()
{
local level=$1

shift
if [ $VERBOSE -ge $level ]; then
echo -e "$@"
fi
}


# parse the script options
#
# This is very crude. The options are allowed only as the very first argments
# and they are required to be used in exactly this order.

VERBOSE=0
USE_COLOR=0
if [ "$1" == "-v" ]; then
VERBOSE=1;
shift
elif [ "$1" == "-vv" ]; then
elif [ "$1" == "-d" ]; then
VERBOSE=2
# USE_COLOR=1
USE_COLOR=1
set -x
shift
fi
if [ "$1" == "-c" ]; then
USE_COLOR=1;
shift
fi


# define color codes

if [ $USE_COLOR -gt 0 ]; then
# ANSI color codes to beautify the output:
Expand All @@ -36,59 +73,75 @@ WHITE='\033[1;37m'
OFF='\033[0m'
fi

# check if cp is in the path using 'command -v' (a builtin POSIX function)
if ! command -v cp > /dev/null; then
# Ok, this means we are on a Windows system and we have to find a
# way to access cp and rm in ../win. A simple 'cd ../win' or
# '../win/cp' does't work, as the current working directory is still
# the Arduino binary directory.
#
# This looks ok, but it doesn't work on some Windows systems:
# (No idea why)
# PATH="${0%/wrapper/*}"/win:$PATH
#
# This is technically wrong, but surprisingly it works with Windows:
# cd $0/../..
# PATH=$(pwd)/win:$PATH
#
# Use cd/pwd as a replacement for 'realpath' using only builtins.
# It has the positive side effect of converting from Windows to Unix
# path syntax avoiding all these backslash issues.
cd "${0%/wrapper/*}"
PATH=$(pwd)/win:$PATH
fi

SDCC="$1"
shift

if [ $VERBOSE ]; then
# echo the full command line in cyan:
>&2 echo -ne "${CYAN}"
>&2 echo -n "${@}"
>&2 echo -e "${OFF}"
fi
# echo the full command line in cyan on stderr:
>&2 vprint 1 "${CYAN}${@}${OFF}"

declare -a OBJS
while [ $# -gt 0 ]; do
echo $1
FILE=$1
if [[ "$FILE" == *.a ]]; then
FILE=${FILE%.a}.lib
cp -a "$1" "$FILE"
fi
if [[ "$FILE" == *.o ]]; then
FILE=${FILE%.o}.rel

# The arduino system insists on a *.a file for a library, but sdar requires
# them to be named *.lib.
#
# Workaround: copy all *.lib files into *.a files.
#
# Iterate over all positional parameters with a for loop.
# The pattern match for filename is easy for bash and dash, but busybox ash
# requires the use of the 'expr' command:
#
# bash, dash: if [[ "$FILE" == *.a ]]; then
# ash uses 'expr': expr "$FILE" : ".*\.a$"; then
#
# This is all pure POSIX, it works for bash, dash and busybox ash
vprint 2 "copy *.a to *.lib"
for FILE; do
vprint 2 "- checking parameter '$FILE'"
# using expr works for bash, dash, busybox ash
if expr "$FILE" : ".*\.a$" > /dev/null; then
NEW=${FILE%.a}.lib
vprint 1 "copy $FILE to $NEW"
cp -a "$FILE" "$NEW"
fi
OBJS+=("${FILE}")
shift
done

if [ $VERBOSE ]; then
echo -ne "cmd: ${ORANGE}"
echo -n "$SDCC" "${OBJS[@]}"
echo -e "${OFF}"
fi
"$SDCC" "${OBJS[@]}"

# replace *.o with *.rel and *.a with *.lib
#
# On bash this is a simple pattern substituiton:
# set -- "${@/.o/.rel}"
# set -- "${@/.a/.lib}"
#
# Unfortunatly, this does not work with dash or ash. dash does not support
# pattern substituition in general. busybox ash does not support arrays and
# shortens the arg list to the first argument, deleting all the rest.
#
# As a workaround we combine the argument list into a single string. By
# using TAB as a field separator we can even deal with spaces, backspaces
# and colons in file names.

# use tab as field separator
IFS=$'\t'


# combine all arguments into a single string with field separator and add a
# TAB at the end. This allows the pattern below to match the last argument
# as well.
vprint 2 "Combine all arguments into a single string"
line="$* "

# do the filename replacements: (bash and ash, not dash)
# Needs a double slash to replace all occurencies, not only the first one.
#line=${line//.o/.rel}
#line=${line//.a/.lib}
# replace all the occurencies just before a field separator
vprint 2 "- before substitution: $line"
line="${line//.o /.rel }"
line="${line//.a /.lib }"
vprint 2 "- after substitution: $line"

vprint 1 "cmd: ${ORANGE}$SDCC $line${OFF}"
"$SDCC" $line

# propagate the sdcc exit code
exit $?

0 comments on commit 5d454b6

Please sign in to comment.