File:  [NetBSD Developer Wiki] / wikisrc / pkgsrc / intro_to_packaging.mdwn
Revision 1.6: download - view: text, annotated - select for diffs
Wed Jul 9 12:34:13 2014 UTC (7 years, 5 months ago) by wiki
Branches: MAIN
CVS tags: HEAD
web commit by https://www.google.com/accounts/o8/id?id=AItOawmuLc-YNA2_8q6AkCIS1Ca0eims4YukCvw: Remove blog specific data

    1: This guide should allow you to learn how to create a new port or
    2: simply fix a port that you need. There are three target demographics
    3: listed below:
    4: 
    5: 	- binary packages user with pkgin or pkg_add
    6:  		(you should be confident here)
    7: 	- build from source, use options
    8:  		(you will know this after reading the guide)
    9: 	- port developers
   10: 		(you should be able to get started here)
   11: 
   12: 
   13: ## pkgsrc tree
   14: 
   15: You should have a copy of the pkgsrc tree sitting somewhere on your
   16: disk, already bootstrapped.
   17: The tree contains a `Makefile`, a `README`, distfiles, packages,
   18: category directories containing the ports, the bootstrap directory
   19: and some documentation.
   20: 
   21: The `mk/*` directory contains the pkgsrc framework Makefiles but
   22: also shell and Awk scripts
   23: 
   24: `pkglocate` is a script to find port names in the tree, though
   25: `pkgtools/pkgfind` is much faster.
   26: 
   27: 
   28: ## use the right tools
   29: 
   30: If you want to get started working on ports like creating new ones
   31: or simply fix ones you need, you should know about these tools:
   32: 
   33:  - install package developer utilities:
   34: 	
   35: 		pkgin -y in pkg_developer
   36: 
   37: It contains very useful programs like:
   38: 
   39:  - checkperms:
   40:  		
   41: 		verify file permissions
   42:  - createbuildlink:
   43: 
   44: 		create buildlink3.mk files, which I'll explain later
   45:  - digest:
   46: 
   47: 		create hashes for messages with crypto algorithms such as sha512 and many others
   48:  - lintpkgsrc:
   49: 
   50: 		checks the whole pkgsrc tree, list all explicitly broken packages for example
   51:  - pkg_chk:
   52: 
   53: 		checks package versions and update if necessary
   54:  - pkg_tarup:
   55: 
   56: 		create archives of installed programs for later use on other machines or backups
   57:  - pkgdiff:
   58: 
   59: 		show diffs of patched files
   60:  - pkglint:
   61: 
   62: 		verify the port you're creating for common mistakes (very useful!)
   63:  - revbump:
   64:  	
   65: 		update package version by one bump by increasing PKGREVISION
   66:  - url2pkg:
   67: 
   68: 		create a blank port from the software download link, it saves you some time by filling out a few basic Makefile settings
   69:  - verifypc:
   70: 
   71: 		sanity check for pkg-config in ports
   72: 
   73: 
   74: ## port contents
   75: 
   76: A pkgsrc port should at least contain:
   77: 
   78: - `Makefile` : a comment, developer info, software download site
   79:   and lots of other possibilities
   80: - `DESCR` : a paragraph containing the description for the software
   81:   of the port we're making
   82: - `PLIST` : the list of files to install, pkgsrc will only install
   83:   the files listed here to your prefix
   84: - `distinfo` : hashes of the software archive and patches or files
   85:   in the port
   86: 
   87: 
   88: Here's how they would look like for a small port I submitted not
   89: long ago in pkgsrc-wip
   90: 
   91: Makefile:
   92: 	
   93: [[!format make """
   94: # [[!paste id=rcsid1]][[!paste id=rcsid2]]
   95: 
   96: PKGNAME=      osxinfo-0.1
   97: CATEGORIES=   misc
   98: GHCOMMIT=     de74b8960f27844f7b264697d124411f81a1eab6
   99: DISTNAME=     ${GHCOMMIT}
  100: MASTER_SITES= https://github.com/yrmt/osxinfo/archive/
  101: 
  102: MAINTAINER=   youri.mout@gmail.com
  103: HOMEPAGE=     http://github.com/yrmt/osxinfo
  104: COMMENT=      Small Mac OS X Info Program
  105: LICENSE=      isc
  106: 
  107: ONLY_FOR_PLATFORM= Darwin-*-*
  108: 
  109: DIST_SUBDIR= osxinfo
  110: WRKSRC= ${WRKDIR}/osxinfo-${GHCOMMIT}
  111: 
  112: .include "../../databases/sqlite3/buildlink3.mk"
  113: .include "../../mk/bsd.pkg.mk"
  114: """]]
  115: 
  116: DESCR:
  117: 	
  118: 	Small and fast Mac OS X info program written in C
  119: 	by Youri Mouton.
  120: 
  121: 
  122: PLIST:
  123: 	
  124: 	@comment [[!paste id=rcsid1]][[!paste id=rcsid2]]
  125: 	bin/osxinfo
  126: 
  127: distinfo:
  128: 
  129: 	[[!paste id=rcsid1]][[!paste id=rcsid2]]
  130: 
  131: 	SHA1 (osxinfo/de74b8960f27844f7b264697d124411f81a1eab6.tar.gz) = 83a2838ad95ff73255bea7f496a8cc9aaa4e17ca
  132: 	RMD160 (osxinfo/de74b8960f27844f7b264697d124411f81a1eab6.tar.gz) = 9102eb2a938be38c4adf8cfbf781c04d0844d09a
  133: 	Size (osxinfo/de74b8960f27844f7b264697d124411f81a1eab6.tar.gz) = 5981 bytes
  134: 
  135: 
  136: ## make
  137: 
  138: Now you know what kind of files you can see when you're in a port
  139: directory. The command used to compile it is the NetBSD `make` but
  140: often `bmake` on non NetBSD systems to avoid Makefile errors. Typing
  141: make alone will only compile the program but you can also use other
  142: command line arguments to make such as extract, patch, configure,
  143: install, package, ...
  144: 
  145: I'll try to list them and explain them in logical order. You can run them together.
  146: 
  147: - `make clean` will remove the source file from the work directory
  148:   so you can restart with either new options, new patches, ...
  149: - `make fetch` will simply fetch the file and check if the hash
  150:   corresponds. It will throw an error if it doesn't.
  151: - `make distinfo` or `make mdi` to update the file hashes in the
  152:   `distinfo` file mentionned above.
  153: - `make extract` extracts the program source files from it's archive
  154:   in the work directory
  155: - `make patch` applies the local pkgsrc patches to the source
  156: - `make configure` run the GNU configure script
  157: - `make` or `make build` or `make all` will stop after the program
  158:   is compiled
  159: - `make stage-install` will install in the port destdir, where
  160:   pkgsrc first installs program files to check if the files correspond
  161:   with the `PLIST` contents before installing to your prefix. For
  162:   `wget`, if you have a default WRKOBJDIR (I'll explain later), the
  163:   program files will first be installed in
  164:   `<path>/pkgsrc/net/wget/work/.destdir` then after a few checks,
  165:   in your actual prefix like `/usr/pkg`
  166: - `make test` run package tests, if they have any
  167: - `make package` create a package without installing it, it will
  168:   install dependencies though
  169: - `make replace` upgrade or reinstall the port if already installed
  170: - `make deinstall` deinstall the program
  171: - `make install` installs from the aforementionned `work/.destdir`
  172:   to your prefix
  173: - `make bin-install` installs a package for the port, locally if
  174:   previously built or remotely, as defined by BINPKG_SITES in
  175:   `mk.conf`, you can make a port install dependencies from packages
  176:   rather than building them with the DEPENDS_TARGET= bin-install
  177:   in `mk.conf`
  178: - `make show-depends` show port dependencies
  179: - `make show-options` show various port options, as defined by `options.mk`
  180: - `make clean-depends` cleans all port dependencies
  181: - `make distclean` remove the source archive
  182: - `make package-clean` remove the package
  183: - `make distinfo` or `make mdi` to update the `distinfo` file
  184:   containing file hashes if you have a new distfile or patch
  185: - `make print-PLIST` to generate a `PLIST` file from files found
  186:   in `work/.destdir`
  187: 
  188: You should be aware that there are many make options along with
  189: these targets, like
  190: 
  191: - `PKG_DEBUG_LEVEL`
  192: - `CHECK_FILES`
  193: - and many others described the the NetBSD pkgsrc guide
  194: 
  195: 
  196: ## pkgsrc configuration
  197: 
  198: The framework uses an `mk.conf` file, usually found in /etc. Here's
  199: how mine looks:
  200: 
  201: [[!format make """
  202: # Tue Oct 15 21:21:46 CEST 2013
  203: 
  204: .ifdef BSD_PKG_MK          # begin pkgsrc settings
  205: 
  206: DISTDIR=                   /pkgsrc/distfiles
  207: PACKAGES=                  /pkgsrc/packages
  208: WRKOBJDIR=                 /pkgsc/work
  209: ABI=                       64
  210: PKGSRC_COMPILER=           clang
  211: CC=                        clang
  212: CXX=                       clang++
  213: CPP=                       ${CC} -E
  214: 
  215: PKG_DBDIR=                 /var/db/pkg
  216: LOCALBASE=                 /usr/pkg
  217: VARBASE=                   /var
  218: PKG_TOOLS_BIN=             /usr/pkg/sbin
  219: PKGINFODIR=                info
  220: PKGMANDIR=                 man
  221: BINPKG_SITES=              http://pkgsrc.saveosx.org/Darwin/2013Q4/x86_64
  222: DEPENDS_TARGET=            bin-install
  223: X11_TYPE=                  modular
  224: TOOLS_PLATFORM.awk?=       /usr/pkg/bin/nawk
  225: TOOLS_PLATFORM.sed?=       /usr/pkg/bin/nbsed
  226: ALLOW_VULNERABLE_PACKAGES= yes
  227: MAKE_JOBS=                 8
  228: SKIP_LICENSE_CHECK=        yes
  229: PKG_DEVELOPER=             yes
  230: SIGN_PACKAGES=             gpg
  231: PKG_DEFAULT_OPTIONS+=      -pulseaudio -x264 -imlib2-amd64 -dconf
  232: .endif                     # end pkgsrc settings
  233: """]]
  234: 
  235: - I use `DISTDIR`, `PACKAGES`, `WRKOBJDIR` to move distfiles,
  236:   packages and source files somewhere else to keep my pkgsrc tree
  237:   clean
  238: - `PKGSRC_COMPILER`, `CC`, `CXX`, `CPP` and `ABI` are my compiler
  239:   options. I'm using clang to create 64 bit binaries here
  240: - `PKG_DBDIR`, `VARBASE`, `LOCALBASE`, `PKG_TOOLS_BIN` are my prefix
  241:   and package database path and package tools settings
  242: - `PKGINFODIR`, `PKGMANDIR` are the info and man directories
  243: - `BINPKG_SITES` is the remote place where to get packages with the
  244:   `bin-install` make target
  245: - `DEPENDS_TARGET` is the way port dependencies should be installed.
  246:   `bin-install` will simply install a package instead of building
  247:   the port
  248: - `X11_TYPE` sould be `native` or `modular`, the latter meaning we
  249:   want X11 libraries from pkgsrc instead of using the `native` ones
  250:   usually in `/usr/X11R7` in Linux or BSD systems and `/opt/X11`
  251:   on Mac OS X with XQuartz
  252: - `TOOLS_PLATFORM.*` points to specific programs used by pkgsrc,
  253:   here I use the one that was generated by pkgsrc bootstrap for
  254:   maximum compatibility
  255: - `ALLOW_VULNERABLE_PACKAGES` allows you to disallow the installation
  256:   of vulnerable packages in critical environments like servers
  257: - `MAKE_JOBS` the number of concurrent make jobs, I set it to 8 but
  258:   it breaks some ports
  259: - `SKIP_LICENSE_CHECK` will skip the license check. If disabled you
  260:   will have to define a list of licenses you find acceptable with
  261:   `ACCEPTABLE_LICENSES`
  262: - `PKG_DEVELOPER` this option will show more details during the port building
  263: - `SIGN_PACKAGES` allows you to `gpg` sign packages. More info in
  264:   my [blog post](http://saveosx.org/signed-packages/) about it
  265: - `PKG_DEFAULT_OPTIONS` allows you to enable or disable specific
  266:   options for all ports (as defined with ports' options.mk files),
  267:   I disabled a few options so less ports would break, pulseaudio
  268:   doesn't build on Mac OS X for example, neither do x264, dconf
  269: 
  270: Keep in mind that there are many other available options.
  271: 
  272: 
  273: ## creating a simple port
  274: 
  275: Let's create a little port using the tools we've talked about above.
  276: I will use a little window manager called 2bwm.
  277: 
  278: - We need an url for the program source files archive. It can be a
  279: direct link to a tar or xz archive. Mine's
  280: `http://pkgsrc.saveosx.org/Darwin/distfiles/2bwm-0.1.tar.gz`
  281: 
  282: - Now that we have a proper link for our program source, create a
  283:   directory for your port:
  284: 
  285: 		$ mkdir ~/pkgsrc/wm/2bwm
  286: 
  287: - Use `url2pkg` to create the needed files automatically:
  288: 		
  289: 		$ url2pkg http://pkgsrc.saveosx.org/Darwin/distfiles/2bwm-0.1.tar.gz
  290: 
  291: You'll be presented with a text editor like `vim` to enter basic
  292: Makefile options:
  293: 
  294: - `DISTNAME`, `CATEGORIES`, `MASTER_SITES` should be set automatically
  295: - enter your mail address for `MAINTAINER` so users know whom to
  296:   contact if the port is broken
  297: - make sure the `HOMEPAGE` is set right, for 2bwm it is a github page
  298: - write a `COMMENT`, it should be a one-line description of the program
  299: - find out which license the program uses, in my case it is the
  300:   `isc` license. You can find a list of licenses in `pkgsrc/mk/licenses.mk`.
  301: - Below you will see `.include "../../mk/bsd.pkg.mk"` at the end
  302:   of the Makefile and above this should go the port's needed
  303:   dependencies to build, we'll leave that empty at the moment and
  304:   try to figure out what 2bwm needs
  305: - exit vim and it should fetch and update the file hashes for you.
  306:   If it says `permission denied` you can just run `make mdi` to
  307:   fetch and upadate the `distinfo` file
  308: 
  309: So now you have valid `Makefile` and `distinfo` files but you need
  310: to write a paragraph in `DESCR`. You can usually find inspiration
  311: on the program's homepage.
  312: 
  313: Here's how they look like at the moment:
  314: 	
  315: Makefile:
  316: [[!format make """
  317: # [[!paste id=rcsid1]][[!paste id=rcsid2]]
  318: 
  319: DISTNAME=       2bwm-0.1
  320: CATEGORIES=     wm
  321: MASTER_SITES=   http://pkgsrc.saveosx.org/Darwin/distfiles/
  322: 
  323: MAINTAINER=     yrmt@users.sourceforge.net
  324: HOMEPAGE=       http://github.com/venam/2bwm/
  325: COMMENT=        Fast floating WM written over the XCB library and derived from mcwm
  326: LICENSE=        isc
  327: 
  328: .include "../../mk/bsd.pkg.mk"
  329: """]]
  330: 
  331: distinfo:
  332: 
  333: 	
  334: 	[[!paste id=rcsid1]][[!paste id=rcsid2]]
  335: 
  336: 	SHA1 (2bwm-0.1.tar.gz) = e83c862dc1d9aa198aae472eeca274e5d98df0ad
  337: 	RMD160 (2bwm-0.1.tar.gz) = d9a93a7d7ae7183f5921f9ad76abeb1401184ef9
  338: 	Size (2bwm-0.1.tar.gz) = 38419 bytes
  339: 
  340: DESCR:
  341: 
  342: 	A fast floating WM, with the particularity of having 2 borders,
  343: 	written over the XCB library and derived from mcwm written by
  344: 	Michael Cardell. In 2bWM everything is accessible from the keyboard
  345: 	but a pointing device can be used for move, resize and raise/lower.
  346: 
  347: But our PLIST file is still empty.
  348: 
  349: 
  350: #### build stage
  351: 
  352: Let's try to build the port to see if things work but as soon as
  353: the build stage starts, we get this error:
  354: 
  355: > 2bwm.c:26:10: fatal error: 'xcb/randr.h' file not found
  356: 
  357: Let's find out which port provides this file !
  358: 
  359: 	$ pkgin se xcb
  360: 
  361: returns these possible packages:
  362: 
  363: 	xcb-util-wm-0.3.9nb1  Client and window-manager helpers for ICCCM and EWMH
  364: 	xcb-util-renderutil-0.3.8nb1  Convenience functions for the Render extension
  365: 	xcb-util-keysyms-0.3.9nb1  XCB Utilities
  366: 	xcb-util-image-0.3.9nb1  XCB port of Xlib's XImage and XShmImage
  367: 	xcb-util-0.3.9nb1 =  XCB Utilities
  368: 	xcb-proto-1.9 =      XCB protocol descriptions (in XML)
  369: 	xcb-2.4nb1           Extensible, multiple cut buffers for X
  370: 
  371: Package content inspection allowed me to find the right port
  372: 
  373: 	$ pkgin pc libxcb|grep randr.h
  374: 
  375: So we can add the libxcb `buildlink3.mk` file to the Makefile above
  376: the bsd.pkg.mk include:
  377: 
  378: 	.include "../../x11/libxcb/buildlink3.mk"
  379: 
  380: This allows the port to link 2bwm against the libxcb port. Let's
  381: try to build the port again!
  382: 
  383: 	$ make clean
  384: 	$ make
  385: 
  386: Reports another error !
  387: 
  388: > 2bwm.c:27:10: fatal error: 'xcb/xcb_keysyms.h' file not found
  389: 
  390: It looks like this file is provided by xcb-util-keysyms, so let's add:
  391: 
  392: 	.include "../../x11/xcb-util-keysyms/buildlink3.mk"
  393: 
  394: in our Makefile.
  395: 
  396: Clean, build again, and add more dependencies until it passes the
  397: build stage. Here's how my Makefile ends up looking like:
  398: 
  399: [[!format make """
  400: # [[!paste id=rcsid1]][[!paste id=rcsid2]]
  401: 
  402: DISTNAME=       2bwm-0.1
  403: CATEGORIES=     wm
  404: MASTER_SITES=   http://pkgsrc.saveosx.org/Darwin/distfiles/
  405: 
  406: MAINTAINER=     yrmt@users.sourceforge.net
  407: HOMEPAGE=       http://github.com/venam/2bwm/
  408: COMMENT=        Fast floating WM written over the XCB library and derived from mcwm
  409: LICENSE=        isc
  410: 
  411: .include "../../x11/libxcb/buildlink3.mk"
  412: .include "../../x11/xcb-util-wm/buildlink3.mk"
  413: .include "../../x11/xcb-util-keysyms/buildlink3.mk"
  414: .include "../../x11/xcb-util/buildlink3.mk"
  415: .include "../../mk/bsd.pkg.mk"
  416: """]]
  417: 
  418: 
  419: #### install phase
  420: 
  421: Geat ! We got our program to compile in pkgsrc. Now we must generate
  422: the PLIST file so we can actually install the program, but we must
  423: `make stage-install` to make sure that it installs in the right
  424: place.
  425: 
  426: 	
  427: 	$ find /pkgsrc/work/wm/2bwm/work/.destdir/
  428: 
  429: returns:
  430: 
  431: 	/pkgsrc/work/wm/2bwm/work/.destdir/
  432: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr
  433: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local
  434: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local/bin
  435: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local/bin/2bwm
  436: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local/bin/hidden
  437: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local/share
  438: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local/share/man
  439: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local/share/man/man1
  440: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local/share/man/man1/2bwm.1
  441: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/local/share/man/man1/hidden.1
  442: 	/pkgsrc/work/wm/2bwm/work/.destdir//usr/pkg
  443: 
  444: This doesn't look right since our `LOCALBASE` is `/usr/pkg`.
  445: 
  446: 
  447: 	$ make print-PLIST
  448: 
  449: returns nothing, because 2bwm installs files in the wrong place so
  450: we need to fix 2bwm's own Makefile to use the right `DESTDIR` and
  451: `PREFIX`, that is set to the right place by pkgsrc. Let's inspect
  452: how 2bwm installs:
  453: 
  454: From 2bwm's Makefile:
  455: 
  456: [[!format make """
  457: install: $(TARGETS)
  458:         test -d $(DESTDIR)$(PREFIX)/bin || mkdir -p $(DESTDIR)$(PREFIX)/bin
  459:         install -pm 755 2bwm $(DESTDIR)$(PREFIX)/bin
  460:         install -pm 755 hidden $(DESTDIR)$(PREFIX)/bin
  461:         test -d $(DESTDIR)$(MANPREFIX)/man1 || mkdir -p $(DESTDIR)$(MANPREFIX)/man1
  462:         install -pm 644 2bwm.man $(DESTDIR)$(MANPREFIX)/man1/2bwm.1
  463:         install -pm 644 hidden.man $(DESTDIR)$(MANPREFIX)/man1/hidden.1
  464: """]]
  465: 
  466: This looks fine since it installs in a `DESTDIR`/`PREFIX` but it sets
  467: 
  468: > PREFIX=/usr/local
  469: 
  470: and
  471: 
  472: > MANPREFIX=$(PREFIX)/share/man
  473: 
  474: In the beginning of the Makefile. We should remove the first line
  475: and edit the man prefix:
  476: 
  477: > MANPREFIX=${PKGMANDIR}
  478: 
  479: so pkgsrc can install the program's files in the right place. We
  480: have two ways of modifying this file, either patch the Makefile or
  481: use `sed` substitution which is a builtin pkgsrc feature that allows
  482: you to change lines in files with a sed command before building the
  483: port.
  484: 
  485: I will show how to do both ways so you can get an introduction on
  486: how to generate patch files for pkgsrc.
  487: 
  488: #### patching the Makefile :
  489: 
  490: - edit the file you need to modify with `pkgvi`:
  491: 
  492: 	
  493: 		$ pkgvi /pkgsrc/work/wm/2bwm/work/2bwm-0.1/Makefile
  494: 
  495: 	which should return:
  496: 
  497: 	> pkgvi: File was modified. For a diff, type:
  498: pkgdiff "/Volumes/Backup/pkgsrc/work/wm/2bwm/work/2bwm-0.1/Makefile"
  499: 
  500: 	and this returns our diff.
  501: 	
  502: 
  503: - create the patch with `mkpatches`, it should create a `patches`
  504:   directory in the port containing the patch and an original file
  505:   removed with `mkpatches -c`.
  506: 
  507: 		$ find patches/*
  508: 		patches/patch-Makefile
  509: 
  510: - now that the patch has been created, we need to add it's hash to
  511:   distinfo otherwise pkgsrc won't pick it up:
  512: 
  513: 		$ make mdi
  514: you should get this new line:
  515: 
  516: 	> SHA1 (patch-Makefile) = 9f8cd00a37edbd3e4f65915aa666ebd0f3c04e04
  517: 
  518: 
  519: - you can now clean and `make patch` and `make stage-install
  520:   CHECK_FILES=no` since we still haven't generated a proper PLIST.
  521:   Let's see if 2wm files were installed in the right place this
  522:   time:
  523: 
  524: 		$ find /pkgsrc/work/wm/2bwm/work/.destdir/
  525: 
  526: 		/pkgsrc/work/wm/2bwm/work/.destdir/
  527: 		/pkgsrc/work/wm/2bwm/work/.destdir//usr
  528: 		/pkgsrc/work/wm/2bwm/work/.destdir//usr/pkg
  529: 		/pkgsrc/work/wm/2bwm/work/.destdir//usr/pkg/bin
  530: 		/pkgsrc/work/wm/2bwm/work/.destdir//usr/pkg/bin/2bwm
  531: 		/pkgsrc/work/wm/2bwm/work/.destdir//usr/pkg/bin/hidden
  532: 
  533: 	It looks like it is alright ! Let's generate the PLIST:
  534: 
  535: 		$ make print-PLIST > PLIST
  536: 	
  537: 	containing:
  538: 
  539: 		@comment [[!paste id=rcsid1]][[!paste id=rcsid2]]
  540: 		bin/2bwm
  541: 		bin/hidden
  542: 
  543: 	There you have a working port you can install normally with
  544: 
  545: 		$ make install
  546: 
  547: 
  548: #### using the sed substitution framework
  549: 
  550: You should be able to fix the prefix error much quicker than with
  551: the patching explained above thanks to the sed substitution framework.
  552: Here's how it looks like in my port Makefile:
  553: 
  554: [[!format make """
  555: SUBST_CLASSES+=         makefile
  556: SUBST_STAGE.makefile=   pre-build
  557: SUBST_MESSAGE.makefile= Fixing makefile
  558: SUBST_FILES.makefile=   Makefile
  559: SUBST_SED.makefile=     -e 's,/usr/local,${PREFIX},g'
  560: SUBST_SED.makefile+=    -e 's,share/man,${PKGMANDIR},g'
  561: """]]
  562: 
  563: As you can see, you can do multiple commands on multiple files, it
  564: is very useful for very small fixes like this.
  565: 
  566: 
  567: #### pkglint
  568: 
  569: Now that we have a working port, we must make sure it complies to the pkgsrc rules.
  570: 
  571: 	$ pkglint
  572: 	
  573: Returns
  574: 
  575: 	ERROR: DESCR:4: File must end with a newline.
  576: 	ERROR: patches/patch-Makefile:3: Comment expected.
  577: 	2 errors and 0 warnings found. (Use -e for more details.)
  578: 
  579: Fix the things pkglint tells you to do until you get the glorious:
  580: 
  581: > looks fine.
  582: 
  583: Then you should do some testing on the program itelf on at least
  584: two platforms such as NetBSD, Mac OS X. Other platforms supported
  585: by pkgsrc can be found at [pkgsrc.org](http://pkgsrc.org). If you
  586: would like to submit your pkgsrc upstream you can either subscribe
  587: to pkgsrc-wip or ask a NetBSD developer to add it for you.
  588: 
  589: You can find the 2bwm port I submitted in
  590: [pkgsrc-wip](http://pkgsrc-wip.cvs.sourceforge.net/viewvc/pkgsrc-wip/wip/2bwm/).
  591: 
  592: 
  593: ## pkgsrc and wip
  594: 
  595: If you want to submit your port for others to use you can either
  596: subscribe to pkgsrc-wip or ask a NetBSD developer to add it for you.
  597: 
  598: pkgsrc-wip is hosted on
  599: [sourceforge](https://sourceforge.net/projects/pkgsrc-wip/) and you
  600: can easily get cvs access to it if you create an account on there
  601: and send an email to NetBSD developer `@wiz` (Thomas Klausner)
  602: asking nicely for commit access.
  603: 
  604: 
  605: ## the options framework
  606: 
  607: You can create port options with the `options.mk` file, like for `wm/dwm`
  608: 
  609: 	
  610: [[!format make """
  611: # [[!paste id=rcsid1]][[!paste id=rcsid2]]
  612: 
  613: PKG_OPTIONS_VAR=			PKG_OPTIONS.dwm
  614: PKG_SUPPORTED_OPTIONS=	xinerama
  615: PKG_SUGGESTED_OPTIONS=	xinerama
  616: 
  617: .include "../../mk/bsd.options.mk"
  618: 
  619: #
  620: # Xinerama support
  621: #
  622: # If we don't want the Xinerama support we delete XINERAMALIBS and
  623: # XINERAMAFLAGS lines, otherwise the Xinerama support is the default.
  624: #
  625: .if !empty(PKG_OPTIONS:Mxinerama)
  626: .  include "../../x11/libXinerama/buildlink3.mk"
  627: .else
  628: SUBST_CLASSES+=         options
  629: SUBST_STAGE.options=    pre-build
  630: SUBST_MESSAGE.options=  Toggle the Xinerama support
  631: SUBST_FILES.options=    config.mk
  632: SUBST_SED.options+=     -e '/^XINERAMA/d'
  633: .  include "../../x11/libX11/buildlink3.mk"
  634: .endif
  635: """]]
  636: 
  637: This file should be included in the Makefile:
  638: 
  639: 	.include "options.mk"
  640: 
  641: If you type `make show-options`, you should see this:
  642: 
  643: 	Any of the following general options may be selected:
  644: 	xinerama	 Enable Xinerama support.
  645: 
  646: 	These options are enabled by default:
  647: 		xinerama
  648: 
  649: 	These options are currently enabled:
  650: 		xinerama
  651: 
  652: 	You can select which build options to use by setting 	PKG_DEFAULT_OPTIONS
  653: 	or PKG_OPTIONS.dwm.
  654: 
  655: Running `make PKG_OPTIONS=""` should build without the `xinerama` dwm option enabled by default.
  656: 
  657: The options.mk file must contain these variables:
  658: 
  659: - `PKG_OPTIONS_VAR` sets the options variable name
  660: - `PKG_SUPPORTED_OPTIONS` lists all available options
  661: - `PKG_SUGGESTED_OPTIONS` lists options enabled by default
  662: 
  663: It allows you to change configure arguments and include other buildlinks, and various other settings.
  664: 
  665: 
  666: ## hosting a package repo
  667: 
  668: Now that you've created a few ports, you might want to make precompiled
  669: packages available for testing. You will need pkgsrc's `pkg_install`
  670: on the host system. I host my [packages](http://pkgsrc.saveosx.org/)
  671: on a FreeBSD server with a bootstrapped pkgsrc.
  672: 
  673: use this `zsh` function to :
  674: 
  675: [[!format bash """
  676: add () {
  677: 	# upload the package to remote server
  678: 	scp $1 yrmt@saveosx.org:/usr/local/www/saveosx/packages/Darwin/2013Q4/x86_64/All/ 2> /dev/null
  679: 	
  680: 	# update the package summary
  681: 	ssh yrmt@saveosx.org 'cd /usr/local/www/saveosx/packages/Darwin/2013Q4/x86_64/All/;
  682: 	        rm pkg_summary.gz;
  683:  	        /usr/pkg/sbin/pkg_info -X *.tgz | gzip -9 > pkg_summary.gz'
  684: 	
  685: 	# pkgin update
  686: 	sudo pkgin update
  687: }
  688: """]]
  689: 
  690: - upload a package
  691: - update the package summary, which is an archive containing
  692:   information about all present packages that will be picked up by
  693:   pkg_install and pkgin. It looks like this for one package:
  694: 
  695: 		PKGNAME=osxinfo-0.1
  696: 		DEPENDS=sqlite3>=3.7.16.2nb1
  697: 		COMMENT=Small Mac OS X Info Program
  698: 		SIZE_PKG=23952
  699: 		BUILD_DATE=2014-06-29 12:45:08 +0200
  700: 		CATEGORIES=misc
  701: 		HOMEPAGE=http://github.com/yrmt/osxinfo
  702: 		LICENSE=isc
  703: 		MACHINE_ARCH=x86_64
  704: 		OPSYS=Darwin
  705: 		OS_VERSION=14.0.0
  706: 		PKGPATH=wip/osxinfo
  707: 		PKGTOOLS_VERSION=20091115
  708: 		REQUIRES=/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
  709: 		REQUIRES=/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
  710: 		REQUIRES=/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
  711: 		REQUIRES=/usr/lib/libSystem.B.dylib
  712: 		REQUIRES=/usr/pkg/lib/libsqlite3.0.dylib
  713: 		FILE_NAME=osxinfo-0.1.tgz
  714: 		FILE_SIZE=9710
  715: 		DESCRIPTION=Small and fast Mac OS X info program written in C
  716: 		DESCRIPTION=by Youri Mouton.
  717: 		DESCRIPTION=
  718: 		DESCRIPTION=Homepage:
  719: 		DESCRIPTION=http://github.com/yrmt/osxinfo
  720: 
  721: 
  722: - update pkgin
  723: 
  724: 
  725: And this shell alias to upload all my built packages, but I still
  726: need to run `add()` mentionned above to update the pkg_summary
  727: 
  728: [[!format bash """
  729: up='rsync -avhz --progress /pkgsrc/packages/ root@saveosx.org:/usr/local/www/saveosx/packages/Darwin/2013Q4/x86_64/'
  730: """]]
  731: 
  732: Then you should be able to set the url in repositories.conf to use
  733: your packages with pkgin. You can also install them directly with
  734: something like `pkg_add
  735: http://pkgsrc.saveosx.org/Darwin/2013Q4/x86_64/All/9menu-1.8nb1.tgz` of
  736: course.
  737: 
  738: 
  739: ## build all packages
  740: 
  741: see jperkin's excellent blog
  742: [posts](http://www.perkin.org.uk/posts/distributed-chrooted-pkgsrc-bulk-builds.html)
  743: about this.
  744: 
  745: 
  746: ## faq
  747: 
  748: #### what if the port I'm making is a dependency for another one?
  749: 
  750: You should just generate the buildlink3.mk file we've talked about
  751: earlier like this:
  752: 
  753: 	$ createbuildlink > buildlink3.mk
  754: 
  755: #### what if the program is only hosted on GitHub ?
  756: 
  757: pkgsrc supports fetching archives from specific git commits on
  758: GitHub like this:
  759: [[!format make """
  760: PKGNAME=           2bwm-0.1
  761: CATEGORIES=        wm
  762: GHCOMMIT=          52a097ca644eb571b22a135951c945fcca57a25c
  763: DISTNAME=          ${GHCOMMIT}
  764: MASTER_SITES=      https://github.com/venam/2bwm/archive/
  765: DIST_SUBDIR=       2bwm
  766: WRKSRC=            ${WRKDIR}/2bwm-${GHCOMMIT}
  767: """]]
  768: 
  769: You can then easily update the git commit and the distinfo with it
  770: to update the program.
  771: 
  772: #### what if the program doesn't have a Makefile
  773: 
  774: You can do all Makefile operations directly from the port's Makefile
  775: like this:
  776: 
  777: 
  778: [[!format make """
  779: post-extract:
  780: 	${CHMOD} a-x ${WRKSRC}/elementary/apps/48/internet-mail.svg
  781: 
  782: do-install:
  783: 	${INSTALL_DATA_DIR} ${DESTDIR}${PREFIX}/share/icons
  784: 	cd ${WRKSRC} && pax -rw -pe . ${DESTDIR}${PREFIX}/share/icons/
  785: """]]
  786: 
  787: To install, but you can also build programs from the Makefile. This
  788: is what qt4-sqlite3 uses:
  789: 
  790: [[!format make """
  791: do-build:
  792: 	cd ${WRKSRC}/src/tools/bootstrap && env ${MAKE_ENV} ${GMAKE}
  793: 	cd ${WRKSRC}/src/tools/moc && env ${MAKE_ENV} ${GMAKE}
  794: 	cd ${WRKSRC}/src/plugins/sqldrivers/sqlite && env ${MAKE_ENV} ${GMAKE}
  795: """]]
  796: 
  797: 
  798: You can install the following type of files:
  799: 
  800: `INSTALL_PROGRAM_DIR` : directories that contain binaries
  801: 
  802: `INSTALL_SCRIPT_DIR` : directories that contain scripts
  803: 
  804: `INSTALL_LIB_DIR` : directories that contain shared and static libraries
  805: 
  806: `INSTALL_DATA_DIR`: directories that contain data files
  807: 
  808: `INSTALL_MAN_DIR` : directories that contain man pages
  809: 
  810: `INSTALL_PROGRAM` : binaries that can be stripped from debugging symbols
  811: 
  812: `INSTALL_SCRIPT` : binaries that cannot be stripped
  813: 
  814: `INSTALL_GAME` : game binaries
  815: 
  816: `INSTALL_LIB` : shared and static libraries
  817: 
  818: `INSTALL_DATA` : data files
  819: 
  820: `INSTALL_GAME_DATA` : data files for games
  821: 
  822: `INSTALL_MAN` : man pages
  823: 
  824: 
  825: `INSTALLATION_DIRS` : A list of directories relative to PREFIX that
  826: are created by pkgsrc at the beginning of the install phase. The
  827: package is supposed to create all needed directories itself before
  828: installing files to it and list all other directories here.
  829: 
  830: #### common errors
  831: 
  832: - > Makefile:19: *** missing separator.  Stop.
  833: 
  834: This means you're not using the right `make`. On most systems, the
  835: make installed from the pkgsrc bootstrap is called `bmake`
  836: 
  837: - If you have a feeling a port is stuck in the building stage,
  838:   disable make jobs in your mk.conf
  839: 
  840: 
  841: [[!cut id=rcsid1 text="$Net"]]
  842: [[!cut id=rcsid2 text="BSD$"]]
  843: [[!meta title="An introduction to packaging"]]
  844: [[!meta author="Youri Mouton"]]

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb