summaryrefslogtreecommitdiff
path: root/Tools/scripts/plist
blob: e8da00258c5c5708ffa12142f1f8e7f12453510d (plain) (blame)
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
#!/usr/local/bin/ruby
class Plist
	def initialize(no_manpages = true, excl = nil)
		@no_manpages = no_manpages
		self.excludes = excl
		self
	end
	def excludes
		@excludes.dup
	end
	def excludes=(excl)
		if !excl
			@excludes = [
				/^(bin|etc|include|info|lib|libexec|man|sbin|share)$/,
				'etc/rc.d',
				/^lib\/perl5?(\/.*site_perl\/[[:digit:]]\.[[:digit:]]+)?$/,
				/^lib\/xemacs(\/site-lisp)?$/,
				/^man\//,
				/^share\/(dict|doc|emacs|emacs\/site-lisp|examples|misc|skel)$/,
				/^share\/nls($|\/)/
			]
		else
			@excludes = excl.to_a
		end
		
	end
	def make(dir)
		@root = dir.to_s + '/'
		imake('', 0, '')
	end
	private
	def imake(dir, level, prevwd)
		thiswd = prevwd + dir				# always ends in '/'
		rootedwd = @root + thiswd
		subs = []
		Dir.foreach(rootedwd) {|dirent|
			next if dirent =~ /^\.\.?$/
			if test(?d, rootedwd + dirent)
				subs.concat(imake(dirent + '/', level + 1, thiswd))
			else
				if thiswd !~ /^man\// || !@no_manpages
						subs.push(thiswd + dirent)
				end
			end
		}
		thiswd.chop!
		if level > 0 && !@excludes.find {|x| x === thiswd}
			subs.push('@dirrm ' + thiswd)
		end
		return subs
	end
end

if __FILE__ == $0
	if ARGV.size != 1
		$stderr.print <<-USAGE_EOF
usage: #{$0} somepath
       Generate a pkg-plist to stdout given a previously empty somepath which
       a port has been installed into (PREFIX=somepath).
USAGE_EOF
		exit 1
	end
	puts Plist.new.make(ARGV[0]).join("\n")
end