1
+ #! /bin/bash
2
+
3
+ LICENSE_DIRECTORY=" third-party-licenses"
4
+ EXIT_CODE=0
5
+ LIBRARIES=(" pspsdk" " newlib" " pthread-embedded" $@ )
6
+ SCRIPT_NAME=" $( basename " $0 " ) "
7
+
8
+ usage ( ) {
9
+ cat << EOF
10
+ ${SCRIPT_NAME} [OPTION] [LIBRARY]...
11
+ The ${SCRIPT_NAME} tool makes it easier to comply with licenses of used libraries.
12
+ It adds the licenses to the ${LICENSE_DIRECTORY} directory.
13
+ The licenses for pspsdk, newlib and pthread-embedded are always addded,
14
+ since they will always be compiled into your project.
15
+
16
+ options:
17
+ -h Print this message
18
+ -l List installed libraries
19
+
20
+ example:
21
+ If your project has included SDL2, SDL2_ttf and jsoncpp:
22
+
23
+ ${SCRIPT_NAME} sdl2 sdl2-ttf jsoncpp
24
+
25
+ To get a list of installed libraries to get the name right use:
26
+
27
+ ${SCRIPT_NAME} -l
28
+
29
+ EOF
30
+ }
31
+
32
+ get_dependencies ( ) {
33
+ if [ " ${1} " != " pspsdk" ] && [ " ${1} " != " newlib" ] && [ " ${1} " != " pthread-embedded" ]; then
34
+ echo " $( psp-pacman -Qi ${1} | grep " ^Depends On" | cut -d' :' -f 2-| xargs echo) "
35
+ fi
36
+ }
37
+
38
+ copy_license_directory ( ) {
39
+ if [ -d " ${PSPDEV} /psp/share/licenses/${1} " ]; then
40
+ if [ ! -d " ${LICENSE_DIRECTORY} /${1} " ]; then
41
+ echo " Adding license for ${1} to ${LICENSE_DIRECTORY} "
42
+ fi
43
+ cp -rf " ${PSPDEV} /psp/share/licenses/${1} " " ${LICENSE_DIRECTORY} /"
44
+ for dependency in $( get_dependencies " ${1} " ) ; do
45
+ if [ " ${dependency} " == " None" ]; then
46
+ continue
47
+ fi
48
+ if [ ! -d " ${LICENSE_DIRECTORY} /${dependency} " ]; then
49
+ echo " Found dependency ${dependency} for ${1} "
50
+ fi
51
+ copy_license_directory " ${dependency} "
52
+ done
53
+ else
54
+ echo " Failed to find license for library ${1} "
55
+ EXIT_CODE=2
56
+ fi
57
+ }
58
+
59
+ if [ -z " ${PSPDEV} " ]; then
60
+ echo " The PSPDEV environment variable has not been set"
61
+ exit 1
62
+ fi
63
+
64
+ while getopts " hl" OPTION; do
65
+ case ${OPTION} in
66
+ h)
67
+ usage
68
+ exit 0
69
+ ;;
70
+ l)
71
+ psp-pacman -Qq
72
+ exit 0
73
+ ;;
74
+ * )
75
+ echo " ${OPTION} - Unrecongnized option"
76
+ usage
77
+ exit 1
78
+ ;;
79
+ esac
80
+ done
81
+
82
+ mkdir -p " ${LICENSE_DIRECTORY} "
83
+ for library in ${LIBRARIES[@]} ; do
84
+ copy_license_directory " ${library} "
85
+ done
86
+ exit ${EXIT_CODE}
0 commit comments