]>
git.proxmox.com Git - grub2.git/blob - genmk.rb
3 # Copyright (C) 2002,2003,2004,2005 Free Software Foundation, Inc.
5 # This genmk.rb is free software; the author
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
11 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 def collect_with_index
17 self.each_with_index
do |item
, index
|
18 ret
.push(yield(item
, index
))
26 self.gsub(/[^a-zA-Z0-9_@]/, '_')
30 self.sub(/\.[^\.]*$/, '') + '.' + str
34 self.sub(/\.[^\.]*$/, '').to_var
+ '.o'
39 def initialize(dir
, name
)
43 attr_reader
:dir, :name
47 exe
= @name.suffix('exec')
48 objs
= sources
.collect
do |src
|
49 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
50 prefix
+ '-' + src
.to_obj
52 objs_str
= objs
.join(' ')
53 deps
= objs
.collect
{|obj
| obj
.suffix('d')}
54 deps_str
= deps
.join(' ')
56 "CLEANFILES += #{@name} #{exe} #{objs_str}
57 MOSTLYCLEANFILES += #{deps_str}
60 $(OBJCOPY) -O binary -R .note -R .comment $< $@
63 $(CC) -o $@ $^ $(LDFLAGS) $(#{prefix}_LDFLAGS)
65 " + objs
.collect_with_index
do |obj
, i
|
67 fake_obj
= File
.basename(src
).suffix('o')
69 flag
= if /\.c$/ =~ src
then 'CFLAGS' else 'ASFLAGS' end
70 extra_flags
= if /\.S$/ =~ src
then '-DASM_FILE=1' else '' end
71 dir
= File
.dirname(src
)
74 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) #{extra_flags} $(#{flag}) $(#{prefix}_#{flag}) -c -o $@ $<
78 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) #{extra_flags} $(#{flag}) $(#{prefix}_#{flag}) -M $< \
79 | sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
89 # Use PModule instead Module, to avoid name conflicting.
91 def initialize(dir
, name
)
95 attr_reader
:dir, :name
99 objs
= sources
.collect
do |src
|
100 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
101 prefix
+ '-' + src
.to_obj
103 objs_str
= objs
.join(' ')
104 deps
= objs
.collect
{|obj
| obj
.suffix('d')}
105 deps_str
= deps
.join(' ')
106 pre_obj
= 'pre-' + @name.suffix('o')
107 mod_src
= 'mod-' + @name.suffix('c')
108 mod_obj
= mod_src
.suffix('o')
109 defsym
= 'def-' + @name.suffix('lst')
110 undsym
= 'und-' + @name.suffix('lst')
111 mod_name
= File
.basename(@name, '.mod')
112 symbolic_name
= mod_name
.sub(/\.[^\.]*$/, '')
114 "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{defsym} #{undsym}
115 MOSTLYCLEANFILES += #{deps_str}
116 DEFSYMFILES += #{defsym}
117 UNDSYMFILES += #{undsym}
119 #{@name}: #{pre_obj} #{mod_obj}
121 $(LD) $(#{prefix}_LDFLAGS) $(LDFLAGS) -r -d -o $@ $^
122 $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@
124 #{pre_obj}: #{objs_str}
126 $(LD) $(#{prefix}_LDFLAGS) -r -d -o $@ $^
128 #{mod_obj}: #{mod_src}
129 $(CC) $(CPPFLAGS) $(CFLAGS) $(#{prefix}_CFLAGS) -c -o $@ $<
131 #{mod_src}: moddep.lst genmodsrc.sh
132 sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)
134 #{defsym}: #{pre_obj}
135 $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
137 #{undsym}: #{pre_obj}
138 echo '#{mod_name}' > $@
139 $(NM) -u -P -p $< | cut -f1 -d' ' >> $@
141 " + objs
.collect_with_index
do |obj
, i
|
143 fake_obj
= File
.basename(src
).suffix('o')
144 command
= 'cmd-' + obj
.suffix('lst')
145 fs
= 'fs-' + obj
.suffix('lst')
147 flag
= if /\.c$/ =~ src
then 'CFLAGS' else 'ASFLAGS' end
148 dir
= File
.dirname(src
)
151 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(#{flag}) $(#{prefix}_#{flag}) -c -o $@ $<
155 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(#{flag}) $(#{prefix}_#{flag}) -M $< \
156 | sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
157 [ -s $@ ] || rm -f $@
161 CLEANFILES += #{command} #{fs}
162 COMMANDFILES += #{command}
165 #{command}: #{src} gencmdlist.sh
167 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(#{flag}) $(#{prefix}_#{flag}) -E $< \
168 | sh $(srcdir)/gencmdlist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
170 #{fs}: #{src} genfslist.sh
172 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(#{flag}) $(#{prefix}_#{flag}) -E $< \
173 | sh $(srcdir)/genfslist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
182 def initialize(dir
, name
)
186 attr_reader
:dir, :name
189 prefix
= @name.to_var
190 objs
= sources
.collect
do |src
|
191 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
192 prefix
+ '-' + src
.to_obj
194 objs_str
= objs
.join(' ');
195 deps
= objs
.collect
{|obj
| obj
.suffix('d')}
196 deps_str
= deps
.join(' ');
198 "CLEANFILES += #{@name} #{objs_str}
199 MOSTLYCLEANFILES += #{deps_str}
201 #{@name}: #{objs_str}
202 $(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(#{prefix}_LDFLAGS)
204 " + objs
.collect_with_index
do |obj
, i
|
206 fake_obj
= File
.basename(src
).suffix('o')
208 dir
= File
.dirname(src
)
211 $(BUILD_CC) -I#{dir} -I$(srcdir)/#{dir} $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -c -o $@ $<
215 $(BUILD_CC) -I#{dir} -I$(srcdir)/#{dir} $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -M $< \
216 | sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
217 [ -s $@ ] || rm -f $@
227 def initialize(dir
, name
)
231 attr_reader
:dir, :name
234 prefix
= @name.to_var
235 objs
= sources
.collect
do |src
|
236 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
237 prefix
+ '-' + src
.to_obj
239 objs_str
= objs
.join(' ');
240 deps
= objs
.collect
{|obj
| obj
.suffix('d')}
241 deps_str
= deps
.join(' ');
243 "CLEANFILES += #{@name} #{objs_str}
244 MOSTLYCLEANFILES += #{deps_str}
246 #{@name}: #{objs_str}
247 $(CC) -o $@ $^ $(LDFLAGS) $(#{prefix}_LDFLAGS)
249 " + objs
.collect_with_index
do |obj
, i
|
251 fake_obj
= File
.basename(src
).suffix('o')
253 dir
= File
.dirname(src
)
256 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) $(#{prefix}_CFLAGS) -c -o $@ $<
260 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) $(#{prefix}_CFLAGS) -M $< \
261 | sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
262 [ -s $@ ] || rm -f $@
272 def initialize(dir
, name
)
276 attr_reader
:dir, :name
279 if sources
.length
!= 1
280 raise "only a single source file must be specified for a script"
284 raise "unknown source file `#{src}'"
287 "CLEANFILES += #{@name}
289 #{@name}: #{src} config.status
290 ./config.status --file=#{name}:#{src}
317 if /^([a-zA-Z0-9_]+)\s*\+?=\s*(.*?)\s*$/ =~ s
320 if var
=~
/^([a-zA-Z0-9_]+)_([A-Z]+)$/
321 prefix
, type
= $1, $2
325 images
+= args
.split(/\s+/).collect
do |img
|
326 Image
.new(prefix
, img
)
330 pmodules
+= args
.split(/\s+/).collect
do |pmod
|
331 PModule
.new(prefix
, pmod
)
335 utils
+= args
.split(/\s+/).collect
do |util
|
336 Utility
.new(prefix
, util
)
340 programs
+= args
.split(/\s+/).collect
do |prog
|
341 Program
.new(prefix
, prog
)
345 scripts
+= args
.split(/\s+/).collect
do |script
|
346 Script
.new(prefix
, script
)
350 if img
= images
.detect() {|i
| i
.name
.to_var
== prefix
}
351 print img
.rule(args
.split(/\s+/))
352 elsif pmod
= pmodules
.detect() {|m
| m
.name
.to_var
== prefix
}
353 print pmod
.rule(args
.split(/\s+/))
354 elsif util
= utils
.detect() {|u
| u
.name
.to_var
== prefix
}
355 print util
.rule(args
.split(/\s+/))
356 elsif program
= programs
.detect() {|u
| u
.name
.to_var
== prefix
}
357 print program
.rule(args
.split(/\s+/))
358 elsif script
= scripts
.detect() {|s
| s
.name
.to_var
== prefix
}
359 print script
.rule(args
.split(/\s+/))