How can we create .deb packages using Makefile in ubuntu. Can anyone explain.am new in 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
How to add lines to this makefile to create .deb packages after using the command sudo make
To create a Debian package in general, you need to have two directory trees: one with the actual files you want to package, and one with the control information for the package. You'll need a tree somewhat like this one:
The file
controlis a text file with some mandatory fields as documented inman dpkg-control.To create a Debian package, refer to
man dpkg-deb. The command line to do it looks like thisReading your
Makefile, it looks as if you created your binaries in abinright below the project root. So you would either need to create them somewhere else or copy them into a tree for package creation.Assuming all your files (DEBIAN and installation) reside in a directory
package, these are the lines you would need to put into yourMakefile:A variable to contain the version will make things easier. (Hint: there's also version information in the
controlfile and they should not contradict each other. You can set one from the other with a line of script.) The target architecture is only known to you.Note that above is a very minimal example. There's lots of optional and highly useful functionality you can leverage. For further reading, refer to the Debian docs on Control files and Package maintainer scripts.
It might also be worthwhile to read the GNU Make Manual. Notably, your
Makefiledoes not define any prerequisites for the targets (which is a prime motivation for usingmakein the first place) and.PHONY: alldoes not do what the comment says. In fact, it does nothing because there's no target namedall.Start with the manual's introduction and move on until you get an impression how
Makefiles work. Then consider doing an overhaul of yourMakefilewith your newly gained knowledge. It's really well-documented and straightforward.