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