[内核源码][Makefile]修改linux-0.12代码

修改linux-0.12代码,以让其能通过当前编译器编译
deal文件

#! /bin/bash

file_tar=linux-0.12
file_deal=Modify2Now

rm -rf $file_tar
tar -xzf "$file_tar.tar.gz"
cp $file_deal ./$file_tar
cd $file_tar
./$file_deal
make

Modify2Now文件

#! /bin/bash

echo "开始处理..."

# 这一部分是修改编译链接参数,以适用现在的编译器
find . -name Makefile|xargs sed -i 's/gas/as/g'
find . -name Makefile|xargs sed -i 's/gar/ar/g'
find . -name Makefile|xargs sed -i 's/gld/ld/g'
find . -name Makefile|xargs sed -i 's/-fcombine-regs//g'
find . -name Makefile|xargs sed -i 's/-mstring-insns//g'

find . -name Makefile|xargs sed -i 's/$(AS)/$(AS) --32/g'
find . -name Makefile|xargs sed -i 's/$(CC)/$(CC) -m32 -std=gnu11 -fgnu89-inline/g'
find . -name Makefile|xargs sed -i 's/$(LD)/$(LD) -m elf_i386 --oformat elf32-i386/g'
find . -name Makefile|xargs sed -i 's/$(CFLAGS)/$(CFLAGS) -ffreestanding/g' Makefile

sed -i '51s/-ffreestanding//g' Makefile
sed -i '51s/-m32//g' Makefile
sed -i '58s/$(LD)/$(LD) -e startup_32 -Ttext=0x0/g' Makefile

sync

# 这一部分是解决函数不返回问题
sed -i '20i extern inline void oom(void) __attribute__((noreturn));' include/linux/mm.h
sed -i '21s/volatile//g' include/linux/mm.h
sed -i '6s/volatile void do_exit(long error_code);/void do_exit(long error_code) __attribute__((noreturn));/g' include/linux/kernel.h
sed -i '262s/volatile//g' kernel/exit.c
sed -i '5s/volatile void panic(const char \* str);/void panic(const char \* str) __attribute__((noreturn));/g' include/linux/kernel.h
sed -i '62s/extern void panic(const char \* str);/extern void panic(const char \* str) __attribute__((noreturn));/g' include/linux/sched.h
sed -i '16s/volatile//g' kernel/panic.c
sed -i '225s/volatile void _exit(int status);/void _exit(int status) __attribute__((noreturn));/g' include/unistd.h
sed -i '10s/volatile//g' lib/_exit.c
sed -i '48s/extern void init(void);/extern void init(void) __attribute__((noreturn));/g' init/main.c

sync

# 这一部分是修改build工具中的两个函数名
sed -i 's/MAJOR(/major(/g' tools/build.c
sed -i 's/MINOR(/minor(/g' tools/build.c

sync

# 这一部分得处理好像违背了源代码得初衷
find . -name main.c|xargs sed -i 's/static inline/inline/g'
find . -name main.c|xargs sed -i 's/static int printf/int printf/g'

sync

# 将startup_32添加到符号表
sed -i '15s/.globl/.globl startup_32,/g' boot/head.s

sync

# 下面一部分是处理GCC旧版本在符号前添加下划线
find . -type f |xargs sed -i 's/_stack_start/stack_start/g'
find . -type f |xargs sed -i 's/_main/main/g'
find . -type f |xargs sed -i 's/_printk/printk/g'
find . -type f |xargs sed -i 's/_current/current/g'
find . -type f |xargs sed -i 's/_last_task_used_math/last_task_used_math/g'
find . -type f |xargs sed -i 's/_gdt/gdt/g'
find . -type f |xargs sed -i 's/_timer_interrupt/timer_interrupt/g'
find . -type f |xargs sed -i 's/_idt/idt/g'
find . -type f |xargs sed -i 's/_system_call/system_call/g'
find . -type f |xargs sed -i 's/_schedule/schedule/g'
find . -type f |xargs sed -i 's/_NR_syscalls/NR_syscalls/g'
find . -type f |xargs sed -i 's/_sys_call_table/sys_call_table/g'
find . -type f |xargs sed -i 's/_task/task/g'
find . -type f |xargs sed -i 's/_do_signal/do_signal/g'
find . -type f |xargs sed -i 's/_math_error/math_error/g'
find . -type f |xargs sed -i 's/_math_state_restore/math_state_restore/g'
find . -type f |xargs sed -i 's/_math_emulate/math_emulate/g'
find . -type f |xargs sed -i 's/_jiffies/jiffies/g'
find . -type f |xargs sed -i 's/_do_timer/do_timer/g'
find . -type f |xargs sed -i 's/_do_execve/do_execve/g'
find . -type f |xargs sed -i 's/_find_empty_process/find_empty_process/g'
find . -type f |xargs sed -i 's/_copy_process/copy_process/g'
find . -type f |xargs sed -i 's/_hd_timeout/hd_timeout/g'
find . -type f |xargs sed -i 's/_do_hd/do_hd/g'
find . -type f |xargs sed -i 's/_unexpected_hd_interrupt/unexpected_hd_interrupt/g'
find . -type f |xargs sed -i 's/_do_floppy/do_floppy/g'
find . -type f |xargs sed -i 's/_unexpected_floppy_interrupt/unexpected_floppy_interrupt/g'
find . -type f |xargs sed -i 's/_divide_error/divide_error/g'
find . -type f |xargs sed -i 's/_debug/debug/g'
find . -type f |xargs sed -i 's/_nmi/nmi/g'
find . -type f |xargs sed -i 's/_int3/int3/g'
find . -type f |xargs sed -i 's/_overflow/overflow/g'
find . -type f |xargs sed -i 's/_bounds/bounds/g'
find . -type f |xargs sed -i 's/_invalid_op/invalid_op/g'
find . -type f |xargs sed -i 's/_device_not_available/device_not_available/g'
find . -type f |xargs sed -i 's/_double_fault/double_fault/g'
find . -type f |xargs sed -i 's/_coprocessor_segment_overrun/coprocessor_segment_overrun/g'
find . -type f |xargs sed -i 's/_invalid_TSS/invalid_TSS/g'
find . -type f |xargs sed -i 's/_segment_not_present/segment_not_present/g'
find . -type f |xargs sed -i 's/_stack_segment/stack_segment/g'
find . -type f |xargs sed -i 's/_general_protection/general_protection/g'
find . -type f |xargs sed -i 's/_page_fault/page_fault/g'
find . -type f |xargs sed -i 's/_reserved/reserved/g'
find . -type f |xargs sed -i 's/_coprocessor_error/coprocessor_error/g'
find . -type f |xargs sed -i 's/_alignment_check/alignment_check/g'
find . -type f |xargs sed -i 's/_irq13/irq13/g'
find . -type f |xargs sed -i 's/_parallel_interrupt/parallel_interrupt/g'
find . -type f |xargs sed -i 's/_dodivide_error/dodivide_error/g'
find . -type f |xargs sed -i 's/_doint3/doint3/g'
find . -type f |xargs sed -i 's/_donmi/donmi/g'
find . -type f |xargs sed -i 's/_doint3/doint3/g'
find . -type f |xargs sed -i 's/_dooverflow/dooverflow/g'
find . -type f |xargs sed -i 's/_dobounds/dobounds/g'
find . -type f |xargs sed -i 's/_doinvalid_op/doinvalid_op/g'
find . -type f |xargs sed -i 's/_docoprocessor_segment_overrun/docoprocessor_segment_overrun/g'
find . -type f |xargs sed -i 's/_doreserved/doreserved/g'
find . -type f |xargs sed -i 's/_dodouble_fault/dodouble_fault/g'
find . -type f |xargs sed -i 's/_doinvalid_TSS/doinvalid_TSS/g'
find . -type f |xargs sed -i 's/_dosegment_not_present/dosegment_not_present/g'
find . -type f |xargs sed -i 's/_dostack_segment/dostack_segment/g'
find . -type f |xargs sed -i 's/_dogeneral_protection/dogeneral_protection/g'
find . -type f |xargs sed -i 's/_doalignment_check/doalignment_check/g'
find . -type f |xargs sed -i 's/_pg_dir/pg_dir/g'
find . -type f |xargs sed -i 's/_sys_fork/sys_fork/g'
find . -type f |xargs sed -i 's/_sys_execve/sys_execve/g'
find . -type f |xargs sed -i 's/_do_no_page/do_no_page/g'
find . -type f |xargs sed -i 's/_do_wp_page/do_wp_page/g'
find . -type f |xargs sed -i 's/_tmp_floppy_area/tmp_floppy_area/g'
find . -type f |xargs sed -i 's/_floppy_interrupt/floppy_interrupt/g'
find . -type f |xargs sed -i 's/_hd_interrupt/hd_interrupt/g'
find . -type f |xargs sed -i 's/_video_num_columns/video_num_columns/g'
find . -type f |xargs sed -i 's/_keyboard_interrupt/keyboard_interrupt/g'
find . -type f |xargs sed -i 's/_rs1_interrupt/rs1_interrupt/g'
find . -type f |xargs sed -i 's/_rs2_interrupt/rs2_interrupt/g'
find . -type f |xargs sed -i 's/_blankinterval/blankinterval/g'
find . -type f |xargs sed -i 's/_blankcount/blankcount/g'
find . -type f |xargs sed -i 's/_do_tty_interrupt/do_tty_interrupt/g'
find . -type f |xargs sed -i 's/_table_list/table_list/g'
find . -type f |xargs sed -i 's/_show_mem/show_mem/g'
find . -type f |xargs sed -i 's/_show_state/show_state/g'
find . -type f |xargs sed -i 's/_change_console/change_console/g'

sync

# 下面一部分是处理内敛汇编的新旧格式差异
sed -i '176s/:"ax"//g' init/main.c

sed -i '34s/:"si","di","ax"//g' include/string.h
sed -i '50s/:"si","di","ax","cx"//g' include/string.h
sed -i '64s/:"si","di","ax","cx"//g' include/string.h
sed -i '84s/:"si","di","ax","cx"//g' include/string.h
sed -i '103s/:"si","di"//g' include/string.h
sed -i '124s/:"si","di","cx"//g' include/string.h
sed -i '141s/:"si"//g' include/string.h
sed -i '157s/:"ax","si"//g' include/string.h
sed -i '181s/:"ax","cx","dx","di"//g' include/string.h
sed -i '205s/:"ax","cx","dx","di"//g' include/string.h
sed -i '232s/:"ax","cx","dx","di"//g' include/string.h
sed -i '259s/:"cx","dx","di","si"//g' include/string.h
sed -i '271s/:"di"//g' include/string.h
sed -i '332s/:"ax","cx","dx","di"//g' include/string.h
sed -i '342s/:"cx","si","di"//g' include/string.h
sed -i '353s/:"cx","si","di"//g' include/string.h
sed -i '359s/:"cx","si","di"//g' include/string.h
sed -i '375s/:"si","di","cx"//g' include/string.h
sed -i '391s/:"cx"//g' include/string.h
sed -i '401s/:"cx","di"//g' include/string.h

sed -i '248s/:"dx"//g' include/linux/sched.h

sed -i '45s/:"cx","di","si"//g' mm/memory.c

sed -i '191s/:"di","cx","dx"//g' mm/swap.c

sed -i '288s/:"cx","di","si"//g' fs/buffer.c

sed -i '27s/"r"/"q"/g' include/asm/segment.h

sed -i '260s/:"dx"//g' include/linux/sched.h

sed -i '82s/:"cx","di","si"//g' fs/namei.c

sed -i '17s/:"cx","di"//g' fs/bitmap.c
sed -i '44s/:"ax","dx","si"//g' fs/bitmap.c

sed -i '159s/:"cx","di","si"//g' kernel/blk_drv/floppy.c

sed -i '65s/:"cx","di"//g' kernel/blk_drv/hd.c
sed -i '68s/:"cx","si"//g' kernel/blk_drv/hd.c

sed -i '12s/:"di","si","cx"//g' include/asm/memory.h

sed -i '5s/"=r"/"=q"/g' include/asm/segment.h

sed -i '209s/:"cx","di","si"//g' kernel/chr_drv/console.c
sed -i '220s/:"cx","di"//g' kernel/chr_drv/console.c
sed -i '234s/:"cx","di","si"//g' kernel/chr_drv/console.c
sed -i '249s/:"cx","di","si"//g' kernel/chr_drv/console.c
sed -i '270s/:"ax","cx","di","si"//g' kernel/chr_drv/console.c
sed -i '285s/:"ax","cx","di","si"//g' kernel/chr_drv/console.c
sed -i '350s/:"cx","di"//g' kernel/chr_drv/console.c
sed -i '381s/:"cx","di"//g' kernel/chr_drv/console.c
sed -i '604s/:"ax"//g' kernel/chr_drv/console.c
sed -i '1020s/:"ax"//g' kernel/chr_drv/console.c

sync

# 处理左值问题
sed -i '162s/                   !(pag = (char \*) page\[p\/PAGE_SIZE\] =/                   !(pag = (char \*) (page\[p\/PAGE_SIZE\] =/g' fs/exec.c
sed -i '163s/                     (unsigned long \*) get_free_page())) /                      get_free_page()))) /g' fs/exec.c
sed -i '156s/(void \*)/\*(char \*)/g' lib/malloc.c
#sed -i '156s/get_free_page()/((char *)get_free_page())/g' lib/malloc.c

sync

# 处理新旧汇编代码中关于.align的差异
files=$(find . -name *.s)
files=${files}$'\n'$(find . -name *.S)
for file in $files
do
    sed -i 's/.align 2/.align 4/g' $file
    sed -i 's/.align 3/.align 8/g' $file
done

sync

# 处理其他问题
sed -i '190s/   if (\*p = tmp)/ if ((\*p = tmp) != NULL)/g' kernel/sched.c
sed -i '228s/   "ljmp %0\\n\\t" \\/ "ljmp \*%0\\n\\t" \\/g' include/linux/sched.h
sed -i '99s/    call sys_call_table(,%eax,4)/   call \*sys_call_table(,%eax,4)/g' kernel/sys_call.s
sed -i '120s/       if (f=p->filp\[i\])/        if ((f=p->filp\[i\]) != NULL)/g' kernel/fork.c
sed -i '59i     {' kernel/vsprintf.c
sed -i '62i     }' kernel/vsprintf.c
sed -i '76i     {' kernel/vsprintf.c
sed -i '82i     }' kernel/vsprintf.c
sed -i '214s/           if (err = send_sig(sig,\*p,0))/         if ((err = send_sig(sig,\*p,0)) != 0)/g' kernel/exit.c
sed -i 's/  if (p = current->p_cptr) {/ if ((p = current->p_cptr) != NULL) {/g' kernel/exit.c
sed -i '236i qualifier++;' kernel/vsprintf.c
sed -i '331s/       if (to = get_free_page())/      if ((to = get_free_page()) != 0)/g' mm/memory.c
sed -i '331i    {' mm/memory.c
sed -i '336i    }' mm/memory.c
sed -i '490i    {' mm/memory.c
sed -i '496i    }' mm/memory.c
sed -i '155i    {' mm/swap.c
sed -i '160i    }' mm/swap.c
sed -i '176s/asm/__asm__/g' mm/swap.c
sed -i '85s/            if (inode->i_zone\[block\]=new_block(inode->i_dev)) {/          if ((inode->i_zone\[block\]=new_block(inode->i_dev)) != 0) {/g' fs/inode.c
sed -i '94s/            if (inode->i_zone\[7\]=new_block(inode->i_dev)) {/          if ((inode->i_zone\[7\]=new_block(inode->i_dev)) != 0) {/g' fs/inode.c
sed -i '104s/           if (i=new_block(inode->i_dev)) {/           if ((i=new_block(inode->i_dev)) != 0) {/g' fs/inode.c
sed -i '113s/       if (inode->i_zone\[8\]=new_block(inode->i_dev)) {/      if ((inode->i_zone\[8\]=new_block(inode->i_dev)) != 0) {/g' fs/inode.c
sed -i '123s/       if (i=new_block(inode->i_dev)) {/       if ((i=new_block(inode->i_dev)) != 0) {/g' fs/inode.c
sed -i '134s/       if (i=new_block(inode->i_dev)) {/       if ((i=new_block(inode->i_dev)) != 0) {/g' fs/inode.c
sed -i '35i void put_super(int dev);' fs/buffer.c
sed -i '36i void invalidate_inodes(int dev);' fs/buffer.c
sed -i '213s/   if (bh = get_hash_table(dev,block))/    if ((bh = get_hash_table(dev,block)) != NULL)/g' fs/buffer.c
sed -i '305s/           if (bh\[i\] = getblk(dev,b\[i\]))/          if ((bh\[i\] = getblk(dev,b\[i\])) != NULL)/g' fs/buffer.c
sed -i '108s/   if (s = get_super(dev))/    if ((s = get_super(dev)) != NULL)/g' fs/super.c
sed -i '142s/       if (s->s_imap\[i\]=bread(dev,block))/       if ((s->s_imap\[i\]=bread(dev,block)) != NULL)/g' fs/super.c
sed -i '147s/       if (s->s_zmap\[i\]=bread(dev,block))/       if ((s->s_zmap\[i\]=bread(dev,block)) != NULL)/g' fs/super.c
sed -i '19s/typedef/typedef int/g' fs/char_dev.c
sed -i '25s/        if (nr = bmap(inode,(filp->f_pos)\/BLOCK_SIZE)) {/      if ((nr = bmap(inode,(filp->f_pos)\/BLOCK_SIZE)) != 0) {/g' fs/file_dev.c
sed -i '103s/   if (tmp = argv)/    if ((tmp = argv) != NULL)/g' fs/exec.c
sed -i '264d' fs/exec.c
sed -i "264i        if (!(cp = strchr(buf, \'\\\n\'))) {" fs/exec.c
sed -i '325s/   while (c=get_fs_byte(pathname++))/  while ((c=get_fs_byte(pathname++)) != 0)/g' fs/namei.c
sed -i '86s/        if (bh=sb->s_zmap\[i\])/        if (!(bh=sb->s_zmap\[i\]))/g' fs/bitmap.c
sed -i '150s/       if (bh=sb->s_imap\[i\])/        if (!(bh=sb->s_imap\[i\]))/g' fs/bitmap.c
sed -i '21s/    if (bh=bread(dev,block)) {/ if (!(bh=bread(dev,block))) {/g' fs/truncate.c
sed -i '25i     {' fs/truncate.c
sed -i '31i     }' fs/truncate.c
sed -i '50s/    if (bh=bread(dev,block)) {/ if (!(bh=bread(dev,block))) {/g' fs/truncate.c
sed -i '54i     {' fs/truncate.c
sed -i '60i     }' fs/truncate.c
sed -i '76s/        if (\*tpp = p->entry\[i\].oldtask)/     if (!(\*tpp = p->entry\[i\].oldtask))/g' fs/select.c
sed -i '107s/   if (tty = get_tty(inode))/  if (!(tty = get_tty(inode)))/g' fs/select.c
sed -i '108i    {' fs/select.c
sed -i '113i    }' fs/select.c
sed -i '115i    {' fs/select.c
sed -i '120i    }' fs/select.c
sed -i '128s/   if (tty = get_tty(inode))/  if (!(tty = get_tty(inode)))/g' fs/select.c
sed -i '145s/   if (tty = get_tty(inode))/  if (!(tty = get_tty(inode)))/g' fs/select.c
sed -i '146i    {' fs/select.c
sed -i '151i    }' fs/select.c
sed -i '153i    {' fs/select.c
sed -i '158i    }' fs/select.c
sed -i '129i    {' fs/select.c
sed -i '134i    }' fs/select.c
sed -i '136i    {' fs/select.c
sed -i '141i    }' fs/select.c
sed -i '92i     {' kernel/blk_drv/ll_rw_blk.c
sed -i '97i     }' kernel/blk_drv/ll_rw_blk.c
sed -i '115s/   if (rw_ahead = (rw == READA || rw == WRITEA)) {/    if (!(rw_ahead = (rw == READA || rw == WRITEA))) {/g' kernel/blk_drv/ll_rw_blk.c
sed -i '39i void init_swapping(void);' kernel/blk_drv/hd.c
sed -i '192s/asm/__asm__/g' kernel/blk_drv/hd.c



sync

echo "处理完成!"

你可能感兴趣的:(内核源码)