linux 原始码与Tarball套件管理员
gcc的使用
只生成目录文件 .o ,不制作连接文件
gcc -c hello.c
根据环境作业给予最佳化执行速度,是大写的O,不是0
gcc -O hello.c -c
-------------------------------------
[这种可以通过,不过好像不这样用] 在进行编译生成目标文件时,将连结的函式库与相关的路径填入
gcc -c th.c -lm -L/lib -L/usr/lib -I/usr/include
由目标文件生成可执行文档
gcc -o th th.o
--------------------------------------
直接生成目标文件,并指定二进制档名,而不会生成目标文件 .o
gcc -o hello hello.c
编译过程更加严谨,,警告信息也会显示出来
gcc -o hello hello.c -Wall
[root@www ~]# gcc sin.c -lm -L/usr/lib -I/usr/include
这个命令较常下达在最终连结成 binary file 的时候,
-lm 指的是 libm.so 或 libm.a 这个函式库文件;
-L 后面接的路径是刚刚上面那个函式库的搜寻目录;
-I 后面接的是原始码内的 include 文件之所在目录。如 #include<stdio.h>
-----------------------------------------
先链接制作目标文件
gcc -c cos_value.c haha.c main.c sin_value.c
再由生成的目标文件,连接函式库与相关路径
gcc -o res main.o sin_value.o cos_value.o haha.o -lm -L/lib -L/usr/lib -I/usr/include
生成res ,可执行文档默认属性为 rwxr-xr-x
-rwxr-xr-x 1 root root 8927 Dec 19 06:17 res
--------------------------------------------
感觉到上边这种方式太过复杂,于是有了make来简化我们编译的过程
make进行巨集编译使用
标的(target): 目标文件1 目标文件2 ...
<tab> gcc -o 要建立的可执行二进制文件 目标文件1 目标文件2
- 在makefile中#代表批注
- <tab>需要在命令行的第一个字符位置上
- 标的(target)与目标文件之间以:分隔
main: main.o haha.o sin_value.o cos_value.o
gcc -o main main.o haha.o sin_value.o cos_value.o -lm
clear:
rm -rf main main.o haha.o sin_value.o cos_value.o
比如上边标的为: main和clear
make main 即是编译过程 make clear即是下边的rm -rf过程
改进
LIBS = -lm
OBJS = main.o haha.o sin_value.o cos_value.o
CFLAGS = -Wall
main: ${OBJS}
gcc -o main ${OBJS} ${LIBS}
clear:
rm -rf main ${OBJS}
说明:与bash shell语法有些不同这处
1. 变量与变量内容以 = 隔开,同时两边可以有空格
2. 变量左边不可以有tab
3. 变量与变量内容在 = 两边不能有:
4. 习惯上,变量以大写字母为主
5. 取用变量时,以${变量名}或$(变量名)
6. shell的环境变量可以被套用,如CFLAGS
7. 在指令列模式可以给予变量
8. $@表示target
root@changda:/tmp/demo1# CFLAGS="-Wall" make clear main
如上可以在makefile文档内直接指定变量CFLAGS,那么与指令列的这个变量优先给如何呢?
1. make 指令列后边加上的环境变量优先
2. makefile里指定的第二
3. shell原本有的环境变量第三
原始码更新
如果您是以 patch 更新原始码,那么记得, 您可能必须要重新编译,并且重新 install
才算成功更新喔!并不是 patch 就好了!因为 patch 的功能主要仅只是更新原始码档案而已
linux静态库与动态库
库是写好的,成熟的,可以利用的代码.现实中每个程序都要依赖很多基础的底层库,免得我们重复造轮子,库的意义非常重要.
库的本质是一种可以执行的二进制形式,可以被系统载入内存执行.
库的分类
所谓的动态与静态库是指编译阶段的链接过程,如下图
- 静态库(.a,.lib)
链接阶段将汇编生成的.o文件与引用到库一起连接打包到可执行程序中.其实静态库与汇编生成的目标文件格式很相似,静态库可以看成是一组目标文件(.o/.obj)的集合,即很多目标文件经过压缩打包后形成的一个文件.
静态库特点:
- 静态库对函数库的链接是放在编译的时候完成的
- 程序在运行时与函数库没有关系了,移植方便
- 浪费空间与资源,因为目标文件与函数库打包在一起成为可执行文件了
- 更新升级麻烦
来个例子:
//头文件
StaticMath.h
#pragma once
class StaticMath
{
public:
StaticMath(void);
~StaticMath(void);
static double add(double a,double b);
static double sub(double a,double b);
static double mul(double a,double b);
static double div(double a,double b);
void print();
};
//implement文件
StaticMath.cpp
#include "StaticMath.h"
double StaticMath::add(double a ,double b)
{
return a + b;
}
double StaticMath::sub(double a, double b)
{
return a - b;
}
double StaticMath::mul(double a, double b)
{
return a*b;
}
double StaticMath::div(double a, double b)
{
return a/b;
}
void StaticMath::print()
{
}
编译为目标文件
g++ -c StaticMath.cpp-->StaticMath.o
通过ar工具将目标文件打包成.a静态库文件
ar -crv libstaticmath.a StaticMath.o
测试文件
TestStaticLib.cpp
#include "StaticMath.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
double a = 40;
double b = 2;
cout<<"a +b ="<<StaticMath::add(a, b)<<endl;
cout<<"a -b ="<<StaticMath::sub(a, b)<<endl;
cout<<"a *b ="<<StaticMath::mul(a, b)<<endl;
cout<<"a /b ="<<StaticMath::div(a, b)<<endl;
return 0;
}
进行测试
g++ TestStaticLibrary.cpp -L ./ -lstaticmath
root@changda:/tmp# ./a.out
a +b =42
a -b =38
a *b =80
a /b =20
此时删除 libstaticmath.a 文件后程序还可以正常运行,这点区别于动态库
root@changda:/tmp# ./a.out
a +b =42
a -b =38
a *b =80
a /b =20
- 动态库(.so .dll)
1 动态库在程序编译时并不会被连接到目标代码中,而是在程序运行是才被载入
2 不同的应用程序如果调用相同的库,那么在内存里只需要有一份该共享库的实例,规避了空间浪费问题
3 动态库在程序运行是才被载入,也解决了静态库对程序的更新、部署和发布页会带来麻烦。用户只需要更新动态库即可,增量更新
来一张图
动态库特点:
- 动态库把对一些库函数的链接载入推迟到程序运行的时期
- 可以实现进程之间的资源共享
- 将一些程序升级变得简单。
- 甚至可以真正做到链接载入完全由程序员在程序代码中控制
- 不需要打包工具(ar),直接使用编译器即可创建动态库。
搜索动态库的先后顺序
- 编译目标代码时指定的动态库搜索路径
- LD_LIBRARY_PATH
- /etc/ld.so.cache
- default path /lib, and then /usr/lib
//头文件
DynamicMath.h
#pragma once
class DynamicMath
{
public:
DynamicMath(void);
~DynamicMath(void);
static double add(double a,double b);
static double sub(double a,double b);
static double mul(double a,double b);
static double div(double a,double b);
void print();
};
//implement file
DynamicMath.cpp
#include "DynamicMath.h"
double DynamicMath::add(double a ,double b)
{
return a + b;
}
double DynamicMath::sub(double a, double b)
{
return a - b;
}
double DynamicMath::mul(double a, double b)
{
return a*b;
}
double DynamicMath::div(double a, double b)
{
return a/b;
}
void DynamicMath::print()
{
}
生成目标文件,此时要加编译器选项-fpic
g++ -fPIC -c DynamicMath.cpp -->生成 DynamicMath.o
[fPIC 创建与地址无关的编译程序(pic,position independent code),是为了能够在多个应用程序间共享]
生成动态库,此时要加链接器选项-shared
g++ -shared -o libdynamicmath.so DynamicMath.o
//测试代码
TestDynamicMath.cpp
#include "DynamicMath.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
double a = 40;
double b = 8;
cout<<"a +b ="<<DynamicMath::add(a, b)<<endl;
cout<<"a -b ="<<DynamicMath::sub(a, b)<<endl;
cout<<"a *b ="<<DynamicMath::mul(a, b)<<endl;
cout<<"a /b ="<<DynamicMath::div(a, b)<<endl;
//StaticMath sm;
//sm.print();
//system("pause");
return 0;
}
//运行
g++ TestDynamicLib.cpp -ldynamicmath
报错
./a.out: error while loading shared libraries: libdynamicmath.so: cannot open shared object file: No such file or directory
这是因为系统加载可执行代码时候,能够知道其所依赖的库的名字,但是还需要知道绝对路径,动态链接载入器dynamic linker load就是干这事的
对于linux elf格式的可执行程序,是由ld-linux.so*来完成的
它先后搜索elf文件的 DT_RPATH段—环境变量LD_LIBRARY_PATH—/etc/ld.so.cache文件列表—/lib/, /usr/lib 目录找到库文件后将其载入内存
1. 如果安装在/lib或者/usr/lib下,那么ld默认能够找到
2. 如果安装在其他目录,需要将其添加到/etc/ld.so.cache文件中
- 编辑/etc/ld.so.conf文件,加入库文件所在目录的路径
- 运行ldconfig ,该命令会重建/etc/ld.so.cache文件
- ld.so.cache为高速缓存,加快了库的调用速度
假设情况一把生成的动态链接文件libdynamicmath.so 放到 /usr/lib下,这时运行
g++ TestDynamicLib.cpp -ldynamicmath
root@changda:/tmp# ./a.out
a +b =48
a -b =32
a *b =320
a /b =5
情况二对应的命令
vi /etc/ld.so.conf
添加一行: /tmp
ldconfig加入/etc/ld.so.cache
通过命令ldconfig -p查看有一行
libdynamicmath.so (libc6,x86-64) => /tmp/libdynamicmath.so
运行
g++ TestDynamicLib.cpp -ldynamicmath #依然报错,估计是没加入到 /etc/ld.so.cache中
//加入路径就正确了
g++ TestDynamicLib.cpp -L. -ldynamicmath # .代表当前路径也可以是 ./
此时若删除/usr/lib/libdynamicmath.so 此时
root@changda:/tmp# ./a.out
./a.out: error while loading shared libraries: libdynamicmath.so: cannot open shared object file: No such file or directory
可见在编译阶段只是在程序中留一个链接口或指针指向实际动态库所在的位置,当程序运行的时候再去那个位置寻找,再加入当前程序中运行的,如果删除了动态库文件,这时候运行程序的时候就会提示找不到库文件,这点区别于静态库文件
查看a.out可执行文件的所依赖的动态库文件
root@changda:/tmp# ldd a.out
linux-vdso.so.1 => (0x00007fff619ff000)
libdynamicmath.so => ./libdynamicmath.so (0x00007f265536f000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f265506a000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2654cab000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f26549af000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2655573000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2654799000)
linux程序校验
root@changda:/tmp# md5sum -c md5sumtest.md5
hello.c: OK
root@changda:/tmp# echo "test" > hello.c
root@changda:/tmp# md5sum -c md5sumtest.md5
hello.c: FAILED
md5sum: WARNING: 1 computed checksum did NOT match
RPM 与SRPM 套件管理员
rpm用法
//成功安装gcc需要的其它软件
[root@changda rpm]# rpm -qR gcc
/bin/sh
/bin/sh
/bin/sh
/sbin/install-info
/sbin/install-info
binutils >= 2.20.51.0.2-12
cpp = 4.8.5-11.el7
glibc-devel >= 2.2.90-12
//gcc被安装到什么地方
[root@changda rpm]# rpm -ql gcc
/usr/bin/c89
/usr/bin/c99
/usr/bin/cc
/usr/bin/gcc
/usr/bin/gcc-ar
/usr/bin/gcc-nm
/usr/bin/gcc-ranlib
/usr/bin/gcov
/usr/bin/x86_64-redhat-linux-gcc
/usr/lib/gcc
/usr/lib/gcc/x86_64-redhat-linux
//gcc的详细信息
[root@changda rpm]# rpm -qi gcc
Name : gcc
Version : 4.8.5
Release : 11.el7
Architecture: x86_64
Install Date: Sat 17 Dec 2016 08:01:02 AM UTC
Group : Development/Languages
Size : 39227971
License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
Signature : RSA/SHA256, Sun 20 Nov 2016 05:46:14 PM UTC, Key ID 24c6a8a7f4a80eb5
Source RPM : gcc-4.8.5-11.el7.src.rpm
Build Date : Fri 04 Nov 2016 04:01:22 PM UTC
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://gcc.gnu.org
Summary : Various compilers (C, C++, Objective-C, Java, ...)
Description :
The gcc package contains the GNU Compiler Collection version 4.8.
You'll need this package in order to compile C code.
//系统安装的所有套件
[root@changda rpm]# rpm -qa
libestr-0.1.9-2.el7.x86_64
centos-release-7-2.1511.el7.centos.2.10.x86_64
bind-license-9.9.4-29.el7_2.4.noarch
filesystem-3.2-20.el7.x86_64
dhclient-4.2.5-42.el7.centos.x86_64
//找出/bin/sh这个二进制档是由哪个软件提供的
[root@changda rpm]# rpm -qf /bin/sh
bash-4.2.46-20.el7_2.x86_64
[root@changda rpm]# rpm -qf /bin/passwd
passwd-0.79-4.el7.x86_64
先由rpm -ql查到/etc/wgetrc的
[root@changda tmp]# rpm -qf /etc/wgetrc
wget-1.14-10.el7_0.1.x86_64
//查看系统哪些文件可能被改动
[root@changda ~]# rpm -Va
S.5....T. c /etc/ssh/ssh_config
S.5....T. c /etc/sysconfig/authconfig
.......T. c /root/.bash_logout
S.5....T. c /root/.bash_profile
S.5....T. c /root/.bashrc
missing c /root/.cshrc
missing c /root/.tcshrc
....L.... c /etc/pam.d/fingerprint-auth
....L.... c /etc/pam.d/password-auth
....L.... c /etc/pam.d/postlogin
....L.... c /etc/pam.d/smartcard-auth
....L.... c /etc/pam.d/system-auth
SM5....T. c /etc/ssh/sshd_config
S.5....T. c /etc/dracut.conf
missing /var/run/wpa_supplicant
SRPM包的安装
crontabs-1.11-6.20121102git.el7.src.rpm 安装
[root@changda ~]# rpmbuild --rebuild crontabs-1.11-6.20121102git.el7.src.rpm
Installing crontabs-1.11-6.20121102git.el7.src.rpm
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.Zvsghy
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf crontabs-1.11
+ /usr/bin/tar -xf -
+ /usr/bin/gzip -dc /root/rpmbuild/SOURCES/crontabs-1.11-1.20121102git.tar.gz
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd crontabs-1.11
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.jmPcRF
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd crontabs-1.11
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.5CTwrN
+ umask 022
+ cd /root/rpmbuild/BUILD
+ '[' /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64 '!=' / ']'
+ rm -rf /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
++ dirname /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT
+ mkdir /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
+ cd crontabs-1.11
+ rm -rf /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/cron.hourly /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/cron.daily /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/cron.weekly /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/cron.monthly
+ mkdir -p /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/usr/bin
+ mkdir -p /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64//usr/share/man/man4/
+ install -m644 ./crontab /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/crontab
+ install -m755 ./run-parts /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/usr/bin/run-parts
+ install -m644 ./crontabs.4 ./run-parts.4 /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64//usr/share/man/man4/
+ mkdir -p /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/sysconfig/
+ touch /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/sysconfig/run-parts
+ /usr/lib/rpm/find-debuginfo.sh --strict-build-id -m --run-dwz --dwz-low-mem-die-limit 10000000 --dwz-max-die-limit 110000000 /root/rpmbuild/BUILD/crontabs-1.11
/usr/lib/rpm/sepdebugcrcfix: Updated 0 CRC32s, 0 CRC32s did match.
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: crontabs-1.11-6.20121102git.el7.centos.noarch
Provides: config(crontabs) = 1.11-6.20121102git.el7.centos crontabs = 1.11-6.20121102git.el7.centos
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: /bin/bash
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
Wrote: /root/rpmbuild/RPMS/noarch/crontabs-1.11-6.20121102git.el7.centos.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.jcvOn3
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd crontabs-1.11
+ rm -rf /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
+ exit 0
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.buK4mb
+ umask 022
+ cd /root/rpmbuild/BUILD
+ rm -rf crontabs-1.11
+ exit 0
在centos 7.2系统中默认好像是安装在/root/rpmbuild下的
rpm的版本<=4.4.x,rpmbuid工具其默认的工作路径是 /usr/src/redhat因为权限的问题,普通用户不能制作rpm包,制作rpm软件包时必须切换到 root 身份才可以。
rpm从4.5.x版本开始,将rpmbuid的默认工作路径移动到用户家目录下的rpmbuild目录里,即 $HOME/rpmbuild ,并且推荐用户在制作rpm软件包时尽量不要以root身份进行操作。
rpmbuild路径是可以修改的,在/usr/lib/rpm/macros这个文件中的一行
%_topdir %{getenv:HOME}/rpmbuild #这里可以修改路径
不过官方建议在~下建立隐藏文件 .rpmmacros来更新路径
[root@changda SPECS]# rpm --version
RPM version 4.11.3
运行 yum install rpmdevtools 安装rpmdevtools
在%_topdir目录下一般需要建立6个目录 各个文件夹依次是:命令 rpmdev-setuptree
drwxr-xr-x 2 root root 4096 Dec 19 02:29 BUILD
drwxr-xr-x 2 root root 4096 Dec 19 02:29 BUILDROOT
drwxr-xr-x 3 root root 4096 Dec 19 02:29 RPMS
drwxr-xr-x 2 root root 4096 Dec 19 02:29 SOURCES
drwxr-xr-x 2 root root 4096 Dec 19 02:29 SPECS
drwxr-xr-x 2 root root 4096 Dec 19 02:29 SRPMS
SPECS:放置的是该软件编译及安装等的配置档,例如资讯参数,配置项目位置,编译安装动作及相关动作
SOURCES:放置原始档(.tar.gz)以及config配置档
BUILD:编译过程中,缓存数据都放在这个目录中
RPMS:这个是编译成功后,将打包完成的文件放在这个目录中,有i386,i586,i686,noarch等次目录
SRPMS:放SRPM封装文件
[root@changda ~]# rpm -i crontabs-1.11-6.20121102git.el7.src.rpm
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
通过-i参数把src.rpm解包得到SPECS和SOURCES,即配置文件和源码
drwxr-xr-x 2 root root 4096 Dec 19 03:12 SOURCES
drwxr-xr-x 2 root root 4096 Dec 19 03:12 SPECS
命令
rpmbuild -ba 生成rpm与src.rpm
rpmbuild -ba 只生成rpm
[root@changda SPECS]# rpmbuild -ba crontabs.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.XLhJSO
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf crontabs-1.11
+ /usr/bin/tar -xf -
+ /usr/bin/gzip -dc /root/rpmbuild/SOURCES/crontabs-1.11-1.20121102git.tar.gz
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd crontabs-1.11
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.vMFqeB
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd crontabs-1.11
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.32DtAn
+ umask 022
+ cd /root/rpmbuild/BUILD
+ '[' /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64 '!=' / ']'
+ rm -rf /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
++ dirname /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT
+ mkdir /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
+ cd crontabs-1.11
+ rm -rf /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/cron.hourly /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/cron.daily /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/cron.weekly /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/cron.monthly
+ mkdir -p /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/usr/bin
+ mkdir -p /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64//usr/share/man/man4/
+ install -m644 ./crontab /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/crontab
+ install -m755 ./run-parts /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/usr/bin/run-parts
+ install -m644 ./crontabs.4 ./run-parts.4 /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64//usr/share/man/man4/
+ mkdir -p /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/sysconfig/
+ touch /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64/etc/sysconfig/run-parts
+ /usr/lib/rpm/find-debuginfo.sh --strict-build-id -m --run-dwz --dwz-low-mem-die-limit 10000000 --dwz-max-die-limit 110000000 /root/rpmbuild/BUILD/crontabs-1.11
/usr/lib/rpm/sepdebugcrcfix: Updated 0 CRC32s, 0 CRC32s did match.
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: crontabs-1.11-6.20121102git.el7.centos.noarch
Provides: config(crontabs) = 1.11-6.20121102git.el7.centos crontabs = 1.11-6.20121102git.el7.centos
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: /bin/bash
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
Wrote: /root/rpmbuild/SRPMS/crontabs-1.11-6.20121102git.el7.centos.src.rpm
Wrote: /root/rpmbuild/RPMS/noarch/crontabs-1.11-6.20121102git.el7.centos.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.pRYYLJ
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd crontabs-1.11
+ rm -rf /root/rpmbuild/BUILDROOT/crontabs-1.11-6.20121102git.el7.centos.x86_64
+ exit 0
自己制作rpm包[由原始码来编译生成rpm包]
以main.tar.gz源码 来做测试
rpmdev-setuptree #生成目录树
rpmdev-newspec -o main.spec #生成模板spec文件
修改main.spec
拷贝main.tar.gz 到 SOURCES目录
开始制作rpm包
[root@changda SPECS]# rpmbuild -ba main.spec
在RPMS下有个x86_64目录
drwxr-xr-x 2 root root 4096 Dec 19 09:32 x86_64
x86_64目录下文件
-rw-r--r-- 1 root root 5452 Dec 19 09:32 main-0.1-1.x86_64.rpm
-rw-r--r-- 1 root root 4476 Dec 19 09:32 main-debuginfo-0.1-1.x86_64.rpm
在SRPMS下
-rw-r--r-- 1 root root 3004 Dec 19 09:32 main-0.1-1.src.rpm
//卸载
[root@changda x86_64]# rpm -e main
[root@changda x86_64]# main
-bash: /usr/local/bin/main: No such file or directory
再开一篇 -->Linux鸟哥私房菜 笔记六
本文由 dealdot <dealdot#163.com> 创作, Full Stack Developer @ DeepBlue
本文最后编辑时间为: Apr 9, 2017 at 16:58 pm
转载请注明来源