LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1091|回复: 10

请youbest等前辈进来看看如何用spec编译

[复制链接]
发表于 2006-12-14 23:14:07 | 显示全部楼层 |阅读模式
就是rpm系统的spec指引文件。它包含编译一个软件的详细方法,如patch,configure,make等。我看过binutils,gcc,glibc等包的spec文件,configure时比lfs要多选项,但spec里的内容很复杂,我看不明白!是否有办法解析spec文件,然后用里面的方法编译?
 楼主| 发表于 2006-12-14 23:18:45 | 显示全部楼层
顺便说多一句:arch的PKGBUILD很清晰,很容易懂;slack的也不是很难理解,就是rpm的spec复杂,不懂电脑语言的很难读懂
回复 支持 反对

使用道具 举报

发表于 2006-12-14 23:49:27 | 显示全部楼层
这个我想应该是跟不同的包管理器以及发行版息息相关的,我想里面使用的参数也是符合该发行版的。

我没有用过rpm、pkgbuild来做包,所以没有研究过它们的处理方式,不过我在自己设计包管理器的时候也是同样要处理这类问题,我觉得如果要完全理解这些可能就需要读rpm的源代码是如何处理的,要么就进行猜测性理解。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-12-15 00:14:52 | 显示全部楼层
如果要完全理解这些可能就需要读rpm的源代码是如何处理的

不可能这么复杂吧?用rpm的人有许多是可以自己编写spec文件来构建rpm包的。能不能下一个gcc的srpm看看spec,说说你的理解
回复 支持 反对

使用道具 举报

发表于 2006-12-15 09:56:14 | 显示全部楼层
对了,忘记说了,应该有相应的文档来介绍的,不过我不太清楚在哪里,看文档应该是很好的途径.
回复 支持 反对

使用道具 举报

发表于 2006-12-15 11:49:55 | 显示全部楼层
rpm 的 spec 不是很复杂啊。
先是 patch ,有顺序的,然后是 conf 段,make 好像是默认的,post install 是 make install 之后的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-12-17 12:01:22 | 显示全部楼层
gcc,glibc等大个头的家伙的spec很复杂,起码我看不明白
回复 支持 反对

使用道具 举报

发表于 2006-12-17 12:58:31 | 显示全部楼层
记得以前看过,没太仔细研究,找个时间再看一下。
回复 支持 反对

使用道具 举报

发表于 2006-12-17 13:19:21 | 显示全部楼层
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-12-17 14:07:13 | 显示全部楼层
这是binutils的spec,看看它的编译方案是否与lfs的不一样?补丁当然不一样
Summary: A GNU collection of binary utilities.
Name: binutils
Version: 2.15.92.0.2
Release: 10.EL4
Copyright: GPL
Group: Development/Tools
URL: http://sources.redhat.com/binutils
Source: ftp://ftp.kernel.org/pub/linux/devel/binutils/binutils-%{version}.tar.bz2
[QUOTE]Patch1: binutils-2.15.92.0.2-ltconfig-multilib.patch
Patch2: binutils-2.15.92.0.2-ppc64-pie.patch
Patch3: binutils-2.15.92.0.2-place-orphan.patch
Patch4: binutils-2.15.92.0.2-ia64-lib64.patch
Patch5: binutils-2.15.92.0.2-relro-fix.patch
Patch6: binutils-2.15.92.0.2-ldsoconf.patch
Patch7: binutils-2.15.92.0.2-elfvsb-test.patch
Patch8: binutils-2.15.92.0.2-prelink-strip.patch
Patch9: binutils-2.15.92.0.2-ppc-tlbie.patch
Patch10: binutils-2.15.92.0.2-strings.patch
Patch11: binutils-2.15.92.0.2-comdat-linkonce-mix.patch
Patch12: binutils-2.15.92.0.2-justsymbols.patch
Patch13: binutils-2.15.92.0.2-ar-xo.patch
Patch14: binutils-2.15.92.0.2-eh-frame-lsda.patch
Patch15: binutils-2.15.92.0.2-stt_section-abs.patch
Patch16: binutils-2.15.92.0.2-ppc64-emit-relocs.patch
Patch17: binutils-2.15.92.0.2-relro-gap.patch

Buildroot: %{_tmppath}/binutils-root
BuildRequires: texinfo >= 4.0, dejagnu, gettext, flex, bison
Prereq: /sbin/install-info
%ifarch ia64
Obsoletes: gnupro
%endif

%define _gnu %{nil}

%description
Binutils is a collection of binary utilities, including ar (for
creating, modifying and extracting from archives), as (a family of GNU
assemblers), gprof (for displaying call graph profile data), ld (the
GNU linker), nm (for listing symbols from object files), objcopy (for
copying and translating object files), objdump (for displaying
information from object files), ranlib (for generating an index for
the contents of an archive), size (for listing the section sizes of an
object or archive file), strings (for listing printable strings from
files), strip (for discarding symbols), and addr2line (for converting
addresses to file and line).

%prep
%setup -q
%patch1 -p0 -b .ltconfig-multilib~
%patch2 -p0 -b .ppc64-pie~
%patch3 -p0 -b .place-orphan~
%ifarch ia64
%if "%{_lib}" == "lib64"
%patch4 -p0 -b .ia64-lib64~
%endif
%endif
%patch5 -p0 -b .relro-fix~
%patch6 -p0 -b .ldsoconf~
%patch7 -p0 -b .elfvsb-test~
%patch8 -p0 -b .prelink-strip~
%patch9 -p0 -b .ppc-tlbie~
%patch10 -p0 -b .strings~
%patch11 -p0 -b .comdat-linkonce-mix~
%patch12 -p0 -b .justsymbols~
%patch13 -p0 -b .ar-xo~
%patch14 -p0 -b .eh-frame-lsda~
%patch15 -p0 -b .stt_section-abs~
%patch16 -p0 -b .ppc64-emit-relocs~
%patch17 -p0 -b .relro-gap~
# libtool sucks
perl -pi -e 'm/LIBADD/ && s/(\.\.\/bfd\/libbfd.la)/-L\.\.\/bfd\/\.libs \1/' opcodes/Makefile.{am,in}
# LTP sucks
perl -pi -e 's/i\[3-7\]86/i[34567]86/g' */conf*
touch */configure
[color="Red"]这是patch过程吧?

%build
mkdir build-%{_target_platform}
cd build-%{_target_platform}
CARGS=
%ifarch sparc ppc s390
CARGS=--enable-64-bit-bfd
%endif
%ifarch ia64
CARGS=--enable-targets=i386-linux
%endif
CFLAGS="${CFLAGS:-%optflags}" ../configure \
  %{_target_platform} --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} \
  --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} \
  --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} \
  --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} \
  --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} \
  --infodir=%{_infodir} --enable-shared $CARGS
make %{_smp_mflags} tooldir=%{_prefix} all
make %{_smp_mflags} tooldir=%{_prefix} info
make -k check < /dev/null > check.log 2>&1 || :
echo ====================TESTING=========================
cat check.log
echo ====================TESTING END=====================
cd ..
[color="red"]这是configure,make过程?

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_prefix}
cd build-%{_target_platform}
%makeinstall
make prefix=%{buildroot}%{_prefix} infodir=%{buildroot}%{_infodir} install-info
gzip -q9f %{buildroot}%{_infodir}/*.info*

# Rebuild libiberty.a with -fPIC
make -C libiberty clean
make CFLAGS="-g -fPIC $RPM_OPT_FLAGS" -C libiberty

install -m 644 libiberty/libiberty.a %{buildroot}%{_prefix}/%{_lib}
install -m 644 ../include/libiberty.h %{buildroot}%{_prefix}/include
# Remove Windows/Novell only man pages
rm -f %{buildroot}%{_mandir}/man1/{dlltool,nlmconv,windres}*

chmod +x %{buildroot}%{_prefix}/%{_lib}/lib*.so*

# Prevent programs to link against libbfd and libopcodes dynamically,
# they are changing far too often
rm -f %{buildroot}%{_prefix}/%{_lib}/lib{bfd,opcodes}.so

# Remove libtool files, which reference the .so libs
rm -f %{buildroot}%{_prefix}/%{_lib}/lib{bfd,opcodes}.la

# This one comes from gcc
rm -f %{buildroot}%{_prefix}/bin/c++filt
rm -f %{buildroot}%{_infodir}/dir
rm -rf %{buildroot}%{_prefix}/%{_target_platform}

cd ..
%find_lang binutils
%find_lang opcodes
%find_lang bfd
%find_lang gas
%find_lang ld
%find_lang gprof
cat opcodes.lang >> binutils.lang
cat bfd.lang >> binutils.lang
cat gas.lang >> binutils.lang
cat ld.lang >> binutils.lang
cat gprof.lang >> binutils.lang

%clean
rm -rf %{buildroot}

%post
/sbin/ldconfig
/sbin/install-info --info-dir=%{_infodir} %{_infodir}/as.info.gz
/sbin/install-info --info-dir=%{_infodir} %{_infodir}/bfd.info.gz
/sbin/install-info --info-dir=%{_infodir} %{_infodir}/binutils.info.gz
/sbin/install-info --info-dir=%{_infodir} %{_infodir}/gprof.info.gz
/sbin/install-info --info-dir=%{_infodir} %{_infodir}/ld.info.gz
/sbin/install-info --info-dir=%{_infodir} %{_infodir}/standards.info.gz

%preun
if [ $1 = 0 ] ;then
  /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/as.info.gz
  /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/bfd.info.gz
  /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/binutils.info.gz
  /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/gprof.info.gz
  /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/ld.info.gz
  /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/standards.info.gz
fi

%postun -p /sbin/ldconfig

%files -f binutils.lang
%defattr(-,root,root)
%doc README
%{_prefix}/bin/*
%{_mandir}/man1/*
%{_prefix}/include/*
%{_prefix}/%{_lib}/lib*
%{_infodir}/*info*

[color="Red"]lfs里没有这些步骤,应该是redhat的安装吧?不用make install,而是为打包rpm准备的吧?好像有增加删除的举止? [/QUOTE]



想借鉴一下主要发行版的编译方案与lfs的不同,请各位分析一下
回复 支持 反对

使用道具 举报

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

本版积分规则

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