3 # Copyright (C) 2002,2003,2004,2005,2006,2007,2008 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 -R .note.gnu.build-id $< $@
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) $(MODULE_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')
144 partmap = 'partmap-' + obj.suffix('lst')
146 flag = if /\.c$/ =~ src then 'CFLAGS' else 'ASFLAGS' end
147 extra_flags = if /\.S$/ =~ src then '-DASM_FILE=1' else '' end
148 dir = File.dirname(src)
150 "#{obj}: #{src} $(#{src}_DEPENDENCIES)
151 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $<
154 CLEANFILES += #{command} #{fs} #{partmap}
155 COMMANDFILES += #{command}
157 PARTMAPFILES += #{partmap}
159 #{command}: #{src} $(#{src}_DEPENDENCIES) gencmdlist.sh
161 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
162 | sh $(srcdir)/gencmdlist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
164 #{fs}: #{src} $(#{src}_DEPENDENCIES) genfslist.sh
166 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
167 | sh $(srcdir)/genfslist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
169 #{partmap}: #{src} $(#{src}_DEPENDENCIES) genpartmaplist.sh
171 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
172 | sh $(srcdir)/genpartmaplist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
181 def initialize(dir, name)
185 attr_reader :dir, :name
188 prefix = @name.to_var
189 objs = sources.collect do |src|
190 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
191 prefix + '-' + src.to_obj
193 objs_str = objs.join(' ');
194 deps = objs.collect {|obj| obj.suffix('d')}
195 deps_str = deps.join(' ');
197 "CLEANFILES += #{@name} #{objs_str}
198 MOSTLYCLEANFILES += #{deps_str}
200 #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str}
201 $(CC) -o $@ #{objs_str} $(LDFLAGS) $(#{prefix}_LDFLAGS)
203 " + objs.collect_with_index do |obj, i|
205 fake_obj = File.basename(src).suffix('o')
207 dir = File.dirname(src)
209 "#{obj}: #{src} $(#{src}_DEPENDENCIES)
210 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -MD -c -o $@ $<
219 def initialize(dir, name)
223 attr_reader :dir, :name
226 prefix = @name.to_var
227 objs = sources.collect do |src|
228 raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
229 prefix + '-' + src.to_obj
231 objs_str = objs.join(' ');
232 deps = objs.collect {|obj| obj.suffix('d')}
233 deps_str = deps.join(' ');
235 "CLEANFILES += #{@name} #{objs_str}
236 MOSTLYCLEANFILES += #{deps_str}
238 #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str}
239 $(TARGET_CC) -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS)
241 " + objs.collect_with_index do |obj, i|
243 fake_obj = File.basename(src).suffix('o')
245 dir = File.dirname(src)
247 "#{obj}: #{src} $(#{src}_DEPENDENCIES)
248 $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(#{prefix}_CFLAGS) -MD -c -o $@ $<
257 def initialize(dir, name)
261 attr_reader :dir, :name
264 if sources.length != 1
265 raise "only a single source file must be specified for a script"
269 raise "unknown source file `#{src}'"
272 "CLEANFILES += #{@name}
274 #{@name}: #{src} $(#{src}_DEPENDENCIES) config.status
275 ./config.status --file=#{name}:#{src}
302 if /^([a-zA-Z0-9_]+)\s*\+?=\s*(.*?)\s*$/ =~ s
305 if var =~ /^([a-zA-Z0-9_]+)_([A-Z]+)$/
306 prefix, type = $1, $2
310 images += args.split(/\s+/).collect do |img|
311 Image.new(prefix, img)
315 pmodules += args.split(/\s+/).collect do |pmod|
316 PModule.new(prefix, pmod)
320 utils += args.split(/\s+/).collect do |util|
321 Utility.new(prefix, util)
325 programs += args.split(/\s+/).collect do |prog|
326 Program.new(prefix, prog)
330 scripts += args.split(/\s+/).collect do |script|
331 Script.new(prefix, script)
335 if img = images.detect() {|i| i.name.to_var == prefix}
336 print img.rule(args.split(/\s+/))
337 elsif pmod = pmodules.detect() {|m| m.name.to_var == prefix}
338 print pmod.rule(args.split(/\s+/))
339 elsif util = utils.detect() {|u| u.name.to_var == prefix}
340 print util.rule(args.split(/\s+/))
341 elsif program = programs.detect() {|u| u.name.to_var == prefix}
342 print program.rule(args.split(/\s+/))
343 elsif script = scripts.detect() {|s| s.name.to_var == prefix}
344 print script.rule(args.split(/\s+/))