zoukankan      html  css  js  c++  java
  • Linux制作deb

    1、新建一个我们临时的工作目录mkdir deb


    2、新建我们程序的目录
    mkdir hello

    3、编写我们的程序

    我们以我们最熟悉的helloworld程序做起,
    hello.c代码如下
    #include <stdio.h>
    int main()
    {
         printf("Hello world! "); 
         return 0;
    }
    Makefile文件如下:


    OBJS=hello.o
    CC=gcc -g
    all:$(OBJS)
      $(CC) -o hello $(OBJS)
    clean:
      rm -f *.o hello
    .PHONY:all clean

    4、我们sudo make一下,测试程序编译是否有问题,然后在./hello检查程序是否正确执行

    5、如果没问题进行下一步,如果有问题我们看提示检查程序代码

    6、我们清理下刚才编译程序的垃圾,sudo make clean一下

    7、输入命令,切回上级目录


    cd ..

    8、进行一次压缩打包(为什么做这一步,我也不太明白,查资料说,这一步是为了给生成的deb文件进行对比,确保我们deb文件没有错误)


    改名:因为文件名必须包含文件名还有版本号
    mv hello hello-1.0
    //说明:文件名后必须用-,不能用_

    tar zcvf hello_1.0.orig.tar.gz hello-1.0
    说明:压缩包的名字必须是包含文件名及版本号

    9、进入我们的hello-1.0目录
    cd hello-1.0

    10、我们需要dh_make工具进行打包前的配置,如果是第一使用请先安装dh-make
    dh-make安装方法:
    sudo apt-get install dh-make
    安装好后,我们就可以使用该命令了
    dh_make -e linuxidc@www.linuxidc.com 修改参数,也可以不修改,执行这一步,我们将会看到,邮箱是我们刚才输入的
    如果不想改为自己的邮箱,可以执行下面命令
    dh_make
    上面任一命令后都会出现,一下内容:
    www.linuxidc.com@linuxidc:~/deb/hello-1.0$ dh_make -e linuxidc@www.linuxidc.com
    Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch or cdbs?
      [s/i/m/l/k/n/b]

    11、我们输入s


    Maintainer name : zsx
    Email-Address : linuxidc@www.linuxidc.com 
    Date : Sat, 18 Dec 2010 23:06:25 +0800
    Package Name : hello
    Version : 1.0
    License : blank
    Using dpatch : no
    Type of Package : Single
    Hit <enter> to confirm:

    12、输入回车,确认
    Skipping creating ../hello_1.0.orig.tar.gz because it already exists
    Done. Please edit the files in the debian/ subdirectory now. You should also
    check that the hello Makefiles install into $DESTDIR and not in / .

    13、准备工作完成

    14、开始打包


    dpkg-buildpackage

    15、打包成功,切回上级目录就可看到我们的helloworld的deb包
    cd ..
    ls后就会看到 hello_1.0-1_armhf.deb

    -------------------------------------------------------------------------------------

     这里有一个问题,执行hello报错,我自己捣鼓出了解决方法「可能只对我的机器适用---树梅派3b linux arm

     1.把deb下面的文件全删除,我们在来一次

        mkdir hello

        cd hello

        nano hello.c

    #include <stdio.h>
    int main()
    {
         printf("Hello world! "); 
         return 0;
    }

        nano Makefile

    all:
    gcc hello.c -o hello
    clean:

    .PHONY:all clean

     //这里执行的效果和上面是一样的咯

        sudo make

        sudo make clean

        cd ..

        mv hello hello-1.0

        cd hello-1.0

        dh_make --createorig

        输入s

        mkdir bin/

        cp hello bin/

        cd debian/

        nano install

    #!/bin/bash

    ./bin/hello   这里还是有个问题hello虽然被包含到bin里去了但是可能会后台执行这个hello,install里面写mkdir我写过,执行不了的,linux其他机器应该是可以

     cd ..

     cd..

     tar zcvf hello_1.0.orig.tar.gz hello-1.0

     cd hello-1.0

     sudo dpkg-buildpackage

    Finish:]

     sudo dpkg -i *.deb

    -------------------------------------------------------------------------------------------------------------

    下面我介绍一下debain里面脚本(没有的可以自己创建,就和上面install一样)

  • 相关阅读:
    10 种保护 Spring Boot 应用的绝佳方法
    Redis 如何分析慢查询操作?
    Spring Boot 主类及目录结构介绍
    Redis 再牛逼,也得设置密码!!
    Spring Data Redis 详解及实战一文搞定
    Spring Boot Redis Cluster 实战干货
    超详细的 Redis Cluster 官方集群搭建指南
    Redis Linux 安装运行实战全记录
    hdu 4790 Just Random (思路+分类计算+数学)
    poj 1328 Radar Installation(贪心)
  • 原文地址:https://www.cnblogs.com/Frank-dev-blog/p/9459516.html
Copyright © 2011-2022 走看看