1
- #! /bin/bash
1
+ #! /bin/sh -
2
2
3
3
BUILD_PATH=" $1 "
4
4
BUILD_SOURCE_PATH=" $2 "
@@ -9,20 +9,38 @@ if [ ! -f "$BUILD_PATH/sketch" ]; then
9
9
mkdir -p " $BUILD_PATH /sketch"
10
10
fi
11
11
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
16
13
if [ ! -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"
18
15
else
19
16
# Else copy the build_opt.h as build.opt
20
17
# Workaround to the header file preprocessing done by arduino-cli
21
18
# 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"
24
20
fi
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"
26
44
27
45
# 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