# "Hello world" ports example: help request



## Deleted member 67440 (Apr 3, 2021)

I am new to ports (and pkg) development for FreeBSD.

I would like to know, please, if there is a complete example of a very simple "Hello world" port. 

In fact, it is not very easy, at least at the beginning, to disentangle the numerous complications 
(ex g ++ vs clang).

I found a lot of information about it but, almost always, related to extremely complex projects to compile, with very difficult configuration files, for a beginner at least.

Basically I have a project consisting of two .cpp (zpaq.cpp and libzpaq.cpp) files and one .h (libzpaq.h) that I would like to make available to the BSD world.

It is a fork of a compressor with deduplication, in my opinion the most advanced in the category.








						GitHub - fcorbelli/zpaqfranz: Deduplicating archiver with encryption and paranoid-level tests. Swiss army knife for the serious backup and disaster recovery manager. Ransomware neutralizer. Win/Linux/Unix
					

Deduplicating archiver with encryption and paranoid-level tests. Swiss army knife for the serious backup and disaster recovery manager. Ransomware neutralizer. Win/Linux/Unix - GitHub - fcorbelli/z...




					github.com
				




So I would like to do the relative port first (in archivers) and then also the binary version, for pkg add.

The "make" is just like that
g++ -O3 -march=native -Dunix zpaq.cpp libzpaq.cpp -pthread -o zpaqfranz -static-libstdc++ -static-libgcc
or
clang++ -march=native -Dunix zpaq.cpp libzpaq.cpp -pthread -o zpaqfranz -static

Creating a single executable (zpaqfranz) to be putted into /usr/local/bin
Thanks for any reply


----------



## SirDice (Apr 3, 2021)

fcorbelli said:


> I would like to know, please, if there is a complete example of a very simple "Hello world" port.





			Chapter 3. Quick Porting


----------



## George (Apr 3, 2021)

1. This is a ports Makefile that could work with your port:

```
# $FreeBSD$

PORTNAME=    zpaqfranz
DISTVERSION=    5.23
CATEGORIES=    sysutils

MAINTAINER=    random.mail@web.de
COMMENT=       Journaling archiver for incremental backups

LICENSE=    BSD2CLAUSE

USE_GITHUB=    yes
GH_ACCOUNT=    fcorbelli

PLIST_FILES=    bin/zpaqfranz

do-install:
    ${INSTALL_PROGRAM} work/${PORTNAME}-${DISTVERSION}/${PORTNAME} ${STAGEDIR}${LOCALBASE}/bin

.include <bsd.port.mk>
```
Then, you'd still need a license file (github can do that for you), and a plaintext file called pkg-descr.

2. I only know cases where the original project (source code) has a Makefile as well, e.g. this copy and pasted
example Makefile:

```
CC?=cc
#add compiler flags here:
CFLAGS+= -rdynamic

SOURCES= *.cpp

all: zpaqfranz

zpaqfranz: $(SOURCES)
    $(CC) -o zpaqfranz $(SOURCES) $(CFLAGS)
```

3. Then, to test build the port once, you need to run `make makesum`, `make install` in a folder that contains both the ports Makefile and pkg-descr. Maybe this is of some help.. Check the porters handbook, too.


----------



## kpedersen (Apr 3, 2021)

Perhaps also consider looking at a very simple port. Traditionally I used to look at curl or wget but admittedly these have both become a little bit stupid in terms of complexity now.

Maybe ufetch instead:





						[ports] Index of /head/sysutils/ufetch
					






					svnweb.freebsd.org


----------



## tingo (Apr 3, 2021)

sysutils/disktype is another uncomplicated port.


----------



## SirDice (Apr 3, 2021)

If you don't have a Makefile for your code you can add a `do-build:` target to the port's Makefile. If there's no `do-build` target then it's going to default to running make(1) in the source directory.


----------



## Deleted member 67440 (Apr 3, 2021)

Thank you all.
Today I worked on a development (multithreaded hash calculation). Soon I will try to follow the advices.

PS the quickport was the first thing I read, but frankly I didn't find it very useful.


----------



## Alexander88207 (Apr 3, 2021)

fcorbelli said:


> know, please, if there is a complete example of a very simple "Hello world" port.



Here is an more advanced hello world port i guess https://reviews.freebsd.org/source/ports/browse/head/x11-themes/pop-gtk-themes/Makefile


----------



## Deleted member 67440 (Apr 4, 2021)

Thanks to the help I wrote a Makefile that "almost" works. The problem is the compiler call, which is usually clang ++ or gcc (rarely gcc7).
If I set it hardcoded it works (as in the example).
How can I make it "universal", ie it works with both clang, gcc and gcc7?


```
#this is the problem: the compiler
CC?=            cc
INSTALL?=       install
RM?=            rm
PROG=           zpaqfranz
CFLAGS=         -O3  -Dunix
LDADD=          -static -pthread
PREFIX?=        /usr/local
BINDIR=         ${PREFIX}/bin
BSD_INSTALL_PROGRAM?=   install -m 0555

all:    build

build:  ${PROG}

install:        ${PROG}
        ${BSD_INSTALL_PROGRAM} ${PROG} ${DESTDIR}${BINDIR}

${PROG}:        ${OBJECTS}
        clang++  ${CFLAGS} zpaqfranz.cpp -o ${PROG} ${LDADD}
clean:
        ${RM} -f ${PROG}
```

It's probably trivial, but I think it's the last step before trying the big step (the port). Thanks for any indication.

PS
I tried to make things as simple as possible: now the source is composed of a single file which can therefore be compiled without any particular problems. For the clean I brutally put a cancellation. Besides "install" and "clean" do I need any other make commands?


----------



## Deleted member 67440 (Apr 4, 2021)

I have a second problem.
Here is the first port I prepared


			http://www.francocorbelli.it/zpaqfranz/51-26.zip
		


Here the package


			http://www.francocorbelli.it/zpaqfranz/zpaqfranz-51.26.tar.gz
		


The problem should be trivial, an incorrect path, because I get

```
root@aserver:/tmp/zpaqquickport # make DISABLE_VULNERABILITIES=yes install
===>   zpaqfranz-51.26 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by zpaqfranz-51.26 for building
===>  Extracting for zpaqfranz-51.26
=> SHA256 Checksum OK for zpaqfranz-51.26.tar.gz.
===>  Patching for zpaqfranz-51.26
===>  Configuring for zpaqfranz-51.26
===>  Building for zpaqfranz-51.26
cd: /tmp/zpaqquickport/work/zpaqfranz-51.26: No such file or directory
*** Error code 2

Stop.
make: stopped in /tmp/zpaqquickport
root@aserver:/tmp/zpaqquickport # ls work
.configure_done.zpaqfranz._usr_local    Makefile
.extract_done.zpaqfranz._usr_local      zpaqfranz.cpp
.patch_done.zpaqfranz._usr_local
root@aserver:/tmp/zpaqquickport #
```

In fact the Makefile (for compiling) and zpaqfranz.cpp are not putted into ./work/zpaqfranz-51.26 subdir.

...but... why?

this is the Makefile of the port

```
# $FreeBSD$

PORTNAME=       zpaqfranz
DISTVERSION=    51.26
CATEGORIES=     archivers
MASTER_SITES=   http://www.francocorbelli.it/zpaqfranz

MAINTAINER=     franco@francocorbelli.com
COMMENT=        Swiss army knife for the serious backup and disaster recovery manager

.include <bsd.port.mk>
```
and the pkg-plist


```
bin/zpaqfranz
```


----------



## Alexander88207 (Apr 4, 2021)

fcorbelli said:


> In fact the Makefile (for compiling) and zpaqfranz.cpp are not putted into ./work/zpaqfranz-51.26 subdir.
> 
> ...but... why?
> 
> ...








For downloads the portname with port/distversion is directly attached in to link when trying to download your archive.
You can do test it when you clean your /usr/ports/distfiles.

Normally the source code is always expected into a folder in the archive. Since your files are loose no folder was created and therefore the error.









						Chapter 5. Configuring the Makefile
					

Configuring the Makefile for FreeBSD Ports




					docs.freebsd.org


----------



## Deleted member 67440 (Apr 5, 2021)

I leave what I have done so far, maybe it will be useful to other users in my situation

The software consists of a single .cpp which becomes a single executable (maybe!)

*Makefile*

```
#51.27
CC?=            cc
INSTALL?=       install
RM?=            rm
PROG=           zpaqfranz
CFLAGS=         -O3 -march=native -Dunix
LDADD=          -static -pthread -lstdc++ -lm
BINDIR=         /usr/local/bin
BSD_INSTALL_PROGRAM?=   install -m 0555

all:    build

build:  ${PROG}

install:        ${PROG}
        ${BSD_INSTALL_PROGRAM} ${PROG} ${DESTDIR}${BINDIR}

${PROG}:        ${OBJECTS}
        ${CC}  ${CFLAGS} zpaqfranz.cpp -o ${PROG} ${LDADD}
clean:
        ${RM} -f ${PROG}
```

*Port's Makefile*
Please note the dammed portlint check

```
# $FreeBSD$

PORTNAME=       zpaqfranz
DISTVERSION=    51.10
CATEGORIES=     archivers
MASTER_SITES=   http://www.francocorbelli.it/zpaqfranz/

MAINTAINER=     franco@francocorbelli.com
COMMENT=        Swiss army knife for the serious backup and disaster recovery manager

LICENSE=        BSD2CLAUSE MIT
LICENSE_COMB=   dual

WRKSRC=         ${WRKDIR}

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

*pkg-descr*

```
ZPAQ fork with additional features,
mainly in the context of verification
and control of backups.

Swiss army knife for the serious backup and
disaster recovery manager.

About like 7z or RAR on steroids.
Many of them.

Runs on:
Windows, Linux, FreeBSD

Maybe:
QNAP NAS, ESXi, Mac

WWW: https://github.com/fcorbelli/zpaqfranz
```

*pkg-plist*

```
bin/zpaqfranz
```


----------

