#!/bin/bash

#
# To get the right gcc and preprocessor flags used for a given zephyr build,
# run west build in verbose mode. For example:
# west -v build -p always -b esp32c3_devkitm sample_apps/zephyr_ada_hello 2>&1 | tee ~/tmp/tmp.log
#
ZEPHYR_GCC=~/my-projects/third-party/zephyr-sdk-0.17.1/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gcc

ZEPHYR_CFLAGS=' -DCONFIG_APP_BUILD_USE_FLASH_SECTIONS -DCONFIG_IDF_TARGET_ARCH_RISCV -DESP_PLATFORM -DKERNEL -DK_HEAP_MEM_POOL_SIZE=4608 -DPICOLIBC_LONG_LONG_PRINTF_SCANF -D__LINUX_ERRNO_EXTENSIONS__ -D__ZEPHYR__=1 -Dasm=__asm__ -I/Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/kernel/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/arch/riscv/include -I/Users/jgrivera/my-projects/zephyr_ada/sample_apps/zephyr_ada_hello/build/zephyr/include/generated/zephyr -I/Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/include -I/Users/jgrivera/my-projects/zephyr_ada/sample_apps/zephyr_ada_hello/build/zephyr/include/generated -I/Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/soc/espressif -I/Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/include/zephyr/posix -I/Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/soc/espressif/common/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/soc/espressif/esp32c3/. -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/include/bt -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../esp_shared/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../esp_shared/components/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../port/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../common/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/efuse/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/efuse/private_include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/efuse/esp32c3/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/efuse/esp32c3/private_include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_common/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_hw_support/dma -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_hw_support/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_hw_support/include/esp_private -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_hw_support/include/hal -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_hw_support/include/soc -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_hw_support/include/soc/esp32c3 -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_hw_support/port/esp32c3 -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_hw_support/port/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_rom/esp32c3 -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_rom/esp32c3/ld -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_rom/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_rom/include/esp32c3 -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_system/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_system/include/esp_private -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_system/port/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_system/port/include/private -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/hal/esp32c3/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/hal/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/hal/platform_port/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/log/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/soc/esp32c3/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/soc/esp32c3/ld -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/soc/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/riscv/esp32c3/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/riscv/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/riscv/include/esp_private -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/riscv/include/xtensa -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_timer/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_timer/private_include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/driver/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/driver/deprecated -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/driver/gpio/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/driver/uart/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/driver/touch_sensor/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/driver/touch_sensor/esp32c3/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/driver/spi/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/spi_flash/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/spi_flash/include/spi_flash -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_pm/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/bootloader_support/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/bootloader_support/private_include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/bootloader_support/bootloader_flash/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/heap/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_mm/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_netif/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_coex/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_phy/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_phy/include/esp_private -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_phy/esp32c3/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_wifi/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/esp_event/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/esp_supplicant/src -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/esp_supplicant/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/include/esp_supplicant -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/port/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/src -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/src/crypto -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/src/utils -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/wpa_supplicant/src/eap_peer -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../../components/mbedtls/port/include -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/espressif/zephyr/esp32c3/../port/include/boot -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/ti/mspm0/source/ti/devices/msp/. -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/ti/mspm0/source/ti/devices/msp/m0p -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/ti/mspm0/source/ti/devices/msp/peripherals -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/ti/mspm0/source/ti/devices/msp/peripherals/m0p -I/Users/jgrivera/my-projects/third-party/zephyrproject/modules/hal/ti/mspm0/source/ti/devices/msp/peripherals/m0p/sysctl -isystem /Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/lib/libc/common/include -fno-strict-aliasing -Os -imacros /Users/jgrivera/my-projects/zephyr_ada/sample_apps/zephyr_ada_hello/build/zephyr/include/generated/zephyr/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mabi=ilp32 -march=rv32imc_zicsr --sysroot=/Users/jgrivera/my-projects/third-party/zephyr-sdk-0.17.1/riscv64-zephyr-elf/riscv64-zephyr-elf -imacros /Users/jgrivera/my-projects/third-party/zephyrproject/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/Users/jgrivera/my-projects/zephyr_ada/sample_apps/zephyr_ada_hello=CMAKE_SOURCE_DIR -fmacro-prefix-map=/Users/jgrivera/my-projects/third-party/zephyrproject/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/Users/jgrivera/my-projects/third-party/zephyrproject=WEST_TOPDIR -ffunction-sections -fdata-sections -specs=picolibc.specs -D_POSIX_THREADS -fstrict-volatile-bitfields -std=c99'

output_dir=src/third_party/generated_zephyr_ada_bindings/esp32c3_devkitm
mkdir -p $output_dir
rm -f  $output_dir/*
cd $output_dir
$ZEPHYR_GCC $ZEPHYR_CFLAGS -c -fdump-ada-spec -C ~/my-projects/third-party/zephyrproject/zephyr/include/zephyr/kernel.h
$ZEPHYR_GCC $ZEPHYR_CFLAGS -c -fdump-ada-spec -C ~/my-projects/third-party/zephyrproject/zephyr/include/zephyr/posix/pthread.h
#$ZEPHYR_GCC $ZEPHYR_CFLAGS -c -fdump-ada-spec -C ~/my-projects/third-party/zephyrproject/zephyr/include/zephyr/portability/cmsis_os2.h
cd -
ls -l $output_dir

