3 # Copyright (C) 2002,2003,2004,2005,2006,2007 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)
73 "#{obj}: #{src} $(#{src}_DEPENDENCIES)
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 extra_flags = if /\.S$/ =~ src then '-DASM_FILE=1' else '' end
147 dir = File.dirname(src)
149 "#{obj}: #{src} $(#{src}_DEPENDENCIES)
150 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $<
153 CLEANFILES += #{command} #{fs}
154 COMMANDFILES += #{command}
157 #{command}: #{src} $(#{src}_DEPENDENCIES) gencmdlist.sh
159 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
160 | sh $(srcdir)/gencmdlist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
162 #{fs}: #{src} $(#{src}_DEPENDENCIES) genfslist.sh
164 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
165 | sh $(srcdir)/genfslist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
174 def initialize(dir, name)
178 attr_reader :dir, :name
181 prefix = @name.to_var
182 objs = sources.collect do |src|
183 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
184 prefix + '-' + src.to_obj
186 objs_str = objs.join(' ');
187 deps = objs.collect {|obj| obj.suffix('d')}
188 deps_str = deps.join(' ');
190 "CLEANFILES += #{@name} #{objs_str}
191 MOSTLYCLEANFILES += #{deps_str}
193 #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str}
194 $(CC) -o $@ #{objs_str} $(LDFLAGS) $(#{prefix}_LDFLAGS)
196 " + objs.collect_with_index do |obj, i|
198 fake_obj = File.basename(src).suffix('o')
200 dir = File.dirname(src)
202 "#{obj}: #{src} $(#{src}_DEPENDENCIES)
203 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -MD -c -o $@ $<
212 def initialize(dir, name)
216 attr_reader :dir, :name
219 prefix = @name.to_var
220 objs = sources.collect do |src|
221 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
222 prefix + '-' + src.to_obj
224 objs_str = objs.join(' ');
225 deps = objs.collect {|obj| obj.suffix('d')}
226 deps_str = deps.join(' ');
228 "CLEANFILES += #{@name} #{objs_str}
229 MOSTLYCLEANFILES += #{deps_str}
231 #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str}
232 $(TARGET_CC) -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS)
234 " + objs.collect_with_index do |obj, i|
236 fake_obj = File.basename(src).suffix('o')
238 dir = File.dirname(src)
240 "#{obj}: #{src} $(#{src}_DEPENDENCIES)
241 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(#{prefix}_CFLAGS) -MD -c -o $@ $<
250 def initialize(dir, name)
254 attr_reader :dir, :name
257 if sources.length != 1
258 raise "only a single source file must be specified for a script"
262 raise "unknown source file `#{src}'"
265 "CLEANFILES += #{@name}
267 #{@name}: #{src} $(#{src}_DEPENDENCIES) config.status
268 ./config.status --file=#{name}:#{src}
295 if /^([a-zA-Z0-9_]+)\s*\+?=\s*(.*?)\s*$/ =~ s
298 if var =~ /^([a-zA-Z0-9_]+)_([A-Z]+)$/
299 prefix, type = $1, $2
303 images += args.split(/\s+/).collect do |img|
304 Image.new(prefix, img)
308 pmodules += args.split(/\s+/).collect do |pmod|
309 PModule.new(prefix, pmod)
313 utils += args.split(/\s+/).collect do |util|
314 Utility.new(prefix, util)
318 programs += args.split(/\s+/).collect do |prog|
319 Program.new(prefix, prog)
323 scripts += args.split(/\s+/).collect do |script|
324 Script.new(prefix, script)
328 if img = images.detect() {|i| i.name.to_var == prefix}
329 print img.rule(args.split(/\s+/))
330 elsif pmod = pmodules.detect() {|m| m.name.to_var == prefix}
331 print pmod.rule(args.split(/\s+/))
332 elsif util = utils.detect() {|u| u.name.to_var == prefix}
333 print util.rule(args.split(/\s+/))
334 elsif program = programs.detect() {|u| u.name.to_var == prefix}
335 print program.rule(args.split(/\s+/))
336 elsif script = scripts.detect() {|s| s.name.to_var == prefix}
337 print script.rule(args.split(/\s+/))