@@ -17,7 +17,7 @@ source ./tools/config.sh
17
17
18
18
echo " IDF_TARGET: $IDF_TARGET , MEMCONF: $MEMCONF , PWD: $PWD , OUT: $AR_SDK "
19
19
20
- # clean previous
20
+ # Clean previous build artifacts
21
21
if [ -e " $AR_SDK /sdkconfig" ]; then
22
22
rm -rf " $AR_SDK /sdkconfig"
23
23
fi
43
43
mkdir -p " $AR_SDK "
44
44
mkdir -p " $AR_SDK /lib"
45
45
46
+ # Helper function to resolve actual path
46
47
function get_actual_path(){
47
48
d=" $1 " ;
48
49
if [ -d " $d " ]; then
87
88
TOOLCHAIN=" riscv32-esp-elf"
88
89
fi
89
90
90
- # copy zigbee + zboss lib
91
+ # Copy zigbee + zboss libraries if available
91
92
if [ -d " managed_components/espressif__esp-zigbee-lib/lib/$IDF_TARGET /" ]; then
92
93
cp -r " managed_components/espressif__esp-zigbee-lib/lib/$IDF_TARGET " /* " $AR_SDK /lib/"
93
94
EXCLUDE_LIBS+=" esp_zb_api.ed;esp_zb_api.zczr;"
@@ -98,10 +99,10 @@ if [ -d "managed_components/espressif__esp-zboss-lib/lib/$IDF_TARGET/" ]; then
98
99
EXCLUDE_LIBS+=" zboss_stack.ed;zboss_stack.zczr;zboss_port.native;zboss_port.native.debug;zboss_port.remote;zboss_port.remote.debug;"
99
100
fi
100
101
101
- # collect includes, defines and c-flags
102
+ # Extract includes, defines and c-flags from compile_commands.json
102
103
str=` cat build/compile_commands.json | grep arduino-lib-builder-gcc.c | grep command | cut -d' :' -f2 | cut -d' ,' -f1`
103
- str=" ${str: 2: ${# str} -1} " # remove leading space and quotes
104
- str=` printf ' %b' " $str " ` # unescape the string
104
+ str=" ${str: 2: ${# str} -1} "
105
+ str=` printf ' %b' " $str " `
105
106
set -- $str
106
107
for item in " ${@: 2: ${#@ } -5} " ; do
107
108
prefix=" ${item: 0: 2} "
@@ -122,7 +123,7 @@ for item in "${@:2:${#@}-5}"; do
122
123
INCLUDES+=" $item "
123
124
fi
124
125
elif [ " $prefix " = " -D" ]; then
125
- if [[ " ${item: 2: 7} " != " ARDUINO" ]] && [[ " $item " != " -DESP32=ESP32" ]] && [[ " $item " != " -DNDEBUG" ]]; then # skip ARDUINO defines
126
+ if [[ " ${item: 2: 7} " != " ARDUINO" ]] && [[ " $item " != " -DESP32=ESP32" ]] && [[ " $item " != " -DNDEBUG" ]]; then
126
127
DEFINES+=" $item "
127
128
fi
128
129
elif [ " $prefix " = " -O" ]; then
@@ -134,10 +135,10 @@ for item in "${@:2:${#@}-5}"; do
134
135
fi
135
136
done
136
137
137
- # collect asm- flags
138
+ # Extract assembly flags from compile_commands.json
138
139
str=` cat build/compile_commands.json | grep arduino-lib-builder-as.S | grep command | cut -d' :' -f2 | cut -d' ,' -f1`
139
- str=" ${str: 2: ${# str} -1} " # remove leading space and quotes
140
- str=` printf ' %b' " $str " ` # unescape the string
140
+ str=" ${str: 2: ${# str} -1} "
141
+ str=` printf ' %b' " $str " `
141
142
set -- $str
142
143
for item in " ${@: 2: ${#@ } -5} " ; do
143
144
prefix=" ${item: 0: 2} "
@@ -153,10 +154,10 @@ for item in "${@:2:${#@}-5}"; do
153
154
fi
154
155
done
155
156
156
- # collect cpp- flags
157
+ # Extract C++ flags from compile_commands.json
157
158
str=` cat build/compile_commands.json | grep arduino-lib-builder-cpp.cpp | grep command | cut -d' :' -f2 | cut -d' ,' -f1`
158
- str=" ${str: 2: ${# str} -1} " # remove leading space and quotes
159
- str=` printf ' %b' " $str " ` # unescape the string
159
+ str=" ${str: 2: ${# str} -1} "
160
+ str=` printf ' %b' " $str " `
160
161
set -- $str
161
162
for item in " ${@: 2: ${#@ } -5} " ; do
162
163
prefix=" ${item: 0: 2} "
@@ -177,7 +178,7 @@ for item; do
177
178
fi
178
179
done
179
180
180
- # parse link command to extract libs and flags
181
+ # Parse link command to extract libraries and flags
181
182
add_next=0
182
183
is_dir=0
183
184
is_script=0
@@ -207,26 +208,25 @@ for item; do
207
208
prefix=" ${item: 0: 1} "
208
209
if [ " $prefix " = " -" ]; then
209
210
if [ " ${item: 0: 10} " != " -Wl,--Map=" ]; then
210
- if [ " $item " = " -L" ]; then # -L /path
211
+ if [ " $item " = " -L" ]; then
211
212
add_next=1
212
213
is_dir=1
213
- elif [ " ${item: 0: 2} " = " -L" ]; then # -L/path
214
+ elif [ " ${item: 0: 2} " = " -L" ]; then
214
215
LD_SCRIPT_DIRS+=" ${item: 2} "
215
- elif [ " $item " = " -T" ]; then # -T script.ld
216
+ elif [ " $item " = " -T" ]; then
216
217
add_next=1
217
218
is_script=1
218
219
LD_SCRIPTS+=" $item "
219
- elif [ " $item " = " -u" ]; then # -u function_name
220
+ elif [ " $item " = " -u" ]; then
220
221
add_next=1
221
222
LD_FLAGS+=" $item "
222
- elif [ " ${item: 0: 2} " = " -l" ]; then # -l[lib_name]
223
+ elif [ " ${item: 0: 2} " = " -l" ]; then
223
224
short_name=" ${item: 2} "
224
225
if [[ $EXCLUDE_LIBS != * " ;$short_name ;" * ]]; then
225
226
LD_LIBS+=" $item "
226
227
exclude_libs=" ;m;c;gcc;stdc++;"
227
228
if [[ $exclude_libs != * " ;$short_name ;" * && $LD_LIBS_SEARCH != * " lib$short_name .a" * ]]; then
228
229
LD_LIBS_SEARCH+=" lib$short_name .a "
229
- # echo "1. lib add: $item"
230
230
fi
231
231
fi
232
232
elif [ " $item " = " -o" ]; then
@@ -262,29 +262,26 @@ for item; do
262
262
if [[ " $lname " != " main" && " $lname " != " arduino" ]]; then
263
263
lsize=$( $SSTAT " $item " )
264
264
if (( lsize > 8 )) ; then
265
- # do we already have this file?
265
+ # Check if we already have this file
266
266
if [[ $LD_LIB_FILES != * " $item " * ]]; then
267
- # do we already have lib with the same name?
267
+ # Check if we already have lib with the same name
268
268
if [[ $LD_LIBS != * " -l$lname " * ]]; then
269
269
if [[ $EXCLUDE_LIBS != * " ;$lname ;" * ]]; then
270
- # echo "2. collecting lib '$lname' and file: $item"
271
270
LD_LIB_FILES+=" $item "
272
271
LD_LIBS+=" -l$lname "
273
272
fi
274
273
else
275
- # echo "!!! need to rename: '$lname'"
274
+ # Need to rename library to avoid conflicts
276
275
for i in {2..9}; do
277
276
n_item=" ${item: 0: ${# item} -2} _$i .a"
278
277
n_name=$lname " _$i "
279
278
if [ -f " $n_item " ]; then
280
279
if [[ $EXCLUDE_LIBS != * " ;$lname ;" * ]]; then
281
- # echo "3. renamed add: -l$n_name"
282
280
LD_LIBS+=" -l$n_name "
283
281
fi
284
282
break
285
283
elif [[ $LD_LIB_FILES != * " $n_item " * && $LD_LIBS != * " -l$n_name " * ]]; then
286
284
if [[ $EXCLUDE_LIBS != * " ;$lname ;" * ]]; then
287
- # echo "4. Renaming '$lname' to '$n_name': $item"
288
285
cp -f " $item " " $n_item "
289
286
LD_LIB_FILES+=" $n_item "
290
287
LD_LIBS+=" -l$n_name "
@@ -295,7 +292,6 @@ for item; do
295
292
fi
296
293
else
297
294
if [[ $EXCLUDE_LIBS != * " ;$lname ;" * ]]; then
298
- # echo "5. just add: -l$lname"
299
295
LD_LIBS+=" -l$lname "
300
296
fi
301
297
fi
@@ -318,11 +314,11 @@ done
318
314
319
315
mkdir -p " $AR_SDK "
320
316
321
- # start generation of pioarduino-build.py
317
+ # Start generation of pioarduino-build.py
322
318
AR_PLATFORMIO_PY=" $AR_SDK /pioarduino-build.py"
323
319
cat configs/pio_start.txt > " $AR_PLATFORMIO_PY "
324
320
325
- # include dirs - SAMMLE REL_INC für Include-Verkürzung UND kopiere Header
321
+ # Process include directories - collect shortened include paths and copy headers
326
322
REL_INC=" "
327
323
set -- $INCLUDES
328
324
@@ -350,7 +346,7 @@ for item; do
350
346
out_cpath=" $AR_SDK /include/$fname$out_sub "
351
347
REL_INC+=" -iwithprefixbefore $fname$out_sub "
352
348
353
- # KOPIERE HEADER-DATEIEN
349
+ # Copy header files to output directory
354
350
for f in ` find " $item " -name ' *.h' ` ; do
355
351
rel_f=${f#* $item }
356
352
rel_p=${rel_f%/* }
@@ -377,28 +373,25 @@ for item; do
377
373
fi
378
374
done
379
375
380
- # ASFLAGS mit korrigierter Include-Verkürzung (ein String wie Python-Version)
376
+ # Generate ASFLAGS with shortened include paths
381
377
echo " ASFLAGS=[" >> " $AR_PLATFORMIO_PY "
382
378
if [ " $IS_XTENSA " = " y" ]; then
383
379
echo " \" -mlongcalls\" ," >> " $AR_PLATFORMIO_PY "
384
380
else
385
381
echo " \" -march=rv32imc\" ," >> " $AR_PLATFORMIO_PY "
386
382
fi
387
383
388
- # Füge Include-Verkürzung aus REL_INC hinzu - KORRIGIERT wie Python-Version
384
+ # Add shortened include paths for assembly
389
385
if [[ -n " $REL_INC " ]]; then
390
386
echo " \" -iprefix\" , join(FRAMEWORK_DIR, \" tools\" , \" sdk\" , \" $IDF_TARGET \" )," >> " $AR_PLATFORMIO_PY "
391
- # Verarbeite REL_INC korrekt - Flag und Pfad sind getrennt
392
387
IFS=' ' read -ra rel_inc_array <<< " $REL_INC"
393
388
i=0
394
389
while [ $i -lt ${# rel_inc_array[@]} ]; do
395
390
if [[ " ${rel_inc_array[$i]} " == " -iwithprefixbefore" ]]; then
396
- # Nächstes Element ist der Pfad
397
391
if [ $(( i+ 1 )) -lt ${# rel_inc_array[@]} ]; then
398
392
path=" ${rel_inc_array[$((i+1))]} "
399
- # KORRIGIERT: Ein String wie Python-Version
400
393
echo " \" -iwithprefix/include/$path \" ," >> " $AR_PLATFORMIO_PY "
401
- i=$(( i+ 2 )) # Überspringe Flag und Pfad
394
+ i=$(( i+ 2 ))
402
395
else
403
396
i=$(( i+ 1 ))
404
397
fi
@@ -444,27 +437,24 @@ echo " \"$last_item\"" >> "$AR_PLATFORMIO_PY"
444
437
echo " ]," >> " $AR_PLATFORMIO_PY "
445
438
echo " " >> " $AR_PLATFORMIO_PY "
446
439
447
- # CCFLAGS mit korrigierter Include-Verkürzung (ein String wie Python-Version)
440
+ # Generate CCFLAGS with shortened include paths
448
441
echo " CCFLAGS=[" >> " $AR_PLATFORMIO_PY "
449
442
set -- $PIO_CC_FLAGS
450
443
for item; do
451
444
echo " \" $item \" ," >> " $AR_PLATFORMIO_PY "
452
445
done
453
446
454
- # Füge Include-Verkürzung aus REL_INC hinzu - KORRIGIERT wie Python-Version
447
+ # Add shortened include paths for C/C++ compilation
455
448
if [[ -n " $REL_INC " ]]; then
456
449
echo " \" -iprefix\" , join(FRAMEWORK_DIR, \" tools\" , \" sdk\" , \" $IDF_TARGET \" )," >> " $AR_PLATFORMIO_PY "
457
- # Verarbeite REL_INC korrekt - Flag und Pfad sind getrennt
458
450
IFS=' ' read -ra rel_inc_array <<< " $REL_INC"
459
451
i=0
460
452
while [ $i -lt ${# rel_inc_array[@]} ]; do
461
453
if [[ " ${rel_inc_array[$i]} " == " -iwithprefixbefore" ]]; then
462
- # Nächstes Element ist der Pfad
463
454
if [ $(( i+ 1 )) -lt ${# rel_inc_array[@]} ]; then
464
455
path=" ${rel_inc_array[$((i+1))]} "
465
- # KORRIGIERT: Ein String wie Python-Version
466
- echo " \" -iwithprefix/include/$path \" ," >> " $AR_PLATFORMIO_PY "
467
- i=$(( i+ 2 )) # Überspringe Flag und Pfad
456
+ echo " \" $iwithprefix /include/$path \" ," >> " $AR_PLATFORMIO_PY "
457
+ i=$(( i+ 2 ))
468
458
else
469
459
i=$(( i+ 1 ))
470
460
fi
@@ -496,7 +486,7 @@ echo " '-Wl,-Map=\"%s\"' % join(\"\${BUILD_DIR}\", \"\${PROGNAME}.map\")"
496
486
echo " ]," >> " $AR_PLATFORMIO_PY "
497
487
echo " " >> " $AR_PLATFORMIO_PY "
498
488
499
- # CPPPATH - NUR Arduino Core (KEINE Framework-Headers !)
489
+ # CPPPATH - Only Arduino Core (NO Framework headers !)
500
490
echo " CPPPATH=[" >> " $AR_PLATFORMIO_PY "
501
491
echo " join($PIO_SDK , board_config.get(\" build.arduino.memory_type\" , (board_config.get(\" build.flash_mode\" , \" dio\" ) + \" _qspi\" )), \" include\" )," >> " $AR_PLATFORMIO_PY "
502
492
echo " join(FRAMEWORK_DIR, \" cores\" , board_config.get(\" build.core\" ))" >> " $AR_PLATFORMIO_PY "
@@ -513,9 +503,9 @@ for item; do
513
503
PIO_LIBS+=" \" $item \" "
514
504
done
515
505
506
+ # Strip and copy library files
516
507
set -- $LD_LIB_FILES
517
508
for item; do
518
- # echo "***** Stripping $item"
519
509
" $TOOLCHAIN -strip" -g " $item "
520
510
cp " $item " " $AR_SDK /lib/"
521
511
done
@@ -535,8 +525,8 @@ echo "" >> "$AR_PLATFORMIO_PY"
535
525
echo " CPPDEFINES=[" >> " $AR_PLATFORMIO_PY "
536
526
set -- $DEFINES
537
527
for item; do
538
- item=" ${item: 2} " # remove -D
539
- item=" ${item/ NDEBUG} " # remove NDEBUG
528
+ item=" ${item: 2} "
529
+ item=" ${item/ NDEBUG} "
540
530
if [[ $item == * " =" * ]]; then
541
531
item=(${item// =/ } )
542
532
re=' ^[+-]?[0-9]+([.][0-9]+)?$'
@@ -550,13 +540,13 @@ for item; do
550
540
fi
551
541
done
552
542
553
- # end generation of platformio-build.py
543
+ # End generation of platformio-build.py
554
544
cat configs/pio_end.txt >> " $AR_PLATFORMIO_PY "
555
545
556
- # replace double backslashes with single one
546
+ # Replace double backslashes with single one
557
547
DEFINES=` echo " $DEFINES " | tr -s ' \' `
558
548
559
- # target flags files
549
+ # Generate target flags files
560
550
FLAGS_DIR=" $AR_SDK /flags"
561
551
mkdir -p " $FLAGS_DIR "
562
552
echo -n " $DEFINES " > " $FLAGS_DIR /defines"
@@ -572,16 +562,11 @@ if [ -d "managed_components/espressif__esp32-camera/driver/private_include/" ];
572
562
cp -r " managed_components/espressif__esp32-camera/driver/private_include/cam_hal.h" " $AR_SDK /include/espressif__esp32-camera/driver/include/"
573
563
fi
574
564
575
- # sdkconfig
565
+ # Copy configuration files
576
566
cp -f " sdkconfig" " $AR_SDK /sdkconfig"
577
-
578
- # dependencies.lock
579
567
cp -f " dependencies.lock" " $AR_SDK /dependencies.lock"
580
568
581
- # gen_esp32part.py
582
- # cp "$IDF_PATH/components/partition_table/gen_esp32part.py" "$AR_GEN_PART_PY"
583
-
584
- # copy precompiled libs (if we need them)
569
+ # Helper function to copy precompiled libraries if needed
585
570
function copy_precompiled_lib(){
586
571
lib_file=" $1 "
587
572
lib_name=" $( basename $lib_file ) "
@@ -591,7 +576,7 @@ function copy_precompiled_lib(){
591
576
fi
592
577
}
593
578
594
- # idf ld scripts
579
+ # Copy IDF linker scripts and precompiled libraries
595
580
mkdir -p " $AR_SDK /ld"
596
581
set -- $LD_SCRIPT_DIRS
597
582
for item; do
@@ -603,14 +588,15 @@ for item; do
603
588
done
604
589
done
605
590
591
+ # Strip specific libraries
606
592
for lib in " openthread" " espressif__esp-tflite-micro" " bt" " espressif__esp_modem" " espressif__esp-zboss-lib" " espressif__esp-zigbee-lib" " espressif__mdns" " espressif__esp-dsp" " espressif__esp32-camera" " joltwallet__littlefs" ; do
607
593
if [ -f " $AR_SDK /lib/lib$lib .a" ]; then
608
594
echo " Stripping $AR_SDK /lib/lib$lib .a"
609
595
" $TOOLCHAIN -strip" -g " $AR_SDK /lib/lib$lib .a"
610
596
fi
611
597
done
612
598
613
- # Handle Mem Variants
599
+ # Handle memory configuration variants
614
600
mkdir -p " $AR_SDK /$MEMCONF /include"
615
601
mv " $PWD /build/config/sdkconfig.h" " $AR_SDK /$MEMCONF /include/sdkconfig.h"
616
602
for mem_variant in ` jq -c ' .mem_variants_files[]' configs/builds.json` ; do
@@ -629,6 +615,6 @@ for mem_variant in `jq -c '.mem_variants_files[]' configs/builds.json`; do
629
615
fi
630
616
done ;
631
617
632
- # Add IDF versions to sdkconfig
618
+ # Add IDF version information to sdkconfig
633
619
echo " #define CONFIG_ARDUINO_IDF_COMMIT \" $IDF_COMMIT \" " >> " $AR_SDK /$MEMCONF /include/sdkconfig.h"
634
620
echo " #define CONFIG_ARDUINO_IDF_BRANCH \" $IDF_BRANCH \" " >> " $AR_SDK /$MEMCONF /include/sdkconfig.h"
0 commit comments