Creating FreeBSD ports

Anton Berezin

tobez@tobez.org

 
A bit of meaningless statistics
 
~18800 individual ports
 
Two-level structure
 
One-level of categories
 
64 categories
 
ports/category/a-port/*
 
Probably the best beer^W^Wlargest collection in the world.
 
Old technology - a bunch of Makefiles
 
Infrastructure - include makefiles - ~19000 lines
 
Relatively well documented
 
The FreeBSD Porter's Handbook
 
http://www.freebsd.org/doc/en/books/porters-handbook/
 
Read it!
 
The most important include file: Mk/bsd.port.mk
 
If you are serious - read it, too!
 
If all else fails, going through it will answer your questions
 
Built-in targets
 
fetch
 
extract
 
patch
 
configure
 
build
 
install
 
package
 
clean
 
Anatomy of a port
 
Makefile - how to build it
 
pkg-descr - what it does
 
distinfo - what files constitute a distro
 
pkg-plist - what files it contains
 
files/patch-* - FreeBSD-specific patches
 
files/* - anything goes
 
src/* - when the port is self-contained
 
Anatomy of a Makefile
 
comment header
 
PORTNAME
 
PORTVERION
 
PORTREVISION
 
MASTER_SITES
 
MASTER_SITE_SUBDIR
 
MAINTAINER
 
COMMENT (an inode-saving device)
 
NO_BUILD/NO_INSTALL
 
dependencies
 
LIB_DEPENDS
 
BUILD_DEPENDS
 
RUN_DEPENDS
 
package dependencies
 
manpages
 
MAN1
 
MAN3
 
Overriding built-in targets
 
do-something:
 
post and/or pre stage targets
 
pre-something:/post-something:
 
Most useful: post-patch: and post-install:
 
ports-mgmt/portlint helps
 
So you have an idea for a port
 
First thing - make sure it is not already there!
 
Sometimes it may lurk in a non-obvious place
 
such as ports/devel
 
Sometimes it might be non-obviously named
 
locate
 
grep ports/INDEX-?
 
find | grep
 
So, it's not there
 
Is there a PR open for it?
 
http://www.freebsd.org/cgi/query-pr-summary.cgi?query
 
Use a similar existing port as a starting point
 
For non-obvious things, try to find a port that already does a similar thing
 
Try to follow existing conventions
 
in how to do things
 
as well as in naming
 
If in doubt, ask
 
mailing list freebsd-ports@freebsd.org
 
IRC EFNet #bsdports
 
Ok, time to make a port
 
Most of the ports I do these days have a p5- prefix
 
If I am bored, I just pick one at random
 
First we'll go for a simple one
 
Such as Text::LooseCSV
 
Make sure the software builds OK by hand
 
cd /usr/ports/textproc
 
cp -pr p5-Text-CSV p5-Text-LooseCSV
 
rm distinfo pkg-plist
 
touch pkg-plist
 
vi pkg-descr
 
vi Makefile
 
make makesum
 
mkdir /var/tmp/$(make -V PORTNAME)
 
mtree -U -f $(make -V MTREE_FILE) -d -e -p /var/tmp/$(make -V PORTNAME)
 
make depends PREFIX=/var/tmp/$(make -V PORTNAME)
 
make install PREFIX=/var/tmp/$(make -V PORTNAME)
 
/usr/ports/Tools/scripts/plist -Md -m $(make -V MTREE_FILE) /var/tmp/$(make -V PORTNAME) > pkg-plist
 
vi pkg-plist
 
@dirrm vs. @dirrmtry
 
%%SITE_PERL%% and %%PERL_ARCH%%
 
pkg_delete
 
make clean
 
portlint -abtN
 
make
 
make install
 
make package
 
pkg_delete
 
make reinstall
 
make package
 
make deinstall
 
rm p5-*
 
rm -rf work ~ make clean
 
So everything's OK
 
cd ..
 
shar `find p5-Text-LooseCSV` >/tmp/port.shar
 
Use send-pr
 
http://www.freebsd.org/doc/en/books/porters-handbook/porting-submitting.html
 
Only *then* bug a committer you know on IRC
 
Then wait
 
Quite a bit of all this can be automated
 
Quite a bit of it *is* automated (many times over)
 
Do not skimp on the manual steps the first few times
 
The automation will fail
 
Then you are back to basics
 
So - understand the basics
 
We'll go now for Perl6-GatherTake
 
This one has dependencies
 
As we can see examining Makefile.PL
 
Do we have a port for Coro?
 
locate p5-Coro
 
Yup!
 
Pitfall: different Perl versions
 
Coro wants 5.8.0+
 
Ergo, Perl6-GatherTake wants it, too
 
What about Scalar::Util?
 
There is a port alright
 
Also included in perl5.8 itself
 
So skip this dependency
 
Proceed with manual build
 
perl Makefile.PL
 
make
 
make test
 
What category?
 
locate p5-Perl6
 
devel: 7 vs. lang: 1
 
but we'll put it in lang anyway
 
ports/devel is sort of a backup place
 
ls /usr/ports/devel|wc -l
 
2515!!!
 
cd /usr/ports/lang
 
cp -pr p5-Perl6-Subs p5-Perl6-GatherTake
 
cd p5-Perl6-GatherTake
 
rm distinfo pkg-plist
 
vi pkg-descr
 
vi Makefile
 
Let's put some whitespace!
 
touch pkg-plist
 
make makesum
 
cat distinfo
 
mkdir /var/tmp/$(make -V PORTNAME)
 
mtree -U -f $(make -V MTREE_FILE) -d -e -p /var/tmp/$(make -V PORTNAME)
 
make depends PREFIX=/var/tmp/$(make -V PORTNAME)
 
make install PREFIX=/var/tmp/$(make -V PORTNAME)
 
/usr/ports/Tools/scripts/plist -Md -m $(make -V MTREE_FILE) /var/tmp/$(make -V PORTNAME) > pkg-plist
 
vi pkg-plist
 
@dirrm vs. @dirrmtry
 
%%SITE_PERL%% and %%PERL_ARCH%%
 
pkg_delete p5-Perl6-GatherTake-0.0.3
 
make clean
 
portlint -abtN
 
Gotcha!
 
vi Makefile
 
portlint -abtN
 
make
 
make install
 
make package
 
pkg_delete
 
make reinstall
 
make package
 
make deinstall
 
rm p5-*
 
rm -rf work ~ make clean
 
cd ..
 
shar `find p5-Perl6-GatherTake` >/tmp/port.shar
 
send-pr
 
Ok, let's try something else
 
freshmeat main page
 
hmm, this englab thing is interesting
 
is there a port?
 
locate
 
locate -i
 
nope!
 
download
 
ok, which one?
 
we'll skip the GUI
 
let's do the console app
 
download
 
extract
 
less INSTALL
 
aha, dependency!
 
is there a port?
 
nope!
 
so we'll make the library port first
 
download
 
extract
 
less INSTALL
 
no dependencies, good
 
can we build it by hand?
 
nope!
 
linuxisms
 
patch time
 
real patch or post-patch:
 
cp configure configure.orig
 
remember bash dependency
 
can we build it now?
 
still nope!
 
linuxisms
 
hmm, aha, a bug
 
report a bug upstream
 
fix a bug
 
fix a linuxism
 
remember gmake
 
can we build it now?
 
patch seems to work
 
diff configure{.orig,} >patch-linuxisms
 
cd /usr/ports/math
 
cp -pr libgmp4 libenglab
 
cd libenglab
 
rm distinfo pkg-plist
 
touch pkg-plist
 
mkdir files
 
cd files
 
copy the patch here
 
cd ..
 
vi pkg-descr
 
touch pkg-plist
 
vi Makefile
 
bash!
 
gmake!
 
make makesum
 
mkdir /var/tmp/$(make -V PORTNAME)
 
mtree -U -f $(make -V MTREE_FILE) -d -e -p /var/tmp/$(make -V PORTNAME)
 
make depends PREFIX=/var/tmp/$(make -V PORTNAME)
 
make PREFIX=/var/tmp/$(make -V PORTNAME)
 
questions so far, while it builds?
 
make install PREFIX=/var/tmp/$(make -V PORTNAME)
 
/usr/ports/Tools/scripts/plist -Md -m $(make -V MTREE_FILE) /var/tmp/$(make -V PORTNAME) > pkg-plist
 
vi pkg-plist
 
No more slides for this port
 
Just walk through the port creation
 
Pitfall: different FreeBSD versions
 
Pitfall: different gcc versions
 
Pitfall: different architectures
 
testing, testing, testing

Thank you.

 

Thank you!

 

Any questions?