Format FreeBSD Ports Makefiles
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Go to file
Tobias Kortkamp 7e0ac20087
ast sort: recompute entire mapping after the sort
It's invalid afterwards.
3 days ago
ast ast/word/expand/modifier: Also clone flags 3 days ago
libias@9687c5b7f1 ast/format: Format categories 5 months ago
man/man1 Merge portclippy, portedit, portscan with portfmt 7 months ago
parser ast: add AST_VARIABLE_NAME node 5 months ago
portscan Chase libias 9 months ago
scripts enum.awk: Allow for empty values 6 months ago
tests ast: add AST_VARIABLE_NAME node 5 months ago
.clangd Replace dev helper Makefile with script 9 months ago
.dir-locals.el ast: use linked list for words 3 days ago
.editorconfig editorconfig: Use the right tab width for the test files 6 months ago
.envrc ast/format: Format categories 5 months ago
.gitignore Chase libias and point clangd to the compilation database 9 months ago
.gitmodules Update libias and make sure it is rebuild when it is updated 2 years ago
CHANGELOG.md CHANGELOG.md: Manually merge 1.1.4 changes 7 months ago
LICENSE Drop "in this position and unchanged" from the LICENSE 4 years ago
README.md Replace references to GitHub 9 months ago
ast.c ast sort: recompute entire mapping after the sort 3 days ago
ast.h ast: add AST_VARIABLE_NAME node 5 months ago
build.ninja build: switch to ninja 2 years ago
build.ninja.spec Drop unused kakoune.select-object-on-line 6 months ago
buildinfo.h main: Add support for --version 6 months ago
capsicum_helpers.h Fix deps to not forget about capsicum_helpers.h on non-FreeBSD systems 2 years ago
configure Merge portclippy, portedit, portscan with portfmt 7 months ago
constants.c constants: Support :{build,run,test} suffixes for USE_{KDE,QT,PYQT} 9 months ago
constants.h Sync rules 9 months ago
guix.scm guix: Allow for toolchain switching 8 months ago
main.c Drop unused kakoune.select-object-on-line 6 months ago
mainutils.c Chase libias: add struct Directory 9 months ago
mainutils.h Chase libias 9 months ago
parser.c ast: add AST_VARIABLE_NAME node 5 months ago
parser.h ast/format: Update the formatting code to use the AST edit API 6 months ago
portscan.c ast: hide node words 5 months ago
regexp.c Chase libias 7 months ago
regexp.h Use more mempools 2 years ago
rules.c ast/format: Update the formatting code to use the AST edit API 6 months ago
rules.h ast/format: Update the formatting code to use the AST edit API 6 months ago
sexp.c sexp: escape strings 9 months ago
sexp.h Chase libias 9 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://codeberg.org/tobik/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>