Skip to content

Commit 8a555d8

Browse files
authored
Update copy-libs.sh
1 parent dbd39e3 commit 8a555d8

File tree

1 file changed

+68
-125
lines changed

1 file changed

+68
-125
lines changed

tools/copy-libs.sh

Lines changed: 68 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -52,87 +52,6 @@ function get_actual_path(){
5252
fi
5353
}
5454

55-
# Include-Pfad-Verkürzung Funktionen (für statische Generierung)
56-
if [ -n "$IDF_PATH" ]; then
57-
BUILD_FRAMEWORK_DIR="$IDF_PATH"
58-
elif [ -d "../esp-idf" ]; then
59-
BUILD_FRAMEWORK_DIR="$(realpath ../esp-idf)"
60-
else
61-
BUILD_FRAMEWORK_DIR=$(dirname $(dirname "$PWD"))
62-
fi
63-
64-
is_framework_subfolder() {
65-
local potential_subfolder="$1"
66-
67-
if [[ "$potential_subfolder" != /* ]]; then
68-
return 1
69-
fi
70-
71-
local sdk_drive="${BUILD_FRAMEWORK_DIR%%:*}"
72-
local sub_drive="${potential_subfolder%%:*}"
73-
if [[ "$sdk_drive" != "$sub_drive" ]]; then
74-
return 1
75-
fi
76-
77-
case "$potential_subfolder" in
78-
"$BUILD_FRAMEWORK_DIR"*)
79-
return 0
80-
;;
81-
*)
82-
return 1
83-
;;
84-
esac
85-
}
86-
87-
shorten_includes() {
88-
local includes_str="$1"
89-
local shortened_includes=""
90-
local generic_includes=""
91-
92-
IFS=' ' read -ra includes_array <<< "$includes_str"
93-
94-
for inc in "${includes_array[@]}"; do
95-
if [[ -n "$inc" ]]; then
96-
if is_framework_subfolder "$inc"; then
97-
local rel_path="${inc#$BUILD_FRAMEWORK_DIR}"
98-
rel_path="${rel_path#/}"
99-
100-
if [[ "$rel_path" == "components/"* ]]; then
101-
local component_path="${rel_path#components/}"
102-
local component_name="${component_path%%/*}"
103-
local sub_path="${component_path#*/}"
104-
if [[ "$sub_path" == "include" ]]; then
105-
shortened_includes+=" -iwithprefix/include/$component_name"
106-
elif [[ "$sub_path" == "include/"* ]]; then
107-
local remaining_path="${sub_path#include/}"
108-
shortened_includes+=" -iwithprefix/include/$component_name/$remaining_path"
109-
else
110-
shortened_includes+=" -iwithprefix/include/$component_name/$sub_path"
111-
fi
112-
elif [[ "$rel_path" == "managed_components/"* ]]; then
113-
local component_path="${rel_path#managed_components/}"
114-
local component_name="${component_path%%/*}"
115-
local sub_path="${component_path#*/}"
116-
if [[ "$sub_path" == "include" ]]; then
117-
shortened_includes+=" -iwithprefix/include/$component_name"
118-
elif [[ "$sub_path" == "include/"* ]]; then
119-
local remaining_path="${sub_path#include/}"
120-
shortened_includes+=" -iwithprefix/include/$component_name/$remaining_path"
121-
else
122-
shortened_includes+=" -iwithprefix/include/$component_name/$sub_path"
123-
fi
124-
else
125-
shortened_includes+=" -iwithprefix/$rel_path"
126-
fi
127-
else
128-
generic_includes+=" $inc"
129-
fi
130-
fi
131-
done
132-
133-
echo "$generic_includes|$shortened_includes"
134-
}
135-
13655
#
13756
# START OF DATA EXTRACTION FROM CMAKE
13857
#
@@ -142,7 +61,6 @@ CPP_FLAGS=""
14261
AS_FLAGS=""
14362

14463
INCLUDES=""
145-
INCLUDES_RAW=""
14664
DEFINES=""
14765

14866
EXCLUDE_LIBS=";"
@@ -192,19 +110,16 @@ for item in "${@:2:${#@}-5}"; do
192110
if [ "${item:0:1}" = "/" ]; then
193111
item=`get_actual_path $item`
194112
INCLUDES+="$item "
195-
INCLUDES_RAW+="$item "
196113
elif [ "${item:0:2}" = ".." ]; then
197114
if [[ "${item:0:14}" = "../components/" && "${item:0:22}" != "../components/arduino/" ]] || [[ "${item:0:11}" = "../esp-idf/" ]] || [[ "${item:0:22}" = "../managed_components/" ]]; then
198115
item="$PWD${item:2}"
199116
item=`get_actual_path $item`
200117
INCLUDES+="$item "
201-
INCLUDES_RAW+="$item "
202118
fi
203119
else
204120
item="$PWD/build/$item"
205121
item=`get_actual_path $item`
206122
INCLUDES+="$item "
207-
INCLUDES_RAW+="$item "
208123
fi
209124
elif [ "$prefix" = "-D" ]; then
210125
if [[ "${item:2:7}" != "ARDUINO" ]] && [[ "$item" != "-DESP32=ESP32" ]] && [[ "$item" != "-DNDEBUG" ]]; then #skip ARDUINO defines
@@ -219,11 +134,6 @@ for item in "${@:2:${#@}-5}"; do
219134
fi
220135
done
221136

222-
# Wende Include-Verkürzung an
223-
SHORTENED_RESULT=$(shorten_includes "$INCLUDES_RAW")
224-
GENERIC_INCLUDES="${SHORTENED_RESULT%|*}"
225-
SHORTENED_INCLUDES="${SHORTENED_RESULT#*|}"
226-
227137
#collect asm-flags
228138
str=`cat build/compile_commands.json | grep arduino-lib-builder-as.S | grep command | cut -d':' -f2 | cut -d',' -f1`
229139
str="${str:2:${#str}-1}" #remove leading space and quotes
@@ -412,25 +322,17 @@ mkdir -p "$AR_SDK"
412322
AR_PLATFORMIO_PY="$AR_SDK/pioarduino-build.py"
413323
cat configs/pio_start.txt > "$AR_PLATFORMIO_PY"
414324

415-
# ASFLAGS mit statischer Include-Verkürzung
325+
# Sammle Include-Pfade für Verkürzung
326+
SHORTENED_INCLUDES=""
327+
416328
echo " ASFLAGS=[" >> "$AR_PLATFORMIO_PY"
417329
if [ "$IS_XTENSA" = "y" ]; then
418330
echo " \"-mlongcalls\"" >> "$AR_PLATFORMIO_PY"
419331
else
420332
echo " \"-march=rv32imc\"" >> "$AR_PLATFORMIO_PY"
421333
fi
422334

423-
# Füge statische Include-Verkürzung hinzu
424-
if [[ -n "$SHORTENED_INCLUDES" ]]; then
425-
echo " \"-iprefix\", join(FRAMEWORK_DIR, \"tools\", \"sdk\", \"$IDF_TARGET\")," >> "$AR_PLATFORMIO_PY"
426-
IFS=' ' read -ra shortened_array <<< "$SHORTENED_INCLUDES"
427-
for flag in "${shortened_array[@]}"; do
428-
if [[ -n "$flag" ]]; then
429-
echo " \"$flag\"," >> "$AR_PLATFORMIO_PY"
430-
fi
431-
done
432-
fi
433-
335+
# Include-Verkürzung wird später hinzugefügt
434336
echo " ]," >> "$AR_PLATFORMIO_PY"
435337
echo "" >> "$AR_PLATFORMIO_PY"
436338

@@ -467,24 +369,13 @@ echo " \"$last_item\"" >> "$AR_PLATFORMIO_PY"
467369
echo " ]," >> "$AR_PLATFORMIO_PY"
468370
echo "" >> "$AR_PLATFORMIO_PY"
469371

470-
# CCFLAGS mit statischer Include-Verkürzung
471372
echo " CCFLAGS=[" >> "$AR_PLATFORMIO_PY"
472373
set -- $PIO_CC_FLAGS
473374
for item; do
474375
echo " \"$item\"," >> "$AR_PLATFORMIO_PY"
475376
done
476377

477-
# Füge statische Include-Verkürzung hinzu
478-
if [[ -n "$SHORTENED_INCLUDES" ]]; then
479-
echo " \"-iprefix\", join(FRAMEWORK_DIR, \"tools\", \"sdk\", \"$IDF_TARGET\")," >> "$AR_PLATFORMIO_PY"
480-
IFS=' ' read -ra shortened_array <<< "$SHORTENED_INCLUDES"
481-
for flag in "${shortened_array[@]}"; do
482-
if [[ -n "$flag" ]]; then
483-
echo " \"$flag\"," >> "$AR_PLATFORMIO_PY"
484-
fi
485-
done
486-
fi
487-
378+
# Include-Verkürzung wird später hinzugefügt
488379
echo " \"-MMD\"" >> "$AR_PLATFORMIO_PY"
489380
echo " ]," >> "$AR_PLATFORMIO_PY"
490381
echo "" >> "$AR_PLATFORMIO_PY"
@@ -507,15 +398,12 @@ echo " '-Wl,-Map=\"%s\"' % join(\"\${BUILD_DIR}\", \"\${PROGNAME}.map\")"
507398
echo " ]," >> "$AR_PLATFORMIO_PY"
508399
echo "" >> "$AR_PLATFORMIO_PY"
509400

510-
# CPPPATH NUR mit Arduino Core - KEINE kopierten Headers!
401+
# include dirs - HIER WIRD DIE VERKÜRZUNG IMPLEMENTIERT
402+
REL_INC=""
511403
echo " CPPPATH=[" >> "$AR_PLATFORMIO_PY"
512-
echo " join($PIO_SDK, board_config.get(\"build.arduino.memory_type\", (board_config.get(\"build.flash_mode\", \"dio\") + \"_qspi\")), \"include\")," >> "$AR_PLATFORMIO_PY"
513-
echo " join(FRAMEWORK_DIR, \"cores\", board_config.get(\"build.core\"))" >> "$AR_PLATFORMIO_PY"
514-
echo " ]," >> "$AR_PLATFORMIO_PY"
515-
echo "" >> "$AR_PLATFORMIO_PY"
516404

517-
# Headers kopieren (aber NICHT zu CPPPATH hinzufügen)
518405
set -- $INCLUDES
406+
519407
for item; do
520408
if [[ "$item" != $PWD ]]; then
521409
ipath="$item"
@@ -539,7 +427,15 @@ for item; do
539427
out_sub="${item#*$ipath}"
540428
out_cpath="$AR_SDK/include/$fname$out_sub"
541429

542-
# Headers kopieren
430+
# Sammle für Include-Verkürzung: Konvertiere zu relativem Pfad
431+
if [ "$out_sub" = "" ]; then
432+
SHORTENED_INCLUDES+=" -iwithprefix/include/$fname"
433+
else
434+
sub_clean="${out_sub#/}" # Entferne führenden Slash
435+
SHORTENED_INCLUDES+=" -iwithprefix/include/$fname/$sub_clean"
436+
fi
437+
438+
# Headers kopieren (wie bisher)
543439
for f in `find "$item" -name '*.h'`; do
544440
rel_f=${f#*$item}
545441
rel_p=${rel_f%/*}
@@ -558,7 +454,6 @@ for item; do
558454
mkdir -p "$out_cpath$rel_p"
559455
cp -n $f "$out_cpath$rel_p/"
560456
done
561-
562457
# Temporary measure to fix issues caused by https://github.com/espressif/esp-idf/commit/dc4731101dd567cc74bbe4d0f03afe52b7db9afb#diff-1d2ce0d3989a80830fdf230bcaafb3117f32046d16cf46616ac3d55b4df2a988R17
563458
if [[ "$fname" == "bt" && "$out_sub" == "/include/$IDF_TARGET/include" && -f "$ipath/controller/$IDF_TARGET/esp_bt_cfg.h" ]]; then
564459
mkdir -p "$AR_SDK/include/$fname/controller/$IDF_TARGET"
@@ -567,6 +462,55 @@ for item; do
567462
fi
568463
done
569464

465+
# Nur Arduino Core und Memory-Variant in CPPPATH (NICHT die Framework-Headers!)
466+
echo " join($PIO_SDK, board_config.get(\"build.arduino.memory_type\", (board_config.get(\"build.flash_mode\", \"dio\") + \"_qspi\")), \"include\")," >> "$AR_PLATFORMIO_PY"
467+
echo " join(FRAMEWORK_DIR, \"cores\", board_config.get(\"build.core\"))" >> "$AR_PLATFORMIO_PY"
468+
echo " ]," >> "$AR_PLATFORMIO_PY"
469+
echo "" >> "$AR_PLATFORMIO_PY"
470+
471+
# JETZT: Füge Include-Verkürzung zu CCFLAGS und ASFLAGS hinzu
472+
if [[ -n "$SHORTENED_INCLUDES" ]]; then
473+
# Aktualisiere CCFLAGS
474+
sed -i '/CCFLAGS=\[/,/\]/{
475+
/"-MMD"/i\
476+
"-iprefix", join(FRAMEWORK_DIR, "tools", "sdk", "'$IDF_TARGET'"),
477+
}' "$AR_PLATFORMIO_PY"
478+
479+
# Füge iwithprefix Flags hinzu
480+
IFS=' ' read -ra shortened_array <<< "$SHORTENED_INCLUDES"
481+
for flag in "${shortened_array[@]}"; do
482+
if [[ -n "$flag" ]]; then
483+
sed -i '/CCFLAGS=\[/,/\]/{
484+
/"-MMD"/i\
485+
"'$flag'",
486+
}' "$AR_PLATFORMIO_PY"
487+
fi
488+
done
489+
490+
# Aktualisiere ASFLAGS
491+
if [ "$IS_XTENSA" = "y" ]; then
492+
sed -i '/ASFLAGS=\[/,/\]/{
493+
/"-mlongcalls"/a\
494+
"-iprefix", join(FRAMEWORK_DIR, "tools", "sdk", "'$IDF_TARGET'"),
495+
}' "$AR_PLATFORMIO_PY"
496+
else
497+
sed -i '/ASFLAGS=\[/,/\]/{
498+
/"-march=rv32imc"/a\
499+
"-iprefix", join(FRAMEWORK_DIR, "tools", "sdk", "'$IDF_TARGET'"),
500+
}' "$AR_PLATFORMIO_PY"
501+
fi
502+
503+
# Füge iwithprefix Flags zu ASFLAGS hinzu
504+
for flag in "${shortened_array[@]}"; do
505+
if [[ -n "$flag" ]]; then
506+
sed -i '/ASFLAGS=\[/,/\]/{
507+
$i\
508+
"'$flag'",
509+
}' "$AR_PLATFORMIO_PY"
510+
fi
511+
done
512+
fi
513+
570514
AR_LIBS="$LD_LIBS"
571515
PIO_LIBS=""
572516
set -- $LD_LIBS
@@ -624,16 +568,16 @@ DEFINES=`echo "$DEFINES" | tr -s '\'`
624568
FLAGS_DIR="$AR_SDK/flags"
625569
mkdir -p "$FLAGS_DIR"
626570
echo -n "$DEFINES" > "$FLAGS_DIR/defines"
571+
echo -n "$REL_INC" > "$FLAGS_DIR/includes"
627572
echo -n "$C_FLAGS" > "$FLAGS_DIR/c_flags"
628573
echo -n "$CPP_FLAGS" > "$FLAGS_DIR/cpp_flags"
629574
echo -n "$AS_FLAGS" > "$FLAGS_DIR/S_flags"
630575
echo -n "$LD_FLAGS" > "$FLAGS_DIR/ld_flags"
631576
echo -n "$LD_SCRIPTS" > "$FLAGS_DIR/ld_scripts"
632577
echo -n "$AR_LIBS" > "$FLAGS_DIR/ld_libs"
633578

634-
# Speichere auch die verkürzten Includes in den Flags
579+
# Speichere verkürzte Includes für Debugging
635580
echo -n "$SHORTENED_INCLUDES" > "$FLAGS_DIR/shortened_includes"
636-
echo -n "$GENERIC_INCLUDES" > "$FLAGS_DIR/generic_includes"
637581

638582
if [ -d "managed_components/espressif__esp32-camera/driver/private_include/" ]; then
639583
cp -r "managed_components/espressif__esp32-camera/driver/private_include/cam_hal.h" "$AR_SDK/include/espressif__esp32-camera/driver/include/"
@@ -699,4 +643,3 @@ done;
699643
# Add IDF versions to sdkconfig
700644
echo "#define CONFIG_ARDUINO_IDF_COMMIT \"$IDF_COMMIT\"" >> "$AR_SDK/$MEMCONF/include/sdkconfig.h"
701645
echo "#define CONFIG_ARDUINO_IDF_BRANCH \"$IDF_BRANCH\"" >> "$AR_SDK/$MEMCONF/include/sdkconfig.h"
702-

0 commit comments

Comments
 (0)