@@ -52,6 +52,92 @@ function get_actual_path(){
52
52
fi
53
53
}
54
54
55
+ # Include-Pfad-Verkürzung Funktionen (für statische Generierung)
56
+ # Das Build-Zeit Framework-Verzeichnis (ESP-IDF Quellen)
57
+ if [ -n " $IDF_PATH " ]; then
58
+ BUILD_FRAMEWORK_DIR=" $IDF_PATH "
59
+ elif [ -d " ../esp-idf" ]; then
60
+ BUILD_FRAMEWORK_DIR=" $( realpath ../esp-idf) "
61
+ else
62
+ BUILD_FRAMEWORK_DIR=$( dirname $( dirname " $PWD " ) )
63
+ fi
64
+
65
+ is_framework_subfolder () {
66
+ local potential_subfolder=" $1 "
67
+
68
+ # Prüfe ob absoluter Pfad
69
+ if [[ " $potential_subfolder " != /* ]]; then
70
+ return 1
71
+ fi
72
+
73
+ # Prüfe ob auf gleichem Laufwerk
74
+ local sdk_drive=" ${BUILD_FRAMEWORK_DIR%%:* } "
75
+ local sub_drive=" ${potential_subfolder%%:* } "
76
+ if [[ " $sdk_drive " != " $sub_drive " ]]; then
77
+ return 1
78
+ fi
79
+
80
+ # Prüfe ob Unterordner (analog zu Python os.path.commonpath)
81
+ case " $potential_subfolder " in
82
+ " $BUILD_FRAMEWORK_DIR " * )
83
+ return 0
84
+ ;;
85
+ * )
86
+ return 1
87
+ ;;
88
+ esac
89
+ }
90
+
91
+ shorten_includes () {
92
+ local includes_str=" $1 "
93
+ local shortened_includes=" "
94
+ local generic_includes=" "
95
+
96
+ # Konvertiere Include-String zu Array
97
+ IFS=' ' read -ra includes_array <<< " $includes_str"
98
+
99
+ for inc in " ${includes_array[@]} " ; do
100
+ if [[ -n " $inc " ]]; then
101
+ if is_framework_subfolder " $inc " ; then
102
+ # Mappe auf die kopierte Struktur im Arduino Framework
103
+ local rel_path=" ${inc# $BUILD_FRAMEWORK_DIR } "
104
+ rel_path=" ${rel_path#/ } " # Entferne führenden Slash
105
+
106
+ # Konvertiere ESP-IDF Pfad zu Arduino Framework Pfad
107
+ if [[ " $rel_path " == " components/" * ]]; then
108
+ # components/freertos/include -> include/freertos
109
+ local component_path=" ${rel_path# components/ } "
110
+ local component_name=" ${component_path%%/* } "
111
+ local sub_path=" ${component_path#*/ } "
112
+ if [[ " $sub_path " == " include" ]]; then
113
+ shortened_includes+=" -iwithprefix/include/$component_name "
114
+ else
115
+ shortened_includes+=" -iwithprefix/include/$component_name /$sub_path "
116
+ fi
117
+ elif [[ " $rel_path " == " managed_components/" * ]]; then
118
+ # managed_components/esp32-camera/include -> include/esp32-camera
119
+ local component_path=" ${rel_path# managed_components/ } "
120
+ local component_name=" ${component_path%%/* } "
121
+ local sub_path=" ${component_path#*/ } "
122
+ if [[ " $sub_path " == " include" ]]; then
123
+ shortened_includes+=" -iwithprefix/include/$component_name "
124
+ else
125
+ shortened_includes+=" -iwithprefix/include/$component_name /$sub_path "
126
+ fi
127
+ else
128
+ # Andere Pfade direkt mappen
129
+ shortened_includes+=" -iwithprefix/$rel_path "
130
+ fi
131
+ else
132
+ generic_includes+=" $inc "
133
+ fi
134
+ fi
135
+ done
136
+
137
+ # Rückgabe: "generic_includes|shortened_includes"
138
+ echo " $generic_includes |$shortened_includes "
139
+ }
140
+
55
141
#
56
142
# START OF DATA EXTRACTION FROM CMAKE
57
143
#
@@ -61,6 +147,7 @@ CPP_FLAGS=""
61
147
AS_FLAGS=" "
62
148
63
149
INCLUDES=" "
150
+ INCLUDES_RAW=" "
64
151
DEFINES=" "
65
152
66
153
EXCLUDE_LIBS=" ;"
@@ -110,16 +197,19 @@ for item in "${@:2:${#@}-5}"; do
110
197
if [ " ${item: 0: 1} " = " /" ]; then
111
198
item=` get_actual_path $item `
112
199
INCLUDES+=" $item "
200
+ INCLUDES_RAW+=" $item "
113
201
elif [ " ${item: 0: 2} " = " .." ]; then
114
202
if [[ " ${item: 0: 14} " = " ../components/" && " ${item: 0: 22} " != " ../components/arduino/" ]] || [[ " ${item: 0: 11} " = " ../esp-idf/" ]] || [[ " ${item: 0: 22} " = " ../managed_components/" ]]; then
115
203
item=" $PWD ${item: 2} "
116
204
item=` get_actual_path $item `
117
205
INCLUDES+=" $item "
206
+ INCLUDES_RAW+=" $item "
118
207
fi
119
208
else
120
209
item=" $PWD /build/$item "
121
210
item=` get_actual_path $item `
122
211
INCLUDES+=" $item "
212
+ INCLUDES_RAW+=" $item "
123
213
fi
124
214
elif [ " $prefix " = " -D" ]; then
125
215
if [[ " ${item: 2: 7} " != " ARDUINO" ]] && [[ " $item " != " -DESP32=ESP32" ]] && [[ " $item " != " -DNDEBUG" ]]; then # skip ARDUINO defines
@@ -134,6 +224,11 @@ for item in "${@:2:${#@}-5}"; do
134
224
fi
135
225
done
136
226
227
+ # Wende Include-Verkürzung an
228
+ SHORTENED_RESULT=$( shorten_includes " $INCLUDES_RAW " )
229
+ GENERIC_INCLUDES=" ${SHORTENED_RESULT% |* } "
230
+ SHORTENED_INCLUDES=" ${SHORTENED_RESULT#* |} "
231
+
137
232
# collect asm-flags
138
233
str=` cat build/compile_commands.json | grep arduino-lib-builder-as.S | grep command | cut -d' :' -f2 | cut -d' ,' -f1`
139
234
str=" ${str: 2: ${# str} -1} " # remove leading space and quotes
@@ -322,12 +417,25 @@ mkdir -p "$AR_SDK"
322
417
AR_PLATFORMIO_PY=" $AR_SDK /pioarduino-build.py"
323
418
cat configs/pio_start.txt > " $AR_PLATFORMIO_PY "
324
419
420
+ # ASFLAGS mit statischer Include-Verkürzung
325
421
echo " ASFLAGS=[" >> " $AR_PLATFORMIO_PY "
326
422
if [ " $IS_XTENSA " = " y" ]; then
327
423
echo " \" -mlongcalls\" " >> " $AR_PLATFORMIO_PY "
328
424
else
329
425
echo " \" -march=rv32imc\" " >> " $AR_PLATFORMIO_PY "
330
426
fi
427
+
428
+ # Füge statische Include-Verkürzung hinzu
429
+ if [[ -n " $SHORTENED_INCLUDES " ]]; then
430
+ echo " \" -iprefix\" , join(FRAMEWORK_DIR, \" tools\" , \" sdk\" , \" $IDF_TARGET \" )," >> " $AR_PLATFORMIO_PY "
431
+ IFS=' ' read -ra shortened_array <<< " $SHORTENED_INCLUDES"
432
+ for flag in " ${shortened_array[@]} " ; do
433
+ if [[ -n " $flag " ]]; then
434
+ echo " \" $flag \" ," >> " $AR_PLATFORMIO_PY "
435
+ fi
436
+ done
437
+ fi
438
+
331
439
echo " ]," >> " $AR_PLATFORMIO_PY "
332
440
echo " " >> " $AR_PLATFORMIO_PY "
333
441
@@ -364,11 +472,24 @@ echo " \"$last_item\"" >> "$AR_PLATFORMIO_PY"
364
472
echo " ]," >> " $AR_PLATFORMIO_PY "
365
473
echo " " >> " $AR_PLATFORMIO_PY "
366
474
475
+ # CCFLAGS mit statischer Include-Verkürzung
367
476
echo " CCFLAGS=[" >> " $AR_PLATFORMIO_PY "
368
477
set -- $PIO_CC_FLAGS
369
478
for item; do
370
479
echo " \" $item \" ," >> " $AR_PLATFORMIO_PY "
371
480
done
481
+
482
+ # Füge statische Include-Verkürzung hinzu
483
+ if [[ -n " $SHORTENED_INCLUDES " ]]; then
484
+ echo " \" -iprefix\" , join(FRAMEWORK_DIR, \" tools\" , \" sdk\" , \" $IDF_TARGET \" )," >> " $AR_PLATFORMIO_PY "
485
+ IFS=' ' read -ra shortened_array <<< " $SHORTENED_INCLUDES"
486
+ for flag in " ${shortened_array[@]} " ; do
487
+ if [[ -n " $flag " ]]; then
488
+ echo " \" $flag \" ," >> " $AR_PLATFORMIO_PY "
489
+ fi
490
+ done
491
+ fi
492
+
372
493
echo " \" -MMD\" " >> " $AR_PLATFORMIO_PY "
373
494
echo " ]," >> " $AR_PLATFORMIO_PY "
374
495
echo " " >> " $AR_PLATFORMIO_PY "
@@ -391,9 +512,11 @@ echo " '-Wl,-Map=\"%s\"' % join(\"\${BUILD_DIR}\", \"\${PROGNAME}.map\")"
391
512
echo " ]," >> " $AR_PLATFORMIO_PY "
392
513
echo " " >> " $AR_PLATFORMIO_PY "
393
514
394
- # include dirs
395
- REL_INC= " "
515
+ # CPPPATH nur mit kopierten Headers
516
+ echo " CPPPATH=[ " >> " $AR_PLATFORMIO_PY "
396
517
518
+ # Bestehende CPPPATH-Logik für kopierte Headers
519
+ REL_INC=" "
397
520
set -- $INCLUDES
398
521
399
522
for item; do
@@ -420,11 +543,11 @@ for item; do
420
543
out_cpath=" $AR_SDK /include/$fname$out_sub "
421
544
REL_INC+=" -iwithprefixbefore $fname$out_sub "
422
545
if [ " $out_sub " = " " ]; then
423
- echo " "
546
+ echo " join( $PIO_SDK , \" include \" , \" $fname \" ), " >> " $AR_PLATFORMIO_PY "
424
547
else
425
548
pio_sub=" ${out_sub: 1} "
426
549
pio_sub=` echo $pio_sub | sed ' s/\//\\", \\"/g' `
427
- echo " "
550
+ echo " join( $PIO_SDK , \" include \" , \" $fname \" , \" $pio_sub \" ), " >> " $AR_PLATFORMIO_PY "
428
551
fi
429
552
for f in ` find " $item " -name ' *.h' ` ; do
430
553
rel_f=${f#* $item }
@@ -451,17 +574,6 @@ for item; do
451
574
fi
452
575
fi
453
576
done
454
-
455
- echo " CPPPATH=[" >> " $AR_PLATFORMIO_PY "
456
-
457
- set -- $REL_INC
458
- for item; do
459
- if [ " ${item: 0: 17} " = " -iwithprefixbefore" ]; then
460
- include_path=" ${item: 18} "
461
- echo " join($PIO_SDK , \" include\" , \" $include_path \" )," >> " $AR_PLATFORMIO_PY "
462
- fi
463
- done
464
-
465
577
echo " join($PIO_SDK , board_config.get(\" build.arduino.memory_type\" , (board_config.get(\" build.flash_mode\" , \" dio\" ) + \" _qspi\" )), \" include\" )," >> " $AR_PLATFORMIO_PY "
466
578
echo " join(FRAMEWORK_DIR, \" cores\" , board_config.get(\" build.core\" ))" >> " $AR_PLATFORMIO_PY "
467
579
echo " ]," >> " $AR_PLATFORMIO_PY "
@@ -520,6 +632,35 @@ cat configs/pio_end.txt >> "$AR_PLATFORMIO_PY"
520
632
# replace double backslashes with single one
521
633
DEFINES=` echo " $DEFINES " | tr -s ' \' `
522
634
635
+ # target flags files
636
+ FLAGS_DIR=" $AR_SDK /flags"
637
+ mkdir -p " $FLAGS_DIR "
638
+ echo -n " $DEFINES " > " $FLAGS_DIR /defines"
639
+ echo -n " $REL_INC " > " $FLAGS_DIR /includes"
640
+ echo -n " $C_FLAGS " > " $FLAGS_DIR /c_flags"
641
+ echo -n " $CPP_FLAGS " > " $FLAGS_DIR /cpp_flags"
642
+ echo -n " $AS_FLAGS " > " $FLAGS_DIR /S_flags"
643
+ echo -n " $LD_FLAGS " > " $FLAGS_DIR /ld_flags"
644
+ echo -n " $LD_SCRIPTS " > " $FLAGS_DIR /ld_scripts"
645
+ echo -n " $AR_LIBS " > " $FLAGS_DIR /ld_libs"
646
+
647
+ # Speichere auch die verkürzten Includes in den Flags
648
+ echo -n " $SHORTENED_INCLUDES " > " $FLAGS_DIR /shortened_includes"
649
+ echo -n " $GENERIC_INCLUDES " > " $FLAGS_DIR /generic_includes"
650
+
651
+ if [ -d " managed_components/espressif__esp32-camera/driver/private_include/" ]; then
652
+ cp -r " managed_components/espressif__esp32-camera/driver/private_include/cam_hal.h" " $AR_SDK /include/espressif__esp32-camera/driver/include/"
653
+ fi
654
+
655
+ # sdkconfig
656
+ cp -f " sdkconfig" " $AR_SDK /sdkconfig"
657
+
658
+ # dependencies.lock
659
+ cp -f " dependencies.lock" " $AR_SDK /dependencies.lock"
660
+
661
+ # gen_esp32part.py
662
+ # cp "$IDF_PATH/components/partition_table/gen_esp32part.py" "$AR_GEN_PART_PY"
663
+
523
664
# copy precompiled libs (if we need them)
524
665
function copy_precompiled_lib(){
525
666
lib_file=" $1 "
@@ -549,31 +690,6 @@ for lib in "openthread" "espressif__esp-tflite-micro" "bt" "espressif__esp_modem
549
690
fi
550
691
done
551
692
552
- # target flags files
553
- FLAGS_DIR=" $AR_SDK /flags"
554
- mkdir -p " $FLAGS_DIR "
555
- echo -n " $DEFINES " > " $FLAGS_DIR /defines"
556
- echo -n " $REL_INC " > " $FLAGS_DIR /includes"
557
- echo -n " $C_FLAGS " > " $FLAGS_DIR /c_flags"
558
- echo -n " $CPP_FLAGS " > " $FLAGS_DIR /cpp_flags"
559
- echo -n " $AS_FLAGS " > " $FLAGS_DIR /S_flags"
560
- echo -n " $LD_FLAGS " > " $FLAGS_DIR /ld_flags"
561
- echo -n " $LD_SCRIPTS " > " $FLAGS_DIR /ld_scripts"
562
- echo -n " $LD_LIBS " > " $FLAGS_DIR /ld_libs"
563
-
564
- if [ -d " managed_components/espressif__esp32-camera/driver/private_include/" ]; then
565
- cp -r " managed_components/espressif__esp32-camera/driver/private_include/cam_hal.h" " $AR_SDK /include/espressif__esp32-camera/driver/include/"
566
- fi
567
-
568
- # sdkconfig
569
- cp -f " sdkconfig" " $AR_SDK /sdkconfig"
570
-
571
- # dependencies.lock
572
- cp -f " dependencies.lock" " $AR_SDK /dependencies.lock"
573
-
574
- # gen_esp32part.py
575
- # cp "$IDF_PATH/components/partition_table/gen_esp32part.py" "$AR_GEN_PART_PY"
576
-
577
693
# Handle Mem Variants
578
694
mkdir -p " $AR_SDK /$MEMCONF /include"
579
695
mv " $PWD /build/config/sdkconfig.h" " $AR_SDK /$MEMCONF /include/sdkconfig.h"
0 commit comments