]>
git.proxmox.com Git - grub2.git/blob - genmk.rb
3 # Copyright (C) 2002,2003,2004,2005,2006 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 $(TARGET_CC) -o $@ $^ $(TARGET_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 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $<
82 # Use PModule instead Module, to avoid name conflicting.
84 def initialize(dir
, name
)
88 attr_reader
:dir, :name
92 objs
= sources
.collect
do |src
|
93 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
94 prefix
+ '-' + src
.to_obj
96 objs_str
= objs
.join(' ')
97 deps
= objs
.collect
{|obj
| obj
.suffix('d')}
98 deps_str
= deps
.join(' ')
99 pre_obj
= 'pre-' + @name.suffix('o')
100 mod_src
= 'mod-' + @name.suffix('c')
101 mod_obj
= mod_src
.suffix('o')
102 defsym
= 'def-' + @name.suffix('lst')
103 undsym
= 'und-' + @name.suffix('lst')
104 mod_name
= File
.basename(@name, '.mod')
105 symbolic_name
= mod_name
.sub(/\.[^\.]*$/, '')
107 "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym}
108 ifneq ($(#{prefix}_EXPORTS),no)
109 CLEANFILES += #{defsym}
110 DEFSYMFILES += #{defsym}
112 MOSTLYCLEANFILES += #{deps_str}
113 UNDSYMFILES += #{undsym}
115 #{@name}: #{pre_obj} #{mod_obj}
117 $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^
118 $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@
120 #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str}
122 $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ #{objs_str}
124 #{mod_obj}: #{mod_src}
125 $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(#{prefix}_CFLAGS) -c -o $@ $<
127 #{mod_src}: moddep.lst genmodsrc.sh
128 sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)
130 ifneq ($(#{prefix}_EXPORTS),no)
131 #{defsym}: #{pre_obj}
132 $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
135 #{undsym}: #{pre_obj}
136 echo '#{mod_name}' > $@
137 $(NM) -u -P -p $< | cut -f1 -d' ' >> $@
139 " + objs
.collect_with_index
do |obj
, i
|
141 fake_obj
= File
.basename(src
).suffix('o')
142 command
= 'cmd-' + obj
.suffix('lst')
143 fs
= 'fs-' + obj
.suffix('lst')
145 flag
= if /\.c$/ =~ src
then 'CFLAGS' else 'ASFLAGS' end
146 dir
= File
.dirname(src
)
149 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $<
152 CLEANFILES += #{command} #{fs}
153 COMMANDFILES += #{command}
156 #{command}: #{src} gencmdlist.sh
158 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
159 | sh $(srcdir)/gencmdlist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
161 #{fs}: #{src} genfslist.sh
163 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
164 | sh $(srcdir)/genfslist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
173 def initialize(dir
, name
)
177 attr_reader
:dir, :name
180 prefix
= @name.to_var
181 objs
= sources
.collect
do |src
|
182 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
183 prefix
+ '-' + src
.to_obj
185 objs_str
= objs
.join(' ');
186 deps
= objs
.collect
{|obj
| obj
.suffix('d')}
187 deps_str
= deps
.join(' ');
189 "CLEANFILES += #{@name} #{objs_str}
190 MOSTLYCLEANFILES += #{deps_str}
192 #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str}
193 $(CC) -o $@ #{objs_str} $(LDFLAGS) $(#{prefix}_LDFLAGS)
195 " + objs
.collect_with_index
do |obj
, i
|
197 fake_obj
= File
.basename(src
).suffix('o')
199 dir
= File
.dirname(src
)
201 "#{obj}: #{src} $(#{src}_DEPENDENCIES)
202 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -MD -c -o $@ $<
211 def initialize(dir
, name
)
215 attr_reader
:dir, :name
218 prefix
= @name.to_var
219 objs
= sources
.collect
do |src
|
220 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
221 prefix
+ '-' + src
.to_obj
223 objs_str
= objs
.join(' ');
224 deps
= objs
.collect
{|obj
| obj
.suffix('d')}
225 deps_str
= deps
.join(' ');
227 "CLEANFILES += #{@name} #{objs_str}
228 MOSTLYCLEANFILES += #{deps_str}
230 #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str}
231 $(TARGET_CC) -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS)
233 " + objs
.collect_with_index
do |obj
, i
|
235 fake_obj
= File
.basename(src
).suffix('o')
237 dir
= File
.dirname(src
)
240 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(#{prefix}_CFLAGS) -MD -c -o $@ $<
249 def initialize(dir
, name
)
253 attr_reader
:dir, :name
256 if sources
.length
!= 1
257 raise "only a single source file must be specified for a script"
261 raise "unknown source file `#{src}'"
264 "CLEANFILES += #{@name}
266 #{@name}: #{src} config.status
267 ./config.status --file=#{name}:#{src}
294 if /^([a-zA-Z0-9_]+)\s*\+?=\s*(.*?)\s*$/ =~ s
297 if var
=~
/^([a-zA-Z0-9_]+)_([A-Z]+)$/
298 prefix
, type
= $1, $2
302 images
+= args
.split(/\s+/).collect
do |img
|
303 Image
.new(prefix
, img
)
307 pmodules
+= args
.split(/\s+/).collect
do |pmod
|
308 PModule
.new(prefix
, pmod
)
312 utils
+= args
.split(/\s+/).collect
do |util
|
313 Utility
.new(prefix
, util
)
317 programs
+= args
.split(/\s+/).collect
do |prog
|
318 Program
.new(prefix
, prog
)
322 scripts
+= args
.split(/\s+/).collect
do |script
|
323 Script
.new(prefix
, script
)
327 if img
= images
.detect() {|i
| i
.name
.to_var
== prefix
}
328 print img
.rule(args
.split(/\s+/))
329 elsif pmod
= pmodules
.detect() {|m
| m
.name
.to_var
== prefix
}
330 print pmod
.rule(args
.split(/\s+/))
331 elsif util
= utils
.detect() {|u
| u
.name
.to_var
== prefix
}
332 print util
.rule(args
.split(/\s+/))
333 elsif program
= programs
.detect() {|u
| u
.name
.to_var
== prefix
}
334 print program
.rule(args
.split(/\s+/))
335 elsif script
= scripts
.detect() {|s
| s
.name
.to_var
== prefix
}
336 print script
.rule(args
.split(/\s+/))