]>
git.proxmox.com Git - grub2.git/blob - genmk.rb
3 # Copyright (C) 2002,2003 Yoshinori K. Okuji <okuji@enbug.org>
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')
113 "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{defsym} #{undsym}
114 MOSTLYCLEANFILES += #{deps_str}
115 DEFSYMFILES += #{defsym}
116 UNDSYMFILES += #{undsym}
118 #{@name}: #{pre_obj} #{mod_obj}
121 $(STRIP) --strip-unneeded -K pupa_mod_init -K pupa_mod_fini -R .note -R .comment $@
123 #{pre_obj}: #{objs_str}
127 #{mod_obj}: #{mod_src}
128 $(CC) $(CPPFLAGS) $(CFLAGS) $(#{prefix}_CFLAGS) -c -o $@ $<
130 #{mod_src}: moddep.lst genmodsrc.sh
131 sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)
133 #{defsym}: #{pre_obj}
134 $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
136 #{undsym}: #{pre_obj}
137 echo '#{mod_name}' > $@
138 $(NM) -u -P -p $< >> $@
140 " + objs
.collect_with_index
do |obj
, i
|
142 fake_obj
= File
.basename(src
).suffix('o')
144 flag
= if /\.c$/ =~ src
then 'CFLAGS' else 'ASFLAGS' end
145 dir
= File
.dirname(src
)
148 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(#{flag}) $(#{prefix}_#{flag}) -c -o $@ $<
152 $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(#{flag}) $(#{prefix}_#{flag}) -M $< \
153 | sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
154 [ -s $@ ] || rm -f $@
164 def initialize(dir
, name
)
168 attr_reader
:dir, :name
171 prefix
= @name.to_var
172 objs
= sources
.collect
do |src
|
173 raise "unknown source file `#{src}'" if /\.c$/ !~ src
174 prefix
+ '-' + src
.to_obj
176 objs_str
= objs
.join(' ');
177 deps
= objs
.collect
{|obj
| obj
.suffix('d')}
178 deps_str
= deps
.join(' ');
180 "CLEANFILES += #{@name} #{objs_str}
181 MOSTLYCLEANFILES += #{deps_str}
183 #{@name}: #{objs_str}
184 $(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(#{prefix}_LDFLAGS)
186 " + objs
.collect_with_index
do |obj
, i
|
188 fake_obj
= File
.basename(src
).suffix('o')
190 dir
= File
.dirname(src
)
193 $(BUILD_CC) -I#{dir} -I$(srcdir)/#{dir} $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DPUPA_UTIL=1 $(#{prefix}_CFLAGS) -c -o $@ $<
197 $(BUILD_CC) -I#{dir} -I$(srcdir)/#{dir} $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DPUPA_UTIL=1 $(#{prefix}_CFLAGS) -M $< \
198 | sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
199 [ -s $@ ] || rm -f $@
226 if /^([a-zA-Z0-9_]+)\s*=\s*(.*?)\s*$/ =~ s
229 if var
=~
/^([a-zA-Z0-9_]+)_([A-Z]+)$/
230 prefix
, type
= $1, $2
234 images
+= args
.split(/\s+/).collect
do |img
|
235 Image
.new(prefix
, img
)
239 pmodules
+= args
.split(/\s+/).collect
do |pmod
|
240 PModule
.new(prefix
, pmod
)
244 utils
+= args
.split(/\s+/).collect
do |util
|
245 Utility
.new(prefix
, util
)
249 if img
= images
.detect() {|i
| i
.name
.to_var
== prefix
}
250 print img
.rule(args
.split(/\s+/))
251 elsif pmod
= pmodules
.detect() {|m
| m
.name
.to_var
== prefix
}
252 print pmod
.rule(args
.split(/\s+/))
253 elsif util
= utils
.detect() {|u
| u
.name
.to_var
== prefix
}
254 print util
.rule(args
.split(/\s+/))
265 puts
"CLEANFILES += moddep.lst"
266 puts
"pkgdata_DATA += moddep.lst"
267 puts
"moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep"
268 puts
" cat $(DEFSYMFILES) /dev/null | ./genmoddep $(UNDSYMFILES) > $@ \\"
269 puts
" || (rm -f $@; exit 1)"