1#!/bin/bash
2
3# There is only one tx_port.h file that covers three architectures: M3/M4/M7 and four tools: ac5/ac6/gnu/iar.
4# This file is in threadx/ports/armv7-m/inc. We are going to ignore GHS for now, but I’d like to get GHS unified as well.
5
6set -e
7
8ports_folder="ports"
9source_folder="ports_arch/ARMv7-M/threadx"
10target_mcu="cortex_m3 cortex_m4 cortex_m7"
11source_inc_folder="$source_folder/inc"
12target_inc_mcu=$target_mcu
13target_inc_ide="ac5 ac6 gnu iar keil"
14target_inc_folder="inc"
15source_src_ide="ac5 ac6 gnu iar"
16target_src_mcu=$target_mcu
17src_folder="src"
18readme="readme_threadx.txt"
19source_string="Cortex-Mx"
20target_string_pre="Cortex-M"
21
22cd $(dirname `realpath $0`)/..
23
24# Copy port files
25for mcu in $target_mcu;
26do
27    for ide in $target_inc_ide;
28    do
29        # Copy files
30        target=$ports_folder/$mcu/$ide/$target_inc_folder
31        [ -d "$target" ] || continue
32        echo "$source_inc_folder -> $target"
33        rm -rf $target
34        cp -rf $source_inc_folder $target
35
36        # String replacement
37        mcu_string="$target_string_pre${mcu: -1}"
38        if [ "$ide" == "keil" ];
39        then
40            ide_string="Keil"
41            mcu_ide_string="$mcu_string\/$ide_string"
42        else
43            ide_string="${ide^^}"
44            mcu_ide_string="$mcu_string\/$ide_string "
45        fi
46        sed -i "s/ $source_string    /$mcu_ide_string/g" $target/*
47        sed -i "s/ThreadX $source_string /ThreadX $mcu_string\/$ide_string /g" $target/*
48        sed -i "s/$source_string/$mcu_string/g" $target/*
49    done
50done
51echo ""
52
53# Copy source files
54for ide in $source_src_ide;
55do
56    for mcu in $target_src_mcu;
57    do
58        # Copy source files
59        src=$source_folder/$ide/$src_folder
60        target=$ports_folder/$mcu/$ide/$src_folder
61        #[ -d "$target" ] || continue
62        echo "$src -> $target"
63        rm -rf $target
64        cp -rf $src $target
65
66        # String replacement
67        sed -i "s/$source_string/$target_string_pre${mcu: -1}/g" $target/*
68
69        # Copy readme files
70        src=$source_folder/$ide/$readme
71        target=$ports_folder/$mcu/$ide/$readme
72        #[ -f "$target" ] || continue
73        echo "$src -> $target"
74        rm -f $target
75        cp -f $src $target
76
77        # String replacement
78        sed -i "s/$source_string/$target_string_pre${mcu: -1}/g" $target
79    done
80done