# How to obtain source for a given pkg



## balanga (Oct 22, 2022)

What is the recommended way of obtaining the source for a given pkg from the github freebsd ports tree?

Should I use git clone?

How would I start off if I wanted to build sysutils/atop ?


----------



## dgmm (Oct 22, 2022)

cd /usr/ports/sysutils/atop
make install clean

If you want to see and/or play with the source code then before building the port:

make fetch extract


----------



## Alain De Vos (Oct 22, 2022)

go to "/usr/ports/sysutils/atop"
perform "make patch"
Now you can see all the sources in "./work/atop-freebsd-atop-2.0.2.fbsd.beta3"


----------



## balanga (Oct 22, 2022)

dgmm said:


> cd /usr/ports/sysutils/atop
> make install clean
> 
> If you want to see and/or play with the source code then before building the port:
> ...


Thanks, but what I meant was how to get the source from github.


----------



## W.hâ/t (Oct 22, 2022)

hurrrm.. https://github.com


----------



## tyson (Oct 23, 2022)

Did you mean FreeBSD ports tree source? If yes then you can just clone https://github.com/freebsd/freebsd-ports  into /ust/ports.
If you mean specific port source package … you can get it the way others just showed you up in this thread, but you have to have ports under /use/ports.


----------



## Alain De Vos (Oct 23, 2022)

GitHub - samm-git/atop-freebsd: atop system utility - FreeBSD port
					

atop system utility - FreeBSD port. Contribute to samm-git/atop-freebsd development by creating an account on GitHub.




					github.com


----------



## balanga (Oct 23, 2022)

W.hâ/t said:


> hurrrm.. https://github.com


I'm perfectly aware of github thank you. What I want to know is how you are supposed download a pkg from github.


----------



## Phishfry (Oct 23, 2022)

You dont usually download single ports because of dependencies you download the whole tree.
`portsnap auto`

It is possible to download single port but I bet you need more.

You then build packages from ports.
`cd /usr/ports/sysutils/atop`
`make pkg`
Then you can scape packages.


----------



## Phishfry (Oct 23, 2022)

Looking at freshports sysutils/atop there are no dependencies. So download the single port and build your package.


----------



## balanga (Oct 23, 2022)

tyson said:


> Did you mean FreeBSD ports tree source? If yes then you can just clone https://github.com/freebsd/freebsd-ports  into /ust/ports.
> If you mean specific port source package … you can get it the way others just showed you up in this thread, but you have to have ports under /use/ports.


Are you saying I need to 'git clone' the whole ports tree if I just want to build a single pkg?


----------



## Phishfry (Oct 23, 2022)

No. It comes down to dependencies. None means all good.


----------



## balanga (Oct 23, 2022)

Phishfry said:


> You dont usually download single ports because of dependencies you download the whole tree.
> `portsnap auto`
> 
> It is possible to download single port but I bet you need more.
> ...


It's ages since I built anything and have forgotten about how to get started, so thanks for reminder about portsnap.


----------



## Phishfry (Oct 23, 2022)

For a single freestanding package you could use git-lite.
`pkg install git-lite`
Then clone your desired port.
`git clone https://github.com/freebsd/freebsd-ports/tree/main/sysutils/atop /usr/ports`


----------



## jmos (Oct 23, 2022)

tyson said:


> but you have to have ports under /use/ports.


To be more specific: You can have a port wherever you want it to be - just the missing build and run dependencies of your "somewhere port" are expected to be found in /usr/ports.


----------



## jmos (Oct 23, 2022)

balanga said:


> What is the recommended way of obtaining the source for a given pkg from the github freebsd ports tree?


So you want a port to build a FreeBSD package, and not just compiling the source of a software; A port assumes an environment: The ports tree. A port may (but mustn't) depend on other ports a) for build, and b) to be executed. If you are willing to solve both dependencies by yourself you could go with just the files of that one port, but: In most cases you won't have much fun with this - some depend on +100 others.

So you're asking of the "recommended way": That is to get the whole ports tree. You could use "git" or "portsnap" to get it, but I would recommend the port/package "gitup" (just execute `gitup ports`).


----------



## astyle (Nov 1, 2022)

balanga said:


> Are you saying I need to 'git clone' the whole ports tree if I just want to build a single pkg?


If you want to find the source for a package, it takes doing some research.

The FreeBSD ports tree is merely the infrastructure to pull in source tarballs and compile them properly for your system. If you want to read the code of what's inside the tarball itself, you can look the package up on freshports, and see where the tarballs are published. This is where the ports infrastructure downloads the tarball from.

Another way to look at a package source tarball is in /usr/ports/distfiles.

But frankly, I'd recommend getting the whole ports tree in one go. This will save the headaches of hunting down deps later if what you have locally is outdated for the port you want.

Updating any given package - now that's a different bowl of fish, and invites dependency hell. However, that is something that all of Open Source Software is living with - BSD, Linux, you name it. Even Android is not great at updating single apps. Apple and Microsoft are closed source, and have their own ways of dealing with updates. However, they also have other, rather unrelated issues that drove me to FreeBSD...


----------



## patmaddox (Nov 3, 2022)

balanga said:


> Are you saying I need to 'git clone' the whole ports tree if I just want to build a single pkg?


Pretty much, yes.

The reason is because ports building depends on bsd.port.mk and all the files it includes. There may be tools that allow you to build ports without a ports tree, but at the most basic level, you need the port-building infrastructure in `ports/Mk`.

Here's the process I use to view the source for a particular package (in this case I'll use `poudriere-devel`).

1. Look at the Makefile.
2. See where the sources point to – in this case, it has `GH_TAGNAME= 3.3.0-1135-g137c376a8`
3. Look up that tag on GitHub: https://github.com/freebsd/poudriere/tree/3.3.0-1135-g137c376a8

That's if you want to explore the code online (which I do).

Another option is to use the fetch target to download the source code.


----------

