"Hello world" ports example: help request

  • Thread starter Deleted member 67440
  • Start date
D

Deleted member 67440

Guest
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.

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
 
1. This is a ports Makefile that could work with your port:
Code:
# $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:
Code:
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.
 
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.
 
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.
 
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?

Code:
#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?
 
I have a second problem.
Here is the first port I prepared

Here the package

The problem should be trivial, an incorrect path, because I get
Code:
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
Code:
# $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

Code:
bin/zpaqfranz
 
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
Code:
# $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

Code:
bin/zpaqfranz

1617563350780.png


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.

 
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
Code:
#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
Code:
# $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
Code:
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
Code:
bin/zpaqfranz
 
Back
Top