1- #! /bin/bash
1+ #! /bin/sh -
22
33BUILD_PATH=" $1 "
44BUILD_SOURCE_PATH=" $2 "
@@ -9,20 +9,38 @@ if [ ! -f "$BUILD_PATH/sketch" ]; then
99 mkdir -p " $BUILD_PATH /sketch"
1010fi
1111
12- # Create empty build.opt if build_opt.h does not exists in the original sketch dir
13- # Then add or append -fmacro-prefix-map option to change __FILE__ absolute path of
14- # the board platform folder to a relative path by using '.'.
15- # (i.e. the folder containing boards.txt)
12+ # Create empty build.opt or clear it if build_opt.h does not exists in the original sketch dir
1613if [ ! -f " $BUILD_SOURCE_PATH /build_opt.h" ]; then
17- printf ' \n-fmacro-prefix-map="%s"=. ' " ${BOARD_PLATFORM_PATH // \\ / \\\\ } " > " $BUILD_PATH /sketch/build.opt"
14+ true > " $BUILD_PATH /sketch/build.opt"
1815else
1916 # Else copy the build_opt.h as build.opt
2017 # Workaround to the header file preprocessing done by arduino-cli
2118 # See https://github.com/arduino/arduino-cli/issues/1338
22- cp " $BUILD_SOURCE_PATH /build_opt.h" " $BUILD_PATH /sketch/build.opt"
23- printf ' \n-fmacro-prefix-map="%s"=.' " ${BOARD_PLATFORM_PATH// \\ / \\\\ } " >> " $BUILD_PATH /sketch/build.opt"
19+ cp -f " $BUILD_SOURCE_PATH /build_opt.h" " $BUILD_PATH /sketch/build.opt"
2420fi
25-
21+ # On Windows, need to protect '\' in path
22+ UNAME_OS=" $( uname -s) "
23+ case " ${UNAME_OS} " in
24+ Windows* )
25+ i=1
26+ prefix=" "
27+ while [ " $i " -le " ${# BOARD_PLATFORM_PATH} " ]; do
28+ c=$( printf ' %s' " $BOARD_PLATFORM_PATH " | cut -c $i )
29+ prefix=${prefix}${c}
30+ if [ " ${c} " = " \\ " ]; then
31+ prefix=${prefix} " \\ "
32+ fi
33+ i=" $(( i + 1 )) "
34+ done
35+ ;;
36+ * )
37+ prefix=${BOARD_PLATFORM_PATH}
38+ ;;
39+ esac
40+ # Then append -fmacro-prefix-map option to change __FILE__ absolute path of
41+ # the board platform folder to a relative path by using '.'.
42+ # (i.e. the folder containing boards.txt)
43+ printf ' \n-fmacro-prefix-map="%s"=.' " ${prefix} " >> " $BUILD_PATH /sketch/build.opt"
2644
2745# Force include of SrcWrapper library
28- echo " #include <SrcWrapper.h>" > " $BUILD_PATH /sketch/SrcWrapper.cpp"
46+ echo " #include <SrcWrapper.h>" > " $BUILD_PATH /sketch/SrcWrapper.cpp"
0 commit comments