Skip to content

Commit 18b2b24

Browse files
committed
Add support for custom CMake flags and positional target arguments in make-libpico.sh
- Refactor `make-libpico.sh` to accept positional arguments for target selection and a `--flags` option to forward custom CMake flags. - Update environment variable exports for clarity. - Add `LIB_PICO_MULTICORE` CMake option to `CMakeLists.txt` and propagate it to target compile definitions. - Preserve backward compatibility and improve build flexibility for local and CI workflows. Closes earlephilhower#3058
1 parent e608439 commit 18b2b24

File tree

2 files changed

+63
-23
lines changed

2 files changed

+63
-23
lines changed

tools/libpico/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cmake_minimum_required(VERSION 3.12)
22

3+
option(LIB_PICO_MULTICORE "Enable multicore support" 0)
4+
35
set(cpu $ENV{CPU})
46
message("Building for CPU ${cpu}")
57

@@ -131,6 +133,7 @@ target_compile_definitions(common-${cpu} INTERFACE
131133
CYW43_WARN=//
132134
CYW43_PIO_CLOCK_DIV_DYNAMIC=1
133135
CYW43_PIN_WL_DYNAMIC=1
136+
LIB_PICO_MULTICORE=${LIB_PICO_MULTICORE}
134137
${xcd}
135138
)
136139

tools/libpico/make-libpico.sh

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,40 @@
33
set -e # Exit on error
44
set -x
55

6-
export PICO_SDK_PATH="$(cd ../../pico-sdk/; pwd)"
7-
export PATH="$(cd ../../system/arm-none-eabi/bin; pwd):$PATH"
8-
export PATH="$(cd ../../system/riscv32-unknown-elf/bin; pwd):$PATH"
9-
export PATH="$(cd ../../system/picotool; pwd):$PATH"
6+
PICO_SDK_PATH="$(cd ../../pico-sdk/; pwd)"
7+
export PICO_SDK_PATH
8+
PATH="$(cd ../../system/arm-none-eabi/bin; pwd):$PATH"
9+
PATH="$(cd ../../system/riscv32-unknown-elf/bin; pwd):$PATH"
10+
PATH="$(cd ../../system/picotool; pwd):$PATH"
11+
export PATH
1012

11-
rm -rf build-rp2040
12-
mkdir build-rp2040
13-
cd build-rp2040
14-
CPU=rp2040 cmake ..
15-
make -j
13+
# Parse arguments
14+
targets=()
15+
flags=()
16+
parse_flags=0
17+
for arg in "$@"; do
18+
if [[ $parse_flags -eq 1 ]]; then
19+
flags+=("$arg")
20+
elif [[ $arg == "--flags" ]]; then
21+
parse_flags=1
22+
else
23+
targets+=("$arg")
24+
fi
25+
done
1626

27+
build_rp2040() {
28+
rm -rf build-rp2040
29+
mkdir build-rp2040
30+
cd build-rp2040
31+
CPU=rp2040 cmake "${flags[@]}" ..
32+
make -j
1733
# The develop branch of the SDK seems to have busted the RP2040 boot2.S files.
1834
# These don't change and aren't lkikely to get any new additions, so comment out
1935
# for now and use the prior versions built under earlier SDK.
2036
#rm -rf boot
2137
#mkdir boot
2238
#cd boot
23-
#mkdir -p pico
39+
#mkdir -p pico
2440
#touch pico/config.h
2541
#for type in boot2_generic_03h boot2_is25lp080 boot2_w25q080 boot2_w25x10cl; do
2642
# for div in 2 4; do
@@ -38,7 +54,7 @@ make -j
3854
# arm-none-eabi-gcc -march=armv6-m -mcpu=cortex-m0plus -mthumb -O3 \
3955
# -DNDEBUG -Wl,--build-id=none --specs=nosys.specs -nostartfiles \
4056
# -Wl,--script="$PICO_SDK_PATH/src/rp2040/boot_stage2/boot_stage2.ld" \
41-
# -Wl,-Map=$type.$div.elf.map $type.o -o $type.$div.elf
57+
# -Wl,-Map=$type.$div.elf.map $type.o -o $type.$div.elf
4258
#
4359
# arm-none-eabi-objdump -h $type.$div.elf > $type.$div.dis
4460
# arm-none-eabi-objdump -d $type.$div.elf >> $type.$div.dis
@@ -51,17 +67,38 @@ make -j
5167
#done
5268
#mv *.S ../../../../boot2/rp2040/.
5369
#cd ../..
70+
cd ..
71+
}
5472

55-
cd ..
56-
rm -rf build-rp2350
57-
mkdir build-rp2350
58-
cd build-rp2350
59-
CPU=rp2350 cmake ..
60-
make -j
73+
build_rp2350() {
74+
rm -rf build-rp2350
75+
mkdir build-rp2350
76+
cd build-rp2350
77+
CPU=rp2350 cmake "${flags[@]}" ..
78+
make -j
79+
cd ..
80+
}
6181

62-
cd ..
63-
rm -rf build-rp2350-riscv
64-
mkdir build-rp2350-riscv
65-
cd build-rp2350-riscv
66-
CPU=rp2350-riscv cmake ..
67-
make -j
82+
build_rp2350_riscv() {
83+
rm -rf build-rp2350-riscv
84+
mkdir build-rp2350-riscv
85+
cd build-rp2350-riscv
86+
CPU=rp2350-riscv cmake "${flags[@]}" ..
87+
make -j
88+
cd ..
89+
}
90+
91+
if [[ ${#targets[@]} -eq 0 ]]; then
92+
build_rp2040
93+
build_rp2350
94+
build_rp2350_riscv
95+
else
96+
for t in "${targets[@]}"; do
97+
case $t in
98+
rp2040) build_rp2040 ;;
99+
rp2350) build_rp2350 ;;
100+
rp2350-riscv) build_rp2350_riscv ;;
101+
*) echo "Unknown target: $t"; exit 1 ;;
102+
esac
103+
done
104+
fi

0 commit comments

Comments
 (0)