找回密码
 注册
查看: 2414|回复: 15

我写的kernel.spec,大家看看

[复制链接]
发表于 2003-11-26 16:24:56 | 显示全部楼层 |阅读模式
里面肯定有错误,不过我已经用标准的kernel打包成功,大家看看.
%define kernelver 2.4.22
Summary: The kernel package contains the Linux kernel
Name: kernel
Group: System Environment/Kernel
License: GPLv2
Version: 2.4.22
Release: 1
BuildPreReq: modutils >= 2.4.21-1, patch >= 2.5.4, bash >= 2.03, sh-utils, tar
BuildPreReq: bzip2, findutils, dev, gzip, m4, perl
BuildRequires: gcc >= 3.00
Source0: linux-2.4.22.tar.gz
Source1: config
BuildRoot: %{_tmppath}/kernel-2.4.22

%description
The kernel package contains the Linux kernel (vmlinuz), the core of yo
ur
Red Hat Linux operating system.  The kernel handles the basic function
s
of the operating system:  memory allocation, process allocation, devic
e
input and output, etc.


%prep

%setup -q -n linux-2.4.22

%build
export CFLAGS="-Wall -Wno-unused-variable -Wno-unused-function -Wno-unused-label -Wno-uninitialized -Wno-multichar -O2 -march=pentium4 -fomit-frame-pointer -ffast-math -finline-functions -frename-registers -pipe"


make -s mrproper

cp %{SOURCE1} .config

make -s oldconfig
make dep
make bzImage
make modules
/usr/lib/rpm/find-debuginfo.sh %{_builddir} || :

%install

mkdir -p $RPM_BUILD_ROOT/boot
install -m 644 System.map $RPM_BUILD_ROOT/boot/System.map-2.4.22
mkdir -p $RPM_BUILD_ROOT/dev/shm
cp arch/i386/boot/bzImage $RPM_BUILD_ROOT/boot/vmlinuz-2.4.22

mkdir -p $RPM_BUILD_ROOT/lib/modules/linux-2.4.22
make -s INSTALL_MOD_PATH=$RPM_BUILD_ROOT modules_install KERNELRELEASE=2.4.22




%clean
rm -fr $RPM_BUILD_ROOT

%pre
/sbin/modprobe loop 2> /dev/null > /dev/null  || :

%post

cd /boot
ln -sf vmlinuz-2.4.22 vmlinuz
ln -sf System.map-2.4.22 System.map
[ -x /usr/sbin/module_upgrade ] && /usr/sbin/module_upgrade
[ -x /sbin/mkkerneldoth ] && /sbin/mkkerneldoth
[ -x /sbin/new-kernel-pkg ] && /sbin/new-kernel-pkg --mkinitrd --depmod --install 2.4.22
%preun
/sbin/modprobe loop 2> /dev/null > /dev/null  || :
[ -x /sbin/new-kernel-pkg ] && /sbin/new-kernel-pkg --rminitrd --rmmoddep --remove 2.4.22

%triggerin -- kudzu
[ -x /usr/sbin/module_upgrade ] && /usr/sbin/module_upgrade || :

%files
%defattr(-,root,root)
/boot/vmlinuz-2.4.22
/boot/System.map-2.4.22
%dir /lib/modules
%dir /dev/shm
/lib/modules/2.4.22
%changelog
* Sat Oct 28 2003 aniuge007 <[email protected]>

first build
发表于 2003-11-26 16:32:14 | 显示全部楼层
不知道改写 grub.conf 的脚本包含在里面没有 ??
回复

使用道具 举报

 楼主| 发表于 2003-11-26 16:47:51 | 显示全部楼层
[ -x /sbin/new-kernel-pkg ] && /sbin/new-kernel-pkg --mkinitrd --depmod --install 2.4.22
这个就是改写grub.conf的.
回复

使用道具 举报

发表于 2003-11-26 16:48:55 | 显示全部楼层
噢,谢谢 !
回复

使用道具 举报

 楼主| 发表于 2003-11-27 10:27:31 | 显示全部楼层
国际惯例,自己顶。
回复

使用道具 举报

 楼主| 发表于 2003-11-27 15:45:53 | 显示全部楼层
这是修改过的,原因是使用了gcc的优化选项,因为公社里有人测试相对于redhat的内核能有7%-10%的性能提高。[code:1]%define KERVER 2.4.22
Summary: The kernel package contains the Linux kernel
Name: kernel
Group: System Environment/Kernel
License: GPLv2
Version: %{KERVER}
Release: 1
BuildPreReq: modutils >= 2.4.21-1, patch >= 2.5.4, bash >= 2.03, sh-utils, tar
BuildPreReq: bzip2, findutils, dev, gzip, m4, perl
BuildRequires: gcc >= 3.00
Source0: linux-%{kernerlver}.tar.bz2
Source1: config
Source2: Makefile-kernel
BuildRoot: %{_tmppath}/kernel-%{KERVER}

%description
The kernel package contains the Linux kernel (vmlinuz), the core of yo
ur
Red Hat Linux operating system.  The kernel handles the basic function
s
of the operating system:  memory allocation, process allocation, devic
e
input and output, etc.


%prep

%setup -q -n linux-{KERVER}

%build
#export CFLAGS="-Wall -Wno-unused-variable -Wno-unused-function -Wno-unused-label -Wno-uninitialized -Wno-multichar -O2 -march=pentium4 -fomit-frame-pointer -ffast-math -finline-functions -frename-registers -pipe"


make -s mrproper

cp -f %{SOURCE1} .config
cp -f %{SOURCE2} arch/i386/Makefile

make -s oldconfig
make dep
make bzImage
make modules

%install

mkdir -p $RPM_BUILD_ROOT/boot
install -m 644 System.map $RPM_BUILD_ROOT/boot/System.map-%{KERVER}
mkdir -p $RPM_BUILD_ROOT/dev/shm
cp arch/i386/boot/bzImage $RPM_BUILD_ROOT/boot/vmlinuz-%{KERVER}

mkdir -p $RPM_BUILD_ROOT/lib/modules/linux-%{KERVER}
make -s INSTALL_MOD_PATH=$RPM_BUILD_ROOT modules_install KERNELRELEASE=%{KERVER}




%clean
rm -fr $RPM_BUILD_ROOT

%pre
/sbin/modprobe loop 2> /dev/null > /dev/null  || :

%post

cd /boot
ln -sf vmlinuz-%{KERVER} vmlinuz
ln -sf System.map-%{KERVER} System.map
[ -x /usr/sbin/module_upgrade ] && /usr/sbin/module_upgrade
[ -x /sbin/mkkerneldoth ] && /sbin/mkkerneldoth
[ -x /sbin/new-kernel-pkg ] && /sbin/new-kernel-pkg --mkinitrd --depmod --install %{KERVER}
%preun
/sbin/modprobe loop 2> /dev/null > /dev/null  || :
[ -x /sbin/new-kernel-pkg ] && /sbin/new-kernel-pkg --rminitrd --rmmoddep --remove %{KERVER}

%triggerin -- kudzu
[ -x /usr/sbin/module_upgrade ] && /usr/sbin/module_upgrade || :

%files
%defattr(-,root,root)
/boot/vmlinuz-%{KERVER}
/boot/System.map-%{KERVER}
%dir /lib/modules
%dir /dev/shm
/lib/modules/%{KERVER}
%changelog
* Sat Oct 28 2003 aniuge007 <[email protected]>

first build
[/code:1][/code][/quote]
回复

使用道具 举报

 楼主| 发表于 2003-11-27 15:49:59 | 显示全部楼层
这是Makefile文件,不同的版本,不一样,大家不要照抄[code:1]#
# i386/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies. Remember to do have actions
# for "archclean" and "archdep" for cleaning up and making dependencies for
# this architecture
#
# This file is subject to the terms and conditions of the GNU General Public
# License.  See the file "COPYING" in the main directory of this archive
# for more details.
#
# Copyright (C) 1994 by Linus Torvalds
#
# 19990713  Artur Skawina <[email protected]>
#           Added '-march' and '-mpreferred-stack-boundary' support
#

LD=$(CROSS_COMPILE)ld -m elf_i386
OBJCOPY=$(CROSS_COMPILE)objcopy -O binary -R .note -R .comment -S
LDFLAGS=-e stext
LINKFLAGS =-T $(TOPDIR)/arch/i386/vmlinux.lds $(LDFLAGS)

CFLAGS += -pipe -O2

check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)

# prevent gcc from keeping the stack 16 byte aligned
CFLAGS += $(call check_gcc,-mpreferred-stack-boundary=2,)

ifdef CONFIG_M386
CFLAGS += -march=i386
endif

ifdef CONFIG_M486
CFLAGS += -march=i486
endif

ifdef CONFIG_M586
CFLAGS += -march=i586
endif

ifdef CONFIG_M586TSC
CFLAGS += -march=i586
endif

ifdef CONFIG_M586MMX
CFLAGS += -march=i586
endif

ifdef CONFIG_M686
CFLAGS += -march=i686
endif

ifdef CONFIG_MPENTIUMIII
CFLAGS += $(call check_gcc,-march=pentium3,-march=i686 -fomit-frame-pointer -malign-functions=4 -fprefetch-loop-arrays)

endif

ifdef CONFIG_MPENTIUM4
CFLAGS += $(call check_gcc,-march=pentium4,-march=i686 -fomit-frame-pointer -malign-functions=4 -fprefetch-loop-arrays)
endif

ifdef CONFIG_MK6
CFLAGS += $(call check_gcc,-march=k6,-march=i586)
endif

ifdef CONFIG_MK7
CFLAGS += $(call check_gcc,-march=athlon,-march=i686 -malign-functions=4 -fomit-frame-pointer)
endif

ifdef CONFIG_MCRUSOE
CFLAGS += -march=i686
CFLAGS += $(call check_gcc,-falign-functions=0 -falign-jumps=0 -falign-loops=0,-malign-functions=0 -malign-jumps=0 -malign-loops=0)
endif

ifdef CONFIG_MWINCHIPC6
CFLAGS += -march=i586
endif

ifdef CONFIG_MWINCHIP2
CFLAGS += -march=i586
endif

ifdef CONFIG_MWINCHIP3D
CFLAGS += -march=i586
endif

ifdef CONFIG_MCYRIXIII
CFLAGS += $(call check_gcc,-march=c3,-march=i486)
CFLAGS += $(call check_gcc,-falign-functions=0 -falign-jumps=0 -falign-loops=0,-malign-functions=0 -malign-jumps=0 -malign-loops=0)
endif

ifdef CONFIG_MVIAC3_2
CFLAGS += $(call check_gcc,-march=c3-2,-march=i686)
endif

HEAD := arch/i386/kernel/head.o arch/i386/kernel/init_task.o

SUBDIRS += arch/i386/kernel arch/i386/mm arch/i386/lib

CORE_FILES := arch/i386/kernel/kernel.o arch/i386/mm/mm.o $(CORE_FILES)
LIBS := $(TOPDIR)/arch/i386/lib/lib.a $(LIBS) $(TOPDIR)/arch/i386/lib/lib.a

ifdef CONFIG_MATH_EMULATION
SUBDIRS += arch/i386/math-emu
DRIVERS += arch/i386/math-emu/math.o
endif

arch/i386/kernel: dummy
        $(MAKE) linuxsubdirs SUBDIRS=arch/i386/kernel

arch/i386/mm: dummy
        $(MAKE) linuxsubdirs SUBDIRS=arch/i386/mm

MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot

vmlinux: arch/i386/vmlinux.lds

FORCE: ;

.PHONY: zImage bzImage compressed zlilo bzlilo zdisk bzdisk install \
                clean archclean archmrproper archdep

zImage: vmlinux
        @$(MAKEBOOT) zImage

bzImage: vmlinux
        @$(MAKEBOOT) bzImage

compressed: zImage

zlilo: vmlinux
        @$(MAKEBOOT) BOOTIMAGE=zImage zlilo

tmp:
        @$(MAKEBOOT) BOOTIMAGE=bzImage zlilo
bzlilo: vmlinux
        @$(MAKEBOOT) BOOTIMAGE=bzImage zlilo

zdisk: vmlinux
        @$(MAKEBOOT) BOOTIMAGE=zImage zdisk

bzdisk: vmlinux
        @$(MAKEBOOT) BOOTIMAGE=bzImage zdisk

install: vmlinux
        @$(MAKEBOOT) BOOTIMAGE=bzImage install

archclean:
        @$(MAKEBOOT) clean

archmrproper:

archdep:
        @$(MAKEBOOT) dep
[/code:1]
回复

使用道具 举报

 楼主| 发表于 2003-11-27 15:57:24 | 显示全部楼层
一天的劳动成果,大家支持一下。
回复

使用道具 举报

 楼主| 发表于 2003-11-27 16:40:05 | 显示全部楼层
spec里有错,查出有奖。
回复

使用道具 举报

发表于 2003-11-27 16:43:48 | 显示全部楼层
枯燥而且没有流程说明、功能解释的程序,是没人会看的。
回复

使用道具 举报

发表于 2003-11-27 21:39:16 | 显示全部楼层
O2真的快吗
回复

使用道具 举报

 楼主| 发表于 2003-11-28 00:16:36 | 显示全部楼层
[quote:a0422c9493="gugong"]枯燥而且没有流程说明、功能解释的程序,是没人会看的。[/quote]这不是程序,只是个很简单的spec脚本。
回复

使用道具 举报

发表于 2003-11-28 10:47:39 | 显示全部楼层
[code:1]Wall -Wno-unused-variable -Wno-unused-function -Wno-unused-label -Wno-uninitialized -Wno-multichar -O2 -march=pentium4 -fomit-frame-pointer -ffast-math -finline-functions -frename-registers -pipe[/code:1]

拜托,如果你是编译出来自己用就算了,如果你打算给大家用的话,千万要把-march=pentium4去掉,不是人人都用pentium4的。
回复

使用道具 举报

 楼主| 发表于 2003-11-28 12:01:27 | 显示全部楼层
[quote:57f64fe92d="樱家冢"]
[code:1]Wall -Wno-unused-variable -Wno-unused-function -Wno-unused-label -Wno-uninitialized -Wno-multichar -O2 -march=pentium4 -fomit-frame-pointer -ffast-math -finline-functions -frename-registers -pipe[/code:1]

拜托,如果你是编译出来自己用就算了,如果你打算给大家用的话,千万要把-march=pentium4去掉,不是人人都用pentium4的。[/quote]奇怪了,那一段我已经注释掉了呀,
回复

使用道具 举报

发表于 2003-11-28 13:53:14 | 显示全部楼层
奇怪了,那一段我已经注释掉了呀

FT,我从上面引用的……
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-1-10 06:11 , Processed in 0.069301 second(s), 15 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表