1 | #!/usr/bin/perl
|
---|
2 | # debbuild script
|
---|
3 | # Shamlessly steals intreface from rpm's "rpmbuild" to create
|
---|
4 | # Debian packages. Please note that such packages are highly
|
---|
5 | # unlikely to conform to "Debian Policy".
|
---|
6 | ###
|
---|
7 | # SVN revision info
|
---|
8 | # $Date: 2005-10-25 20:59:09 +0000 (Tue, 25 Oct 2005) $
|
---|
9 | # SVN revision $Rev: 4 $
|
---|
10 | # Last update by $Author: kdeugau $
|
---|
11 | ###
|
---|
12 |
|
---|
13 | # Program flow:
|
---|
14 | # -> Parse/execute "system" config/macros (if any - should be rare)
|
---|
15 | # -> Parse/execute "user" config/macros (if any - *my* requirement is %_topdir)
|
---|
16 | # -> Parse command line for options, spec file/tarball/.src.deb (NB - also accept .src.rpm)
|
---|
17 |
|
---|
18 | # User's prefs for dirs, environment, etc,etc,etc.
|
---|
19 | # config file ~/.debmacros
|
---|
20 | # Default ordered search paths for config/macros:
|
---|
21 | # /usr/lib/rpm/rpmrc /usr/lib/rpm/redhat/rpmrc /etc/rpmrc ~/.rpmrc
|
---|
22 | # /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros
|
---|
23 | # **NOTE: May be possible to (ab)use bits of debhelper
|
---|
24 |
|
---|
25 | # Build tree
|
---|
26 | # default is /usr/src/debian/{BUILD,SOURCES,SPECS,DEBS,SDEBS}
|
---|
27 |
|
---|
28 | # Globals
|
---|
29 | my $specfile;
|
---|
30 | my $tarball;
|
---|
31 | my $srcpkg;
|
---|
32 | my $verbosity = 0;
|
---|
33 | my %cmdopts = (type => '',
|
---|
34 | stage => 'a',
|
---|
35 | short => 'n'
|
---|
36 | );
|
---|
37 | my %targets = ('p' => 'Prep',
|
---|
38 | 'c' => 'Compile',
|
---|
39 | 'i' => 'Install',
|
---|
40 | 'l' => 'Verify %files',
|
---|
41 | 'a' => 'Build binary and source',
|
---|
42 | 'b' => 'Build binary',
|
---|
43 | 's' => 'Build source'
|
---|
44 | );
|
---|
45 | my $topdir = "/usr/src/debian";
|
---|
46 |
|
---|
47 | load_userconfig();
|
---|
48 | parse_cmd();
|
---|
49 |
|
---|
50 | # Hokay. Need to:
|
---|
51 | # Execute prep if *not* --short-circuit
|
---|
52 | prep() if ($cmdopts{short} ne 'y');
|
---|
53 |
|
---|
54 | if ($cmdopts{stage} =~ /ciab/) {
|
---|
55 | # Execute build if bc
|
---|
56 | # Execute build if bi, ba, bb and NOT --short-circuit
|
---|
57 | build() if ( ($cmdopts{stage} eq 'c') ||
|
---|
58 | (($cmdopts{stage} =~ /iab/) && ($cmdopts{short} ne 'y'))
|
---|
59 | );
|
---|
60 |
|
---|
61 | # -> Execute
|
---|
62 | install() if ($cmdopts{short} ne 'y');
|
---|
63 | binpackage();
|
---|
64 | }
|
---|
65 |
|
---|
66 | srcpackage();
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 | # Just in case.
|
---|
71 | exit 0;
|
---|
72 |
|
---|
73 |
|
---|
74 | ## load_userconfig()
|
---|
75 | # Loads user configuration (if any)
|
---|
76 | # Currently only handles .debmacros
|
---|
77 | # Needs to handle "other files"
|
---|
78 | sub load_userconfig {
|
---|
79 | (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
|
---|
80 | if (-e "$homedir/.debmacros") {
|
---|
81 | open USERMACROS,"<$homedir/.debmacros";
|
---|
82 | while (<USERMACROS>) {
|
---|
83 | # And we also only handle the %_topdir macro at the moment.
|
---|
84 | if (/^\%_topdir/) {
|
---|
85 | (undef,$tmp) = split /\s+/, $_;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | } # end load_userconfig()
|
---|
90 |
|
---|
91 |
|
---|
92 | ## parse_cmd()
|
---|
93 | # Parses command line into global hash %cmdopts, other globals
|
---|
94 | # Options based on rpmbuild's options
|
---|
95 | sub parse_cmd {
|
---|
96 | # Don't feel like coding my own option parser...
|
---|
97 | #use Getopt::Long;
|
---|
98 | # ... but I may have to: (OTOH, rpm uses popt, so maybe we can too.)
|
---|
99 | #use Getopt::Popt qw(:all);
|
---|
100 | # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
|
---|
101 |
|
---|
102 | # Stuff it.
|
---|
103 | my $prevopt = '';
|
---|
104 | foreach (@ARGV) {
|
---|
105 | chomp;
|
---|
106 | $prevopt = $_;
|
---|
107 | # Is it an option?
|
---|
108 | if (/^-/) {
|
---|
109 | # Is it a long option?
|
---|
110 | if (/^--/) {
|
---|
111 | if (/^--short-circuit/) {
|
---|
112 | $cmdopts{short} = 'y';
|
---|
113 | } else {
|
---|
114 | print "Long opt $_\n";
|
---|
115 | }
|
---|
116 | } else {
|
---|
117 | if (/^-[bts]/) {
|
---|
118 | ($cmdopts{stage}) = (/^-[bts]([pcilabs])/);
|
---|
119 | ($cmdopts{type}) = (/^-([bts])[pcilabs]/);
|
---|
120 | } elsif (/^-v/) {
|
---|
121 | # bump verbosity. Not sure what I'll actually do here...
|
---|
122 | } else {
|
---|
123 | die "Bad option $_\n";
|
---|
124 | }
|
---|
125 | }
|
---|
126 | } else {
|
---|
127 | print "Non-option arg $_\n";
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | # Some cross-checks. rpmbuild limits --short-circuit to just
|
---|
132 | # the "compile" and "install" targets - with good reason IMO.
|
---|
133 | # NB - this is NOT fatal, just ignored!
|
---|
134 | if ($cmdopts{short} eq 'y') {
|
---|
135 | warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
|
---|
136 | $cmdopts{short} = 'n';
|
---|
137 | }
|
---|
138 | # Valid options, with example arguments (if any):
|
---|
139 | # Build from .spec file; mutually exclusive:
|
---|
140 | # -bp
|
---|
141 | # -bc
|
---|
142 | # -bi
|
---|
143 | # -bl
|
---|
144 | # -ba
|
---|
145 | # -bb
|
---|
146 | # -bs
|
---|
147 | # Build from tarball; mutually exclusive:
|
---|
148 | # -tp
|
---|
149 | # -tc
|
---|
150 | # -ti
|
---|
151 | # -ta
|
---|
152 | # -tb
|
---|
153 | # -ts
|
---|
154 | # Build from .src.(deb|rpm)
|
---|
155 | # --rebuild
|
---|
156 | # --recompile
|
---|
157 |
|
---|
158 | # General options
|
---|
159 | # --buildroot=DIRECTORY
|
---|
160 | # --clean
|
---|
161 | # --nobuild
|
---|
162 | # --nodeps
|
---|
163 | # --nodirtokens
|
---|
164 | # --rmsource
|
---|
165 | # --rmspec
|
---|
166 | # --short-circuit
|
---|
167 | # --target=CPU-VENDOR-OS
|
---|
168 |
|
---|
169 | #my $popt = new Getopt::Popt(argv => \@ARGV, options => \@optionsTable);
|
---|
170 |
|
---|
171 | } # end parse_cmd()
|
---|
172 |
|
---|
173 |
|
---|
174 | ## prep()
|
---|
175 | # Unpacks the tarball from the SOURCES directory to the BUILD directory.
|
---|
176 | # Speaks gzip and bzip2.
|
---|
177 | # Requires the "package name"
|
---|
178 | # Finishes by applying patches in %prep section of spec file
|
---|
179 | sub prep {
|
---|
180 | my $pkgname = shift;
|
---|
181 |
|
---|
182 | } # end prep()
|
---|
183 |
|
---|
184 |
|
---|
185 | sub build {}
|
---|
186 | sub install {}
|
---|
187 | sub binpackage {}
|
---|
188 | sub srcpackage {}
|
---|