|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +################### |
| 4 | +# name: ux-src |
| 5 | +# description: SImple script to generate a UNIX-friendly structure from a RISC OS source tree |
| 6 | +# author: Paolo Fabio Zaino |
| 7 | +# license: Copyright by Paolo Fabio Zaino, all rights reserved |
| 8 | +# distributed under CDDL v1.1 |
| 9 | +# |
| 10 | +# Long description: |
| 11 | +# This script is used to generate a temporary (and not pushable) ux-src directory |
| 12 | +# that will be used to reconfigure your source code in a way that is "usable" by |
| 13 | +# Linux/BSD based tools for code analysis, SAST etc. |
| 14 | +# |
| 15 | +# Usage: |
| 16 | +# To use this script it's easy: |
| 17 | +# ux-src gen |
| 18 | +# the above will create ux-src in your local directory and will link all your source files |
| 19 | +# ina UNIXy way. |
| 20 | +# To remove ux-src directory type: |
| 21 | +# ux-src clean |
| 22 | +# And, if the directory exists in your pwd then it will be removed. |
| 23 | +#################### |
| 24 | + |
| 25 | +cmd="$1" |
| 26 | +env="$2" |
| 27 | +curr_dir="$3" |
| 28 | +if [ "${curr_dir}" == "" ] |
| 29 | +then |
| 30 | + curr_dir="$(pwd)" |
| 31 | +fi |
| 32 | + |
| 33 | +# Display command usage: |
| 34 | +function usage() |
| 35 | +{ |
| 36 | + echo "Usage: ux-src [gen|clean] [path]" |
| 37 | + echo "gen: generate ux-src directory" |
| 38 | + echo "clean: remove ux-src directory" |
| 39 | +} |
| 40 | + |
| 41 | +# Link files from directory f_dir to directory ux-src with extension f_ext: |
| 42 | +function link_files() |
| 43 | +{ |
| 44 | + f_dir="$1" |
| 45 | + f_ext="$2" |
| 46 | + if [ -d ${curr_dir}/src/${f_dir} ] |
| 47 | + then |
| 48 | + for f in ${curr_dir}/src/${f_dir}/* |
| 49 | + do |
| 50 | + if [ ! -f ${f} ] |
| 51 | + then |
| 52 | + continue |
| 53 | + else |
| 54 | + fname="$(basename ${f})" |
| 55 | + if [ "${env}" == "github" ] |
| 56 | + then |
| 57 | + # GitHub Actions do not support symlinks: |
| 58 | + cp ${f} ${curr_dir}/ux-src/${fname}.${f_ext} |
| 59 | + else |
| 60 | + ln -s ${f} ${curr_dir}/ux-src/${fname}.${f_ext} |
| 61 | + fi |
| 62 | + fi |
| 63 | + done |
| 64 | + fi |
| 65 | +} |
| 66 | + |
| 67 | +# Check command line syntax: |
| 68 | +function check_cmd() |
| 69 | +{ |
| 70 | + if [ "$cmd" != "gen" ] && [ "$cmd" != "clean" ] |
| 71 | + then |
| 72 | + usage |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | +} |
| 76 | + |
| 77 | +################# |
| 78 | +# Main program |
| 79 | +################# |
| 80 | + |
| 81 | +# Check commadn line syntax: |
| 82 | +check_cmd |
| 83 | + |
| 84 | +# Check if we are in a RISC OS source tree: |
| 85 | +if [ ! -d ${curr_dir}/src ] |
| 86 | +then |
| 87 | + echo "Error: you are not in a RISC OS source tree" |
| 88 | + exit 1 |
| 89 | +fi |
| 90 | + |
| 91 | +# Run the command: |
| 92 | +if [ "$cmd" == "gen" ] |
| 93 | +then |
| 94 | + echo "Generating ux-src directory in ${curr_dir}" |
| 95 | + |
| 96 | + # Generate ux-src: |
| 97 | + mkdir ${curr_dir}/ux-src |
| 98 | + |
| 99 | + # Link C files (if any): |
| 100 | + link_files "c" "c" |
| 101 | + link_files "C" "c" |
| 102 | + |
| 103 | + # Link C++ files (if any): |
| 104 | + link_files "cpp" "cpp" |
| 105 | + link_files "CPP" "cpp" |
| 106 | + link_files "cxx" "cxx" |
| 107 | + link_files "CXX" "cxx" |
| 108 | + link_files "cc" "cc" |
| 109 | + link_files "CC" "cc" |
| 110 | + link_files "c++" "cpp" |
| 111 | + link_files "C++" "cpp" |
| 112 | + |
| 113 | + # Link C++ header files (if any): |
| 114 | + link_files "hpp" "hpp" |
| 115 | + link_files "HPP" "hpp" |
| 116 | + link_files "hxx" "hxx" |
| 117 | + link_files "HXX" "hxx" |
| 118 | + |
| 119 | + # Link C header files (if any): |
| 120 | + link_files "h" "h" |
| 121 | + link_files "H" "h" |
| 122 | + |
| 123 | + # Link Assembler files (if any): |
| 124 | + link_files "s" "s" |
| 125 | + link_files "S" "s" |
| 126 | + link_files "Hdr" "s" |
| 127 | + |
| 128 | + # Link Forth files (if any): |
| 129 | + link_files "fth" "fth" |
| 130 | + link_files "FTH" "fth" |
| 131 | + |
| 132 | + # Link Pascal and Prolog files (if any): |
| 133 | + link_files "p" "p" |
| 134 | + link_files "P" "p" |
| 135 | + |
| 136 | + # Link Perl files (if any): |
| 137 | + link_files "pl" "pl" |
| 138 | + link_files "PL" "pl" |
| 139 | + |
| 140 | + # Link BASIC files (if any): |
| 141 | + link_files "bas" "bas" |
| 142 | + link_files "BAS" "bas" |
| 143 | + |
| 144 | + # Link Makefiles |
| 145 | + for f in ${curr_dir}/src/Makefile* |
| 146 | + do |
| 147 | + fname="$(basename ${f})" |
| 148 | + if [ "$env" == "github" ] |
| 149 | + then |
| 150 | + # GitHub Actions do not support symlinks: |
| 151 | + cp ${f} ${curr_dir}/ux-src/${fname} |
| 152 | + else |
| 153 | + ln -s ${f} ${curr_dir}/ux-src/${fname} |
| 154 | + fi |
| 155 | + done |
| 156 | + |
| 157 | + # Link the Build Script for Unix: |
| 158 | + if [ -f ${curr_dir}/src/MkGCC.sh ] |
| 159 | + then |
| 160 | + if [ "$env" == "github" ] |
| 161 | + then |
| 162 | + # GitHub Actions do not support symlinks: |
| 163 | + cp ${curr_dir}/src/MkGCC.sh ${curr_dir}/ux-src/MkGCC.sh |
| 164 | + else |
| 165 | + ln -s ${curr_dir}/src/MkGCC.sh ${curr_dir}/ux-src/MkGCC.sh |
| 166 | + fi |
| 167 | + fi |
| 168 | + |
| 169 | + ls -l ${curr_dir}/ux-src |
| 170 | +else |
| 171 | + # Remove existing ux-src |
| 172 | + if [ -d ${curr_dir}/ux-src ] |
| 173 | + then |
| 174 | + for f in ${curr_dir}/ux-src/* |
| 175 | + do |
| 176 | + if [ "$env" == "github" ] |
| 177 | + then |
| 178 | + # GitHub Actions do not support symlinks: |
| 179 | + rm -f ${f} |
| 180 | + else |
| 181 | + unlink ${f} |
| 182 | + fi |
| 183 | + done |
| 184 | + rm -rf ${curr_dir}/ux-src |
| 185 | + fi |
| 186 | + |
| 187 | +fi |
| 188 | + |
| 189 | +exit $? |
0 commit comments