Format and check FreeBSD Ports Makefiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Tobias Kortkamp cb97a3b878
Chase libias and point clangd to the compilation database
3 weeks ago
io Unbreak on musl libc 8 months ago
libias@f5600512b0 Chase libias and point clangd to the compilation database 3 weeks ago
man portscan: Drop useless --all option 8 months ago
parser Chase libias 4 months ago
portscan Chase libias 4 months ago
scripts scripts/enum.awk: Fix gawk warning 6 months ago
tests Chase libias 6 months ago
.cirrus.yml Chase libias: mkbuild: rewrite in c and replace oconfigure 6 months ago
.clangd Chase libias and point clangd to the compilation database 3 weeks ago
.editorconfig Chase libias and point clangd to the compilation database 3 weeks ago
.gitignore Chase libias and point clangd to the compilation database 3 weeks ago
.gitmodules Update libias and make sure it is rebuild when it is updated 1 year ago
CHANGELOG.md Release 1.1.2 2 months ago
LICENSE Drop "in this position and unchanged" from the LICENSE 3 years ago
Makefile Makefile: origin -> github 2 months ago
README.md README.md: add build instructions and update the description a little 6 months ago
ast.c Chase libias 4 months ago
ast.h *: use bool and *int*_t where possible 7 months ago
build.ninja build: switch to ninja 6 months ago
build.ninja.spec portscan: Simplify using Workqueue 3 months ago
capsicum_helpers.h Fix deps to not forget about capsicum_helpers.h on non-FreeBSD systems 1 year ago
configure Chase libias: mkbuild: rewrite in c and replace oconfigure 6 months ago
constants.c Sync rules 2 months ago
constants.h Sync rules 2 months ago
mainutils.c Chase libias 6 months ago
mainutils.h Chase libias 6 months ago
parser.c portscan: Dereference `${PORTNAME}` in `.include` filenames 3 months ago
parser.h portscan: Dereference `${PORTNAME}` in `.include` filenames 3 months ago
portclippy.c portclippy: Fix crash on unknown long options 3 months ago
portedit.c Chase libias 6 months ago
portfmt.c Chase libias 6 months ago
portscan.c portscan: Unbreak on macOS and Linux 3 months ago
regexp.c *: use bool and *int*_t where possible 7 months ago
regexp.h Use more mempools 12 months ago
rules.c rules: add USES=gstreamer 4 weeks ago
rules.h *: use bool and *int*_t where possible 7 months ago

README.md

portfmt

Portfmt is a collection of tools for editing, formatting, and linting FreeBSD Ports Collection Makefiles.

It comes with several tools:

  • portfmt formats Makefiles
  • portclippy is a linter that checks if variables are in the correct order in a more comprehensive way than portlint
  • portedit edits Makefiles. It comes with several commands that can be used as a basis for your own port update scripts:
    • bump-epoch: bumps PORTEPOCH or inserts it at the right place
    • bump-revision: bumps PORTREVISION or inserts it at the right place
    • set-version: resets PORTREVISION, sets DISTVERSION or PORTVERSION
    • get: lookup unevaluated variable values
    • merge: Generic command to set/update variables while also formatting the updated variables properly and inserting them in the right places if necessary. Useful for merging output of other tools like make cargo-crates, modules2tuple, or make stage-qa. For example to mark a port deprecated:
	printf "DEPRECATED=%s\nEXPIRATION_DATE=%s" \
		Abandonware 2019-08-15 | portedit merge -i Makefile
  • portscan checks the entire Ports Collection for mistakes like unreferenced variables, etc.

Example

A Makefile like this

LICENSE_PERMS=  dist-mirror pkg-mirror auto-accept dist-sell pkg-sell

RUN_DEPENDS+=   ${PYTHON_PKGNAMEPREFIX}paho-mqtt>=0:net/py-paho-mqtt@${PY_FLAVOR}
RUN_DEPENDS+=   ${PYTHON_PKGNAMEPREFIX}supervisor>=0:sysutils/py-supervisor@${PY_FLAVOR}

USES=           cmake \
                compiler:c++11-lib \
                desktop-file-utils \
                gettext-tools \
                pkgconfig \
                qt:5 \
                sqlite \
                gl
USE_QT=         buildtools_build \
                concurrent \
                core \
                dbus \
                gui \
                imageformats \
                linguist_build \
                network \
                opengl \
                qmake_build \
                testlib_build \
                sql \
                widgets \
                x11extras \
                xml

FOOBAR_CXXFLAGS=	-DBLA=foo # workaround for https://github.com/... with a very long explanation

is turned into

LICENSE_PERMS=	dist-mirror dist-sell pkg-mirror pkg-sell auto-accept

RUN_DEPENDS+=	${PYTHON_PKGNAMEPREFIX}paho-mqtt>=0:net/py-paho-mqtt@${PY_FLAVOR} \
		${PYTHON_PKGNAMEPREFIX}supervisor>=0:sysutils/py-supervisor@${PY_FLAVOR}

USES=		cmake compiler:c++11-lib desktop-file-utils gettext-tools gl \
		pkgconfig qt:5 sqlite
USE_QT=		concurrent core dbus gui imageformats network opengl sql widgets \
		x11extras xml buildtools_build linguist_build qmake_build \
		testlib_build

# workaround for https://github.com/... with a very long explanation
FOOBAR_CXXFLAGS=	-DBLA=foo

Building portfmt

If you want to build portfmt from the repository make sure to also clone the submodules: git clone --recurse-submodules https://github.com/t6/portfmt

Building portfmt requires Ninja (packaged often as ninja or ninja-build) or Samurai (package samurai).

  • Prepare the build: ./configure PREFIX=/usr/local
  • Build it: ninja
  • The binaries are available under _build/.bin/ and can be run directly or optionally installed with: ninja install

Editor integration

You can integrate Portfmt into your editor to conveniently run it only on parts of the port, e.g., to reformat USES after adding a new item to it.

Emacs

Add this to ~/.emacs.d/init.el to format the current region with C-c p.

(defun portfmt (&optional b e)
  "PORTFMT(1) on region"
  (interactive "r")
  (shell-command-on-region b e "portfmt " (current-buffer) t
                           "*portfmt errors*" t))

(with-eval-after-load 'make-mode
  (define-key makefile-bsdmake-mode-map (kbd "C-c p") 'portfmt))

Kakoune

Add this to ~/.config/kak/kakrc for filtering the current selection through portfmt with ,1:

map global user 1 '|portfmt<ret>;' -docstring "portfmt on selection"

Vim

Add this to ~/.vimrc for filtering the current selection through portfmt with \1:

xnoremap <leader>1 <esc>:'<,'>!portfmt<CR>