在linux中使用Makefile创建.debs

问题描述 投票:0回答:1

如何在ubuntu中使用Makefile创建.deb包。 谁能解释一下。Makefile 是新的。

OSARCH := "linux/amd64 linux/386 windows/amd64 windows/386 darwin/amd64 darwin/386"
ENV = /usr/bin/env
VERSION=$(shell git describe --dirty --tags --always)

.SHELLFLAGS = -c # Run commands in a -c flag 
.SILENT: ; # no need for @
.ONESHELL: ; # recipes execute in same shell
.NOTPARALLEL: ; # wait for this target to finish
.EXPORT_ALL_VARIABLES: ; # send all vars to shell

.PHONY: all # All targets are accessible for user
.DEFAULT: help # Running Make will run the help target

help: ## Show Help
        @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

dep: ## Get build dependencies
        go get -v -u github.com/golang/dep/cmd/dep

ensure: ## update dependencies
        dep ensure

build: ## Build the app
        for gomodule in  $$(go list ./... | grep -vE 'x1|x2|x3|x4|x5|myself|rfc****') ; do
                go build -gcflags "-N -l" -ldflags "-X main.version=$(VERSION) -s -w"  -o bin/$$(basename $$gomodule).s $$gomodule
                upx --force -qq -o bin/$$(basename $$gomodule) bin/$$(basename $$gomodule).s > /dev/null
        done

test: ## Launch tests
        go test -v ./...

clean: ## Launch clean
        go clean ./...
        rm -rf bin

install: ## Launch install
        go install -ldflags "-X main.version=$(VERSION)" $$(go list ./... | grep -v test)

test-cover: ## Launch tests coverage and send it to coverall
        $(ENV) ./scripts/test-coverage.sh

如何在使用命令后向此 makefile 添加行以创建 .deb 包

sudo make

linux makefile deb
1个回答
0
投票

一般来说,要创建 Debian 软件包,您需要有两棵目录树:一棵包含要打包的实际文件,一棵包含软件包的控制信息。你需要一棵像这样的树:

+ DEBIAN
| + control
+ files
  + bin
  | + myapp
  + lib
  | + libmyapp.so
  + etc
  | + myconfig
  ...

文件

control
是一个文本文件,其中包含一些必填字段,如
man dpkg-control
中所述。

要创建 Debian 软件包,请参阅

man dpkg-deb
。执行此操作的命令行如下所示

dpkg-deb --build files my-package_<version>_<arch>.deb

从您的

Makefile
来看,您似乎是在项目根目录正下方的
bin
中创建了二进制文件。因此,您要么需要在其他地方创建它们,要么将它们复制到树中以创建包。

假设您的所有文件(DEBIAN 和安装)都位于目录

package
中,这些是您需要放入
Makefile
中的行:

package: <artifacts you want to package>
    dpkg-deb --build package my-package_<version>_<arch>.deb

包含版本的变量将使事情变得更容易。目标架构只有你自己知道。

如需进一步阅读,请参阅 Debian 文档中的 控制文件包维护者脚本

阅读GNU Make 手册也可能是值得的。值得注意的是,您的

Makefile
没有定义目标的任何先决条件(这是首先使用
make
的主要动机)并且
.PHONY: all
不执行评论所说的操作。事实上,它什么也没做,因为没有名为
all
的目标。

© www.soinside.com 2019 - 2024. All rights reserved.