# 4 newbie questions about porting process



## vecihi (Dec 18, 2012)

I am trying to implement steps of quick porting http://www.freebsd.org/doc/en/books/porters-handbook/quick-porting.html
It says "First, get the original tarball and put it into DISTDIR, which defaults to /usr/ports/distfiles." 

I have only 2 files in my application:

```
/usr/local/bin/vecihibin
/usr/local/etc/vecihi.conf
```


Question 1)
I created a tar ball of these files and I copied it to /usr/ports/distfiles/vecihi.tar.gz. But I didn't understand where Makefile, pkg-descr, pkg-plist files should be located? In tar ball or?

Makefile:

```
# $FreeBSD$

PORTNAME=	vecihi
PORTVERSION=	1.0b
CATEGORIES=	games
MASTER_SITES=	ftp://ftp.vecihi.com/contrib/

MAINTAINER=	vecihi@vecihi.org
COMMENT=	sleepy cat

MAN1=		vecihi.1
MANCOMPRESSED=	yes
USE_IMAKE=	yes

.include <bsd.port.mk>
```

Quesion 2)
In which folder should I run commands shown as below for testing? Should I define these calls in Makefile?


```
make install
make package
make deinstall
pkg_add package-name
make deinstall
make reinstall
make package
make readme
```

Question3)
How can I generate vecihi.tbz? I don't want to compile custom application with ports. I just want to use pkg_add pkg_delete commands for custom vecihi.tbz package.

Or if I want to install with ports /usr/ports/games/vecihi if I run *make install* in /usr/ports/games/vecihi; I want to install only 2 files again. 

Question4)
if I deinstall it I want to delete 1 file only: vecihibin. vecihi.conf shouldn't be erased. Can I do that?


----------



## SirDice (Dec 18, 2012)

A1) In the port's directory.

A2) In the port's directory.

A3) Using *make package* in the port's directory.

A4) Yes


----------



## wblock@ (Dec 18, 2012)

1. The port files go into /usr/ports/_category_/_portname_.  For example, rsync(1) is in /usr/ports/net/rsync.

2. Those commands are all executed from within the port directory, as in question 1.

3. Not clear what you're asking, but make package is what creates the package file.

4. If the conf file is standard (unmodified by the user), it should be deinstalled along with the rest.  This is an important part of ports, that you can uninstall them without leaving useless files.  If you want a per-user config, have the program read and write ~/.vecihi/vecihi.conf.  Or see http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/plist-config.html for a way to not delete port config files if they have been modified by the user.


----------



## vecihi (Dec 18, 2012)

Makefile:

```
# $FreeBSD$

PORTNAME=       vecihi
PORTVERSION=    1.0b
CATEGORIES=     games
MASTER_SITES=   ftp://192.168.1.40/

MAINTAINER=     vecihi@vecihi.org
COMMENT=        sleepy cat

MAN1=           vecihi.1
MANCOMPRESSED=  yes
USE_IMAKE=      yes

PLIST_FILES=    usr/local/bin/vecihibin \
                usr/local/etc/vecihi.conf


PLIST_DIRS=     usr/local/etc \
                usr/local/bin

.include <bsd.port.mk>
```


make package

```
builder# make package
===>  Building for vecihi-1.0b
make: don't know how to make Makefile. Stop
*** Error code 1

Stop in /usr/ports/games/vecihi.
package-builder# make clean
===>  Cleaning for vecihi-1.0b
package-builder# make package
===>  Extracting for vecihi-1.0b
=> No checksum file (/usr/ports/games/vecihi/distinfo).
===>  Patching for vecihi-1.0b
===>   vecihi-1.0b depends on executable: imake - found
===>  Configuring for vecihi-1.0b
imake -DUseInstalled -I/usr/local/lib/X11/config
imake: No such file or directory
imake: No description file.
  Stop.
===>  Building for vecihi-1.0b
make: don't know how to make Makefile. Stop
*** Error code 1

Stop in /usr/ports/games/vecihi.
```

what the cause of this error message? it s related with imake but i didn't understand clearly the role of imake ...

i change USE_IMAKE = NO

Result:

```
builder# make package
===>  Building for vecihi-1.0b
make: don't know how to make Makefile. Stop
*** Error code 1

Stop in /usr/ports/games/vecihi.
```


----------



## SirDice (Dec 18, 2012)

Remove the USE_IMAKE from your Makefile. Unless your source requires to be build with imake(1) you don't need it.


----------



## vecihi (Dec 19, 2012)

I removed USE_IMAKE


```
builder# cat /usr/ports/games/vecihi/Makefile
# $FreeBSD$

PORTNAME=       vecihi
PORTVERSION=    1.0b
CATEGORIES=     games
MASTER_SITES=   ftp://192.168.1.40/

MAINTAINER=     vecihi@vecihi.org
COMMENT=        sleepy cat

MAN1=           vecihi.1
MANCOMPRESSED=  yes

PLIST_FILES=    usr/local/bin/vecihibin \
                usr/local/etc/vecihi.conf


PLIST_DIRS=     usr/local/bin \
                usr/local/etc

                vecihi-1.0b/opt/vecihi/sbin
.include <bsd.port.mk>
```


```
builder# cd /usr/ports/games/vecihi/
builder# make
===>  Building for vecihi-1.0b
make: cannot open Makefile.
*** Error code 1

Stop in /usr/ports/games/vecihi.
```
Question-)
I need another file Makefile. I just want to copy bins to PLIST_DIRS. I don't want to compile anything. In work/vecihi-1.0b/Makefile file should I define install deinstall functions? Or what I need?


```
builder# touch work/vecihi-1.0b/Makefile
builder# make
===>  Building for vecihi-1.0b
make: don't know how to make all. Stop
*** Error code 1

Stop in /usr/ports/games/vecihi.
```


----------



## vecihi (Dec 19, 2012)

I solved it. The problem was space characters.

/usr/ports/games/vecihi/work/vecihi-1.0b/Makefile  (I extracted vecihi-1.0b.tar.gz to /usr/ports/games/vecihi/work/vecihi-1.0b manually)

```
# A simple Makefile
all:
        echo "test"
```

it works like a charm...

question:
Why *make all* command didn't create /usr/ports/games/vecihi/work/vecihi-1.0b folder automatically? (I extracted vecihi-1.0b.tar.gz to /usr/ports/games/vecihi/work/vecihi-1.0b manually)



```
builder# cd /usr/ports/games/vecihi/
builder# make all
===>  Extracting for vecihi-1.0b
=> No checksum file (/usr/ports/games/vecihi/distinfo).
===>  Patching for vecihi-1.0b
===>  Configuring for vecihi-1.0b
===>  Building for vecihi-1.0b
cd: can't cd to /usr/ports/games/vecihi/work/vecihi-1.0b
```


----------



## vecihi (Dec 19, 2012)

solution:
we should have vecihi-1.0b folder in tar ball. actually it automatically extract tar ball to work/ dir...

thank you all for helps


----------



## vecihi (Dec 19, 2012)

Question-1)
*make all* is successful now. And I will add shell script to Makefile for copying files to required locations. But how can I register port installation to /var/db/pkg/. I want to see installed package (vecihi-1.0b) with pkg_info and I want to create package with make package too.

Question-2) Should I define install:  deinstall: package: make calls in /usr/ports/games/vecihi/work/vecihi-1.0b/Makefile? 
I read apache22's Makefile for learning more


Information about files that I used:

```
cat /usr/ports/games/vecihi/work/vecihi-1.0b/Makefile
# A simple Makefile
all:
        echo "test"
```



```
builder# make all
===>  Extracting for vecihi-1.0b
=> No checksum file ([color="rgb(0, 100, 0)"]/usr/ports/games/vecihi/distinfo[/color]).
===>  Patching for vecihi-1.0b
===>  Configuring for vecihi-1.0b
===>  Building for vecihi-1.0b
echo "test"
test
```



```
builder# make install
===>  Installing for vecihi-1.0b
===>   Generating temporary packing list
===>  Checking if games/vecihi already installed
make: don't know how to make install. Stop
*** Error code 2

Stop in /usr/ports/games/vecihi.
```

thanks


----------



## SirDice (Dec 19, 2012)

vecihi said:
			
		

> Question-2) Should I define install:  deinstall: package: make calls in /usr/ports/games/vecihi/work/vecihi-1.0b/Makefile?


No, the ports system takes care of those. And you don't need a Makefile for your sources, there's nothing to compile.


----------



## wblock@ (Dec 19, 2012)

vecihi said:
			
		

> Makefile:
> 
> ```
> PLIST_FILES=    [color="Red"]usr/local/[/color]bin/vecihibin \
> ...



Do not hardcode paths like that.  Use ${PREFIX} instead.

If your program is already compiled, use NO_BUILD= YES.


----------



## vecihi (Dec 21, 2012)

Makefile: (cat /usr/ports/games/vecihi/Makefile)

```
# $FreeBSD$

PORTNAME=	vecihi
PORTVERSION=	1.0b
CATEGORIES=	games
MASTER_SITES=	http://192.168.1.40/

MAINTAINER=	vecihi@vecihi.org
COMMENT=	sleepy cat

MAN1=		vecihi.1
MANCOMPRESSED=	yes
[color="DarkGreen"]NO_BUILD=	yes[/color]
PLIST_FILES=    ${PREFIX}/bin/vecihibin \
                ${PREFIX}/etc/vecihi.conf


PLIST_DIRS=     ${PREFIX}/etc \
                ${PREFIX}/bin
.include <bsd.port.mk>
```


```
builder# make clean
===>  Cleaning for vecihi-1.0b
```


```
builder# make 
===>  Extracting for vecihi-1.0b
=> No checksum file (/usr/ports/games/vecihi/distinfo).
===>  Patching for vecihi-1.0b
===>  Configuring for vecihi-1.0b
```


```
builder# make install
===>  Installing for vecihi-1.0b
===>   Generating temporary packing list
===>  Checking if games/vecihi already installed
[color="Red"]make: don't know how to make install. Stop
*** Error code 2[/color]

Stop in /usr/ports/games/vecihi.
```


if i add

```
do-install:
	@${ECHO_MSG} "test"
```
to " /usr/ports/games/vecihi/Makefile " i got:

```
"Makefile", line 52: warning: duplicate script for target "do-install" ignored
```


Question-)
for installing with make install what changes should be done in Makefile?


----------



## SirDice (Dec 21, 2012)

If I have problems getting a port to do what I need I always try to look at an existing port that does something similar. Have a look at the Makefile of ports-mgmt/portmaster, it's relatively simple and, like your port, doesn't actually build anything.


----------



## vecihi (Dec 24, 2012)

if i set PREFIX to another place than        /usr/local    

```
PREFIX=  /opt
```
port system creates subfolders in /opt:

```
builder# ls [color="DarkGreen"]/opt/[/color]
bin             include         vecihi        libdata         man             share
etc             info            lib             libexec         sbin            www
```

if i set PREFIX= / (root)...  and if port system creates subdirectories in ( / ) it won't be good i think.

how can i prevent this? 

i know it s not suitable for freebsd's directory structure but it s not public port, i want to install port to another directory than   /usr/local


----------



## oops (Dec 28, 2012)

vecihi said:
			
		

> port system creates subfolders in /opt:
> 
> ```
> builder# ls [color="DarkGreen"]/opt/[/color]
> ...


During install Mk/bsd.port.mk uses mtree(8) to populate PREFIX with basic subdirectories according to Templates/BSD.local.dist. To avoid this just define NO_MTREE in the port's Makefile.


----------



## vecihi (Jan 24, 2013)

Question)

I'm creating custom vecihi.tbz package with: 

```
builder# cd /usr/ports/games
builder# make package-recursive
```
Then, I can see vecihi port installed successfuly with pkg_info on builder machine. And subdirectories (output and logs) created successfuly in /usr/local/vecihi folder. And package (vecihi.tbz) created in /usr/ports/packages/All/ folder.


But if I install package (vecihi.tbz) to another machine with pkg_add, subdirectories (output and logs)   are missing...

Makefile:

```
# $FreeBSD: ports/security/VECIHI//Makefile $

VECIHIDIR=	[color="SeaGreen"]vecihi[/color]
[color="Red"]VECIHIOUTPUT=	output
VECIHILOGS=	logs[/color]
...

.include <bsd.port.pre.mk>

do-install:
	[color="Green"]${MKDIR} ${PREFIX}/${VECIHIDIR}[/color]
[color="Red"]	${MKDIR} ${PREFIX}/${VECIHIDIR}/${VECIHILOGS}	
	${MKDIR} ${PREFIX}/${VECIHIDIR}/${VECIHIOUTPUT}	[/color]
	@${CHOWN} -R itap ${PREFIX}/${VECIHIDIR}
	(cd ${WRKSRC}${PREFIX}/${VECIHIDIR} && ${COPYTREE_SHARE} \* ${PREFIX}/${VECIHIDIR})
	
...
```
Red directives are not working correctly with pkg_add.

How can i fix it?


----------



## SirDice (Jan 24, 2013)

Check the pkg-plist file. It's this file that's used for packaging.


----------



## vecihi (Jan 24, 2013)

Actually output/ and log/ directories are defined in Makefile: those directories are empty.


```
PLIST_FILES=    usr/local/vecihi/bin/vecihibin \
                usr/local/vecihi/conf/vecihi.conf


PLIST_DIRS=     usr/local/vecihi/conf \
                usr/local/vecihi/bin \
[color="green"]                usr/local/vecihi/output \
                usr/local/vecihi/logs[/color]
```
I don't want to add those directories to PLIST_DIRS because when i removed package those directories should be there... i don't want to uninstall output/logs.

- Why those empty directories are created successfuly on the builder machine with port installation method (make package-recursive)? 

- And why not with pkg_add on another machine?

Thanks


----------



## vecihi (Jan 28, 2013)

*Solution:*
Empty directories created during port installation need special attention. They will not get created when installing the package, because packages only store the files, and pkg_add creates directories for them as needed. To make sure the empty directory is created when installing the package, add this line to pkg-plist above the corresponding @dirrm line:


```
@exec mkdir -p %D/share/foo/templates
```
http://www.freebsd.org/doc/en/books/porters-handbook/plist-cleaning.html



			
				vecihi said:
			
		

> Actually output/ and log/ directories are defined in Makefile: those directories are empty.
> 
> 
> ```
> ...


----------

