-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmydef_install.def
181 lines (161 loc) · 5.21 KB
/
mydef_install.def
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
include: version.def
page: mydef_install
type:
output_dir: script
$call parse_args
$if $b_debug
$print mydef_install: ARGV = @ARGV
# mydef_install deflib . def --> *.def -> ${MYDEFLIB}
# mydef_install MyDef/lib . pm --> *.pm -> ${PERL5LIB}
# mydef_install MyDef/script . - --> * -> ${PATH}
# mydef_install - out/{a,b,c} --> * -> ${PATH}
$call check_install_dir
$if $dst ne "."
$install_dir.="/$dst"
$if $b_debug
$print install_dir: $install_dir
$if @$src_list
install_all($src_list, $install_dir, $ext)
subcode: parse_args
$call @check_arg_version, $ARGV[0]
$global $b_force, $b_debug
$if $ARGV[0] eq "-f"
$b_force = 1
shift @ARGV
$if $ARGV[0] eq "-debug"
$b_debug = 1
shift @ARGV
my ($dst, $ext)
my $src_list
$if $ARGV[0] eq "-"
$call install_arglist_to_PATH
$else
my $src
($src, $dst, $ext)=($ARGV[0], $ARGV[1], $ARGV[2])
$call install_src_dst_type
subcode: install_arglist_to_PATH
($dst, $ext) = (".", "-")
shift @ARGV
$src_list=[]
$foreach $a in @ARGV
$if -f $a
push @$src_list, $a
$elif -d $a
my $tlist = load_srcs_dir($a,"-")
push @$src_list, @$tlist
$else
warn "[$a] not found\n"
$if $a=~/\{.*\}/
warn " note: {*} expansion may not work in your shell, try bash.\n"
subcode: install_src_dst_type
$if !$ext
$ext = "def"
$if -d $src
$src_list = load_srcs_dir($src, $ext)
$else
die "Not a directory [$src]\n"
#----------------------------------------
fncode: load_srcs_dir($dir, $ext)
$if $dir ne "."
chdir $dir or die "Can't chdir $dir\n";
my @files=glob("*");
my @srcs;
my @dirs;
$foreach $f in @files
$if -d $f
push @dirs, $f;
$elif $ext eq "-"
push @srcs, $f;
$elif $f=~/\.$ext$/
push @srcs, $f;
$call load_dirs
return \@srcs
# ---- load a single level of dirs ----
subcode: load_dirs
$foreach $d in @dirs
$if -f "$d/skip"
next
my $pat = "$d/*.$ext"
$if $ext eq "-"
$pat = "$d/*"
my @files=glob($pat);
$if @files
$foreach $f in @files
push @srcs, $f;
#----------------------------------------------
fncode: install_all($src_list, $install_dir, $ext)
$call check_exist, $install_dir
my @cmds
$if $ext eq "-"
&call load_cmds, install -m555
my $t=$src
$t=~s/^.*\///
my $dst = "$install_dir/$t"
$else
&call load_cmds, install -m644
$if $src=~/(.*)\//
$call check_exist, $install_dir/$1
my $dst="$install_dir/$src"
$if @cmds
$print install_all: $install_dir [$ext]
$foreach $cmd in @cmds
$print " :| $cmd"
system $cmd
subcode: load_cmds(install)
$foreach $src in @$src_list
BLOCK
$if !-e $dst or $b_force or (-M $src < -M $dst)
push @cmds, "$(install) $src $dst"
subcode: check_exist(d)
$if !-d "$(d)"
mkdir "$(d)" or die "Can't mkdir $(d)"
#-----------------------------------------------
subcode: check_install_dir
my $home = $ENV{HOME}
$call @get_home2
my $install_dir
$if $dst=~/^(\/.*)/
$install_dir=$1
$dst = "."
$elif $ext eq "def"
$install_dir=$ENV{MYDEFLIB}
$install_dir=~s/:.*//
$if !$install_dir
$print "Missing environment variable MYDEFLIB\n"
$print " try put 'MYDEFLIB=\$HOME/lib/MyDef' in your .bashrc (and source it)\n"
exit
$elif $ext eq "pm"
$install_dir=$ENV{PERL5LIB}
$install_dir=~s/:.*//
$if !$install_dir
$print "Missing environment variable PERL5LIB\n"
$print " try put 'PERL5LIB=\$HOME/lib/perl5' in your .bashrc (and source it)\n"
exit
$elif $ext eq "-"
$if $ENV{MYDEFBIN}
$install_dir = $ENV{MYDEFBIN}
$else
my $homebin = "$home/bin"
$if $ENV{PATH} =~ /$homebin/
$install_dir = $homebin
$else
$install_dir=$ENV{PATH}
$install_dir=~s/:.*//
$call check_mydefbin
$if !-d $install_dir
mkdir $install_dir or die "Can't mkdir $install_dir\n";
subcode: get_home2
my $home2
$if $ENV{MYDEFLIB}=~/(.*)\/lib\/MyDef/
$home2 = $1
subcode: check_mydefbin
$if $install_dir ne "$home/bin" and $install_dir ne "$home2/bin"
$print "This will install script into your leading path: [$install_dir]"
$print " press 'y' to continute (abort otherwise)"
my $t =<STDIN>
$if $t!~/^\s*y\s*$/
undef $install_dir
$if !$install_dir
$print "Can't figure out installation dir\n"
$print " try set MYDEFBIN (and add it to your PATH)\n"
exit