# Where to find the downloaded source code?



## Newfinder (Mar 19, 2018)

The question might sound silly, but... how can I take a look into the actual source code of a port? While doing make install or make fetch it downloads a tarball and extracts it... where? 
I couldn't find any hint neither in the handbook, nor by googling. So before I go to compare ZFS snapshots, maybe it's better just to ask 
Thanks


----------



## Minbari (Mar 19, 2018)

Inside the port in the work directory.


----------



## ShelLuser (Mar 19, 2018)

Newfinder said:


> how can I take a look into the actual source code of a port? While doing make install or make fetch it downloads a tarball and extracts it... where?


Depends on the port, check the ports(7) manualpage for an overview of all the available build targets, The targets extract and patch could be useful here. One merely extracts the port, the other does the above and applies the patches which the port maintainer made.

But be warned though: just because it's a port doesn't imply that it also provides and/or uses any actual source code. Some port maintainers rely on pre-build packages and there are also closed-source ports available. So this also heavily depends on the port you're using.


----------



## tobik@ (Mar 20, 2018)

The sources are extracted under the working directory which you can get with `make -V WRKDIR` in the port's directory. `make -V WRKSRC` will also point you to the unpacked sources directly.

As Minbari said the working directory is under work/ in the port's directory by default, but it doesn't really have to be depending on your settings and environment.


----------



## Newfinder (Mar 20, 2018)

Extract is exactly what I was missing! After "make extract" the "work" directory appeared in the port. 
Thanks a lot


----------



## Deleted member 48958 (Mar 20, 2018)

Newfinder said:


> Where to find the downloaded source code?


/usr/src 



Newfinder said:


> The question might sound silly, but... how can I take a look into the actual source code of a port? While doing make install or make fetch it downloads a tarball and extracts it... where?


/usr/ports/your/port/work

before you need to execute:
`% cd /usr/ports/your/port/`
`% su`
`# make fetch extract`


----------



## tobik@ (Mar 20, 2018)

ILUXA said:


> before you need to execute:
> % cd /usr/ports/your/port/
> % sudo make fetch extract



fetch is already implied by extract so it's not necessary to specify it.
Please don't fetch/extract/build things as root. :-(  The only stage that needs to be run as root is install. Everything else can be run as a regular user if permissions on the ports tree, /var/db/ports, WRKDIRPREFIX, and DISTDIR are set correctly.


----------



## Deleted member 48958 (Mar 20, 2018)

tobik@ said:


> Please don't fetch/extract/build things as root


Why? Is it dangerous to use it in ports tree? 
Anyway you build and extract everything as root, 
while donig `# make install` Or no?



tobik@ said:


> fetch is already implied by extract so it's not necessary to specify it.


I always use every argument with `# make` (or I use portmaster instead),
so when I want to patch, I use `# make fetch extract patch`
And when I want to "configure"…  History search in your shell helps a lot in such cases.


----------



## tobik@ (Mar 20, 2018)

ILUXA said:


> Why? Is it dangerous to use it in ports tree?


Of course it is. You're fetching third-party sources, which often contains shell scripts with thousands of lines of code which do who knows what.


ILUXA said:


> Anyway you build and extract everything as root,
> while donig  # make install Or no?


No, if you run `make install` as a regular user the ports framework will build everything as that user and only when everything is built, will escalate to root via su(1) to actually install files into the system.


----------



## Deleted member 48958 (Mar 20, 2018)

tobik@ said:


> No, if you run  make install as a regular user the ports framework will build everything as that user and when everything is built, will escalate to root via su(1) to actually install files into the system.


Never used that thing 
I always installed ports as root. And while I'm still alive for today, and I don't think it is a big problem (in my opinion ).


----------



## Newfinder (Mar 20, 2018)

tobik@ said:


> No, if you run `make install` as a regular user the ports framework will build everything as that user and only when everything is built, will escalate to root via su(1) to actually install files into the system.



The rights by default are set to drwxr-xr-x root  wheel. I'll probably have to add +w to the wheel group  Otherwise make install indeed asks for root password couple of times (for every dependency I assume) but them randomly fails.


----------



## Deleted member 48958 (Mar 21, 2018)

BTW, it will be a great feature IMO, if ports will be built in ~/.work/ by default.


----------



## SirDice (Mar 22, 2018)

ILUXA said:


> BTW, it will be a great feature IMO, if ports will be built in ~/.work/ by default.


Set WRKDIRPREFIX to it. It can be set in /etc/make.conf or your own environment.


----------



## Deleted member 48958 (Mar 22, 2018)

SirDice said:


> Set WRKDIRPREFIX to it. It can be set in /etc/make.conf or your own environment.


Yes, it really works, there is no need to use sudo or su,
to fetch and extract, but, unfortunately, it starts asking password for every dependency,
when you try to build a port and it is annoying IMHO a little bit.





Also working directory paths are a little bit too long,
it is like /home/iluxa/.work/usr/ports/x11/xscreensaver/work/xscreensaver-5.38.

Anyway, it should be safe to build, fetch, extract and install ports in their directories and as root,
because it checks "SHA256 Checksum" every time it fetches port sources.


----------



## tobik@ (Mar 22, 2018)

ILUXA said:


> Also working directory paths are a little bit too long,
> it is like /home/iluxa/.work/usr/ports/x11/xscreensaver/work/xscreensaver-5.38.


Just use `cd `make -V WRKSRC`` if you need to go to it. You can make it a shell alias too.


ILUXA said:


> Yes, it really works, there is no need to use sudo or su,
> to fetch, extract, but unfortunately it starts asking passwords for every dependency,
> when you try to build a port and it is annoying IMHO a little bit.


Well that's because it's using su(1) which doesn't cache credentials like sudo(8). You can use sudo by setting

```
SU_CMD=/usr/local/bin/sudo -E sh -c
```
 in /etc/make.conf.


----------

