# porting and packaging



## drforbin (Jun 19, 2021)

I know your suppose to read the porting guide to learn how to create your own ports.
But what do you read to learn how to create pkg (packages)?

DRF 

Thank you.


----------



## jmos (Jun 19, 2021)

Therefore the port is used. The port is the origin of a package. So the answer is still the porting guide.


----------



## drforbin (Jun 19, 2021)

Maybe I should be more specific. How do you create a package.tar.gz file fit for pkg install?


----------



## Vull (Jun 19, 2021)

`pkg create`. pkg-create(8)


----------



## drforbin (Jun 19, 2021)

Thank you!
Where does this formatting come from? Older version?






						Creating Custom Packages on FreeBSD | lastsummer.de
					

This series focuses on FreeBSD's pkg(8)/pkgng tool and how to use it away from the ports tree. TodaY: custom packages.



					lastsummer.de
				




and this 









						GitHub - freebsd/pkg: Package management tool for FreeBSD. Help at #pkg on Libera Chat or pkg@FreeBSD.org
					

Package management tool for FreeBSD. Help at #pkg on Libera Chat or pkg@FreeBSD.org - GitHub - freebsd/pkg: Package management tool for FreeBSD. Help at #pkg on Libera Chat or pkg@FreeBSD.org




					github.com


----------



## Vull (Jun 19, 2021)

Yes, I believe so.


----------



## Alexander88207 (Jun 19, 2021)

drforbin said:


> Maybe I should be more specific. How do you create a package.tar.gz file fit for pkg install?



If you have the port files you can do `make package`.

The package can be found at work/pkg.


----------



## SirDice (Jun 19, 2021)

Yep. If your port is good then the package will automatically created. Ports build packages, and it's that resulting package that gets installed.


----------



## drforbin (Jun 19, 2021)

Wonderful. What's the package format? I know it's a tar file but what's the file spec?


----------



## Alain De Vos (Jun 19, 2021)

I might tell stupidity but there is also, ARCHIVE_FORMAT, I think


----------



## drforbin (Jun 19, 2021)

ok...i guess


----------



## Vull (Jun 19, 2021)

It uses the .txz extension, is that what you mean? It's the LZMA2 compression format rather than GZIP which uses the .tar.gz and .tgz filename extensions. They can be created using tar -xz instead of tar -gz command line parameters. Edited to add: That last part was wrong. I don't know how they're created. `man tar` says the -z option only uses gzip compression. Maybe it's just an extension but I don't know. I type -czpf, -xzpf, and .tgz so automatically that I hardly ever think about it anymore. Sorry. Where the .txz files are concerned, I let `pkg` do all the compression and decompression for me.


----------



## drforbin (Jun 19, 2021)

No. I'm talking about the format of the pkg command.
please see










						GitHub - freebsd/pkg: Package management tool for FreeBSD. Help at #pkg on Libera Chat or pkg@FreeBSD.org
					

Package management tool for FreeBSD. Help at #pkg on Libera Chat or pkg@FreeBSD.org - GitHub - freebsd/pkg: Package management tool for FreeBSD. Help at #pkg on Libera Chat or pkg@FreeBSD.org




					github.com
				










						Creating Custom Packages on FreeBSD | lastsummer.de
					

This series focuses on FreeBSD's pkg(8)/pkgng tool and how to use it away from the ports tree. TodaY: custom packages.



					lastsummer.de


----------



## Vull (Jun 19, 2021)

I don't know. Never tried to do that.


----------



## drforbin (Jun 19, 2021)

Basicly the internal format of the pkg utility.
I know it uses tar file but what is the structure of the files and directory included in tar.


----------



## memreflect (Jun 20, 2021)

I got curious and investigated a bit.  I must first admit that the contents of this post are purely speculation as a result of experimentation and looking at makefile fragments and pkg-create(8).  If you need more authoritative information, you're likely going to need to review the C source for ports-mgmt/pkg.  The lack of additional documentation is probably because some implementation details are subject to change; perhaps pkg-create(8) will one day switch to TOML or some other file format in the future for example.

A package consists of two JSON files named +COMPACT_MANIFEST and +MANIFEST (in that order), followed by the actual files installed by the package.  If you're wondering why there are two manifest files inside a package, consider the fact that some packages install hundreds or even thousands of files; x11-themes/flat-remix-icon-themes has a pkg-plist that is 322236 lines long for example!  If using pkg-rquery(8) over a slow network connection, that's potentially a significant waste of time and resources for the server sending unneeded information.  That is one possible reason why pkg-rquery(8) cannot fetch a list of files and also why +COMPACT_MANIFEST is written to the archive first, though that is once again mere speculation on my part since I have not reviewed the C source.

Further digging seems to indicate that pkg-create(8) is responsible for creating those manifest files, but they are actually generated from other input files.  As confusing as it may be, one of those input files is also named +MANIFEST.  It's easier to see an example of that input file than for me to describe it, so below is the one generated by the default config for ports-mgmt/poudriere.  Compare the contents with "MANIFEST FILE DETAILS" in pkg-create(8):

```
sh$ make -C /usr/ports/ports-mgmt/poudriere 'WRKDIR=/tmp/poudriere-work' create-manifest
sh$ cat /tmp/poudriere-work/.metadir/+MANIFEST
name: "poudriere"
version: "3.3.6"
origin: ports-mgmt/poudriere
comment: <<EOD
Port build and test system
EOD
maintainer: bdrewery@FreeBSD.org
prefix: /usr/local
categories: [ ports-mgmt, ]
licenselogic: single
licenses: [ BSD2CLAUSE, ]
deps: { 
"ca_root_nss": {origin: "security/ca_root_nss", version: "3.63"}
"dialog4ports": {origin: "ports-mgmt/dialog4ports", version: "0.1.6"}
"freebsd-release-manifests": {origin: "misc/freebsd-release-manifests", version: "20210413"}
}
options: {
 BASH: on,
 CERTS: on,
 DIALOG4PORTS: on,
 EXAMPLES: on,
 QEMU: off,
 ZSH: on,
}
```
You might notice how JSON-like that is already.  pkg-create(8) seems to convert that imperfect JSON to valid JSON and combines that with some other information to create the +COMPACT_MANIFEST file; the +MANIFEST file included in the package is essentially the same file as +COMPACT_MANIFEST, except there is some additional information like the list of files installed and installation/deinstallation scripts, and pkg-repository(5) describes another use for +MANIFEST files.


----------



## Alain De Vos (Jun 20, 2021)

Fyi,








						GitHub - vstakhov/libucl: Universal configuration library parser
					

Universal configuration library parser. Contribute to vstakhov/libucl development by creating an account on GitHub.




					github.com


----------



## jmos (Jun 20, 2021)

drforbin said:


> I know it uses tar file but what is the structure of the files and directory included in tar.


Just extract one: `tar Jxvf package-1.23.txz`; You can also use the Midnight Commander (port/package "misc/mc") to enter a package file and see its content like real directories.
Basically there's a directory tree stripped down to the files of a software in it, as well as the license informations and two manifest file with all informations about dependencies, version, its port origin, short summary of the software etc.; But what is that information good for? If you want to create a package, go with the porters handbook.


----------

