grub/genmk.rb

270 lines
6.5 KiB
Ruby
Raw Normal View History

2002-12-27 08:53:07 +00:00
#! /usr/bin/ruby -w
#
shinori K. Okuji <okuji@enbug.org> * genkernsyms.sh: Updated copyright information. * genmk.rb: Likewise. * genmodsrc.sh: Likewise. * gensymlist.sh: Likewise. * boot/i386/pc/boot.S: Likewise. * boot/i386/pc/diskboot.S: Likewise. * disk/i386/pc/biosdisk.c: Likewise. * disk/i386/pc/partition.c: Likewise. * font/manager.c: Likewise. * fs/ext2.c: Likewise. * fs/fat.c: Likewise. * include/pupa/boot.h: Likewise. * include/pupa/device.h: Likewise. * include/pupa/disk.h: Likewise. * include/pupa/dl.h: Likewise. * include/pupa/elf.h: Likewise. * include/pupa/err.h: Likewise. * include/pupa/file.h: Likewise. * include/pupa/font.h: Likewise. * include/pupa/fs.h: Likewise. * include/pupa/kernel.h: Likewise. * include/pupa/loader.h: Likewise. * include/pupa/misc.h: Likewise. * include/pupa/mm.h: Likewise. * include/pupa/net.h: Likewise. * include/pupa/normal.h: Likewise. * include/pupa/rescue.h: Likewise. * include/pupa/setjmp.h: Likewise. * include/pupa/symbol.h: Likewise. * include/pupa/term.h: Likewise. * include/pupa/types.h: Likewise. * include/pupa/i386/setjmp.h: Likewise. * include/pupa/i386/types.h: Likewise. * include/pupa/i386/pc/biosdisk.h: Likewise. * include/pupa/i386/pc/boot.h: Likewise. * include/pupa/i386/pc/console.h: Likewise. * include/pupa/i386/pc/init.h: Likewise. * include/pupa/i386/pc/kernel.h: Likewise. * include/pupa/i386/pc/linux.h: Likewise. * include/pupa/i386/pc/loader.h: Likewise. * include/pupa/i386/pc/memory.h: Likewise. * include/pupa/i386/pc/multiboot.h: Likewise. * include/pupa/i386/pc/partition.h: Likewise. * include/pupa/i386/pc/time.h: Likewise. * include/pupa/i386/pc/vga.h: Likewise. * include/pupa/i386/pc/util/biosdisk.h: Likewise. * include/pupa/util/getroot.h: Likewise. * include/pupa/util/misc.h: Likewise. * include/pupa/util/resolve.h: Likewise. * kern/device.c: Likewise. * kern/disk.c: Likewise. * kern/dl.c: Likewise. * kern/err.c: Likewise. * kern/file.c: Likewise. * kern/fs.c: Likewise. * kern/loader.c: Likewise. * kern/main.c: Likewise. * kern/misc.c: Likewise. * kern/mm.c: Likewise. * kern/rescue.c: Likewise. * kern/term.c: Likewise. * kern/i386/dl.c: Likewise. * kern/i386/pc/init.c: Likewise. * kern/i386/pc/lzo1x.S: Likewise. * kern/i386/pc/startup.S: Likewise. * loader/i386/pc/chainloader.c: Likewise. * loader/i386/pc/linux.c: Likewise. * loader/i386/pc/multiboot.c: Likewise. * normal/cmdline.c: Likewise. * normal/command.c: Likewise. * normal/main.c: Likewise. * normal/menu.c: Likewise. * normal/i386/setjmp.S: Likewise. * term/i386/pc/console.c: Likewise. * term/i386/pc/vga.c: Likewise. * util/console.c: Likewise. * util/genmoddep.c: Likewise. * util/misc.c: Likewise. * util/pupa-emu.c: Likewise. * util/resolve.c: Likewise. * util/unifont2pff.rb: Likewise. * util/i386/pc/biosdisk.c: Likewise. * util/i386/pc/getroot.c: Likewise. * util/i386/pc/pupa-mkimage.c: Likewise. * util/i386/pc/pupa-setup.c: Likewise.
2004-02-24 17:21:53 +00:00
# Copyright (C) 2002,2003 Free Software Foundation, Inc.
2002-12-27 08:53:07 +00:00
#
# This genmk.rb is free software; the author
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
module Enumerable
def collect_with_index
ret = []
self.each_with_index do |item, index|
ret.push(yield(item, index))
end
ret
end
end
class String
def to_var
self.gsub(/[^a-zA-Z0-9_@]/, '_')
end
def suffix(str)
self.sub(/\.[^\.]*$/, '') + '.' + str
end
def to_obj
self.sub(/\.[^\.]*$/, '').to_var + '.o'
end
end
class Image
def initialize(dir, name)
@dir = dir
@name = name
end
attr_reader :dir, :name
def rule(sources)
prefix = @name.to_var
exe = @name.suffix('exec')
objs = sources.collect do |src|
raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
prefix + '-' + src.to_obj
end
objs_str = objs.join(' ')
deps = objs.collect {|obj| obj.suffix('d')}
deps_str = deps.join(' ')
"CLEANFILES += #{@name} #{exe} #{objs_str}
MOSTLYCLEANFILES += #{deps_str}
#{@name}: #{exe}
$(OBJCOPY) -O binary -R .note -R .comment $< $@
#{exe}: #{objs_str}
$(CC) -o $@ $^ $(LDFLAGS) $(#{prefix}_LDFLAGS)
2002-12-27 08:53:07 +00:00
" + objs.collect_with_index do |obj, i|
src = sources[i]
fake_obj = File.basename(src).suffix('o')
dep = deps[i]
flag = if /\.c$/ =~ src then 'CFLAGS' else 'ASFLAGS' end
extra_flags = if /\.S$/ =~ src then '-DASM_FILE=1' else '' end
dir = File.dirname(src)
"#{obj}: #{src}
$(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) #{extra_flags} $(#{flag}) $(#{prefix}_#{flag}) -c -o $@ $<
#{dep}: #{src}
set -e; \
$(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) #{extra_flags} $(#{flag}) $(#{prefix}_#{flag}) -M $< \
| sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
[ -s $@ ] || rm -f $@
-include #{dep}
"
end.join('')
end
end
# Use PModule instead Module, to avoid name conflicting.
class PModule
def initialize(dir, name)
@dir = dir
@name = name
end
attr_reader :dir, :name
def rule(sources)
prefix = @name.to_var
objs = sources.collect do |src|
raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
prefix + '-' + src.to_obj
end
objs_str = objs.join(' ')
deps = objs.collect {|obj| obj.suffix('d')}
deps_str = deps.join(' ')
pre_obj = 'pre-' + @name.suffix('o')
mod_src = 'mod-' + @name.suffix('c')
mod_obj = mod_src.suffix('o')
defsym = 'def-' + @name.suffix('lst')
undsym = 'und-' + @name.suffix('lst')
mod_name = File.basename(@name, '.mod')
"CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{defsym} #{undsym}
MOSTLYCLEANFILES += #{deps_str}
DEFSYMFILES += #{defsym}
UNDSYMFILES += #{undsym}
#{@name}: #{pre_obj} #{mod_obj}
-rm -f $@
$(LD) -r -o $@ $^
$(STRIP) --strip-unneeded -K pupa_mod_init -K pupa_mod_fini -R .note -R .comment $@
#{pre_obj}: #{objs_str}
-rm -f $@
$(LD) -r -o $@ $^
#{mod_obj}: #{mod_src}
$(CC) $(CPPFLAGS) $(CFLAGS) $(#{prefix}_CFLAGS) -c -o $@ $<
2002-12-27 08:53:07 +00:00
#{mod_src}: moddep.lst genmodsrc.sh
sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)
#{defsym}: #{pre_obj}
$(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
#{undsym}: #{pre_obj}
echo '#{mod_name}' > $@
$(NM) -u -P -p $< | cut -f1 -d' ' >> $@
2002-12-27 08:53:07 +00:00
" + objs.collect_with_index do |obj, i|
src = sources[i]
fake_obj = File.basename(src).suffix('o')
dep = deps[i]
flag = if /\.c$/ =~ src then 'CFLAGS' else 'ASFLAGS' end
dir = File.dirname(src)
"#{obj}: #{src}
$(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(#{flag}) $(#{prefix}_#{flag}) -c -o $@ $<
#{dep}: #{src}
set -e; \
$(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(#{flag}) $(#{prefix}_#{flag}) -M $< \
| sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
[ -s $@ ] || rm -f $@
-include #{dep}
"
end.join('')
end
end
class Utility
def initialize(dir, name)
@dir = dir
@name = name
end
attr_reader :dir, :name
def rule(sources)
prefix = @name.to_var
objs = sources.collect do |src|
raise "unknown source file `#{src}'" if /\.c$/ !~ src
prefix + '-' + src.to_obj
end
objs_str = objs.join(' ');
deps = objs.collect {|obj| obj.suffix('d')}
deps_str = deps.join(' ');
"CLEANFILES += #{@name} #{objs_str}
MOSTLYCLEANFILES += #{deps_str}
#{@name}: #{objs_str}
$(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(#{prefix}_LDFLAGS)
2002-12-27 08:53:07 +00:00
" + objs.collect_with_index do |obj, i|
src = sources[i]
fake_obj = File.basename(src).suffix('o')
dep = deps[i]
dir = File.dirname(src)
"#{obj}: #{src}
$(BUILD_CC) -I#{dir} -I$(srcdir)/#{dir} $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DPUPA_UTIL=1 $(#{prefix}_CFLAGS) -c -o $@ $<
2002-12-27 08:53:07 +00:00
#{dep}: #{src}
set -e; \
$(BUILD_CC) -I#{dir} -I$(srcdir)/#{dir} $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DPUPA_UTIL=1 $(#{prefix}_CFLAGS) -M $< \
2002-12-27 08:53:07 +00:00
| sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
[ -s $@ ] || rm -f $@
-include #{dep}
"
end.join('')
end
end
images = []
utils = []
pmodules = []
cont = false
s = nil
while l = gets
if cont
s += l
else
s = l
end
print l
cont = (/\\$/ =~ l)
unless cont
s.gsub!(/\\\n/, ' ')
if /^([a-zA-Z0-9_]+)\s*=\s*(.*?)\s*$/ =~ s
var, args = $1, $2
if var =~ /^([a-zA-Z0-9_]+)_([A-Z]+)$/
prefix, type = $1, $2
case type
when 'IMAGES'
images += args.split(/\s+/).collect do |img|
Image.new(prefix, img)
end
when 'MODULES'
pmodules += args.split(/\s+/).collect do |pmod|
PModule.new(prefix, pmod)
end
when 'UTILITIES'
utils += args.split(/\s+/).collect do |util|
Utility.new(prefix, util)
end
when 'SOURCES'
if img = images.detect() {|i| i.name.to_var == prefix}
print img.rule(args.split(/\s+/))
elsif pmod = pmodules.detect() {|m| m.name.to_var == prefix}
print pmod.rule(args.split(/\s+/))
elsif util = utils.detect() {|u| u.name.to_var == prefix}
print util.rule(args.split(/\s+/))
end
end
end
end
end
end
puts "CLEANFILES += moddep.lst"
puts "pkgdata_DATA += moddep.lst"
puts "moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep"
puts " cat $(DEFSYMFILES) /dev/null | ./genmoddep $(UNDSYMFILES) > $@ \\"
puts " || (rm -f $@; exit 1)"