-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_output
executable file
·115 lines (99 loc) · 2.75 KB
/
generate_output
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
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2021 Robin Vobruba <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# See the output of "$0 -h" for more details.
#
# Dependencies:
# $ pip install pcb-tools
# Exit immediately on each error and unset variable;
# see: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
#set -Eeuo pipefail
set -Eeu
script_dir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
# shellcheck source=./_shared_git
#source "$script_dir/_shared_git"
# initial default values
APP_NAME="KiCad Output Generator"
function print_help() {
script_name="$(basename "$0")"
echo "$APP_NAME - Generates Gerber, drill files and renders,"
echo "with a KiCad PCB file as input."
echo "NOTE: This script depends on 2 python scripts and their dependencies."
echo
echo "Usage:"
echo " $script_name [OPTIONS] <local-repo-dir>"
echo "Options:"
echo " -h, --help Show this help message"
echo " -n, --name <string> Project name (prefferably without spaces)"
echo " -v, --version <string> Project version (prefferably without spaces)"
echo " --build-date <string> Date at which the currently being-made build of the project is made"
echo " This shold basically always be left on the default,"
echo " which is the current date."
echo "Examples:"
echo " $0"
echo " $0 -n my-proj -v 1.2.0"
}
# read command-line args
POSITIONAL=()
while [[ $# -gt 0 ]]
do
arg="$1"
shift # $2 -> $1, $3 -> $2, ...
case "$arg" in
-h|--help)
print_help
exit 0
;;
-n|--name)
project_name="$1"
shift # past argument
;;
-v|--version)
project_version="$1"
shift # past argument
;;
--build-date)
project_build_date="$1"
shift # past argument
;;
*) # non-/unknown option
POSITIONAL+=("$arg") # save it in an array for later
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
root_dir="${1:-$(pwd)}"
root_dir_abs="$(cd "$root_dir"; pwd)"
build_root="${root_dir}/build"
gen_src_root="${build_root}/gen-src"
gerbers_root="${build_root}/gerbers"
assets_root="${build_root}/assets"
project_name="${project_name:-$(cd "$root_dir"; basename "$(pwd)")}"
project_version="${project_version:-$("${script_dir}/git-version" -e "$root_dir")}"
date="$(date +'%Y-%m-%d')"
if [ -z "$project_name" ]
then
>&2 echo "WARNING: No project name given!"
print_help
exit 1
fi
if [ -z "$project_version" ]
then
>&2 echo "WARNING: No project version given!"
print_help
exit 1
fi
mkdir -p "$gen_src_root"
mkdir -p "$gerbers_root"
mkdir -p "$assets_root"
for fi in *.sch *.lib *.dcm *.pro *.kibot.yaml fp-info-cache sym-lib-table Makefile
do
if [ -f "$fi" ]
then
cp "$fi" "$gen_src_root/"
fi
done
cd "$gen_src_root"
time make
echo "done."