2
2
Fork
You've already forked portfmt
4
Format FreeBSD Ports Makefiles
  • C 90%
  • Perl 3.6%
  • Raku 1.9%
  • Awk 1.6%
  • Shell 1.1%
  • Other 1.8%
Tobias Kortkamp c210fc32e2
Unbreak on FreeBSD 14.2 with clang 18
ast/writer.c:425:12: error: comparison of integers of different signs: 'int64_t' (aka 'long') and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
 425 | h->end = MIN(h->end + context, p->sessz - 1);
 | ^ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
/usr/include/sys/param.h:331:23: note: expanded from macro 'MIN'
 331 | #define MIN(a,b) (((a)<(b))?(a):(b))
 | ~ ^ ~
2025年05月13日 15:21:57 +02:00
ast Unbreak on FreeBSD 14.2 with clang 18 2025年05月13日 15:21:57 +02:00
edit *: Use nullptr 2025年05月13日 14:09:39 +02:00
libias libias/str: Add titlecase() and titlecase_p() 2025年05月13日 14:25:31 +02:00
lint *: Use nullptr 2025年05月13日 14:09:39 +02:00
man/man1 main: Gc apply command 2023年12月27日 10:50:02 +01:00
portscan *: Use nullptr 2025年05月13日 14:09:39 +02:00
scripts *: Use nullptr 2025年05月13日 14:09:39 +02:00
tests libias/str: Add titlecase() and titlecase_p() 2025年05月13日 14:25:31 +02:00
.clangd Chase libias: mkbuild: Avoid hidden directories 2023年08月01日 12:19:56 +02:00
.dir-locals.el build: Use gnu23 2025年05月13日 14:09:39 +02:00
.editorconfig Add non-default option to use mimalloc 2023年06月14日 10:42:09 +02:00
.envrc ast/word: Implement word eval and eval of some expand modifiers 2024年09月13日 14:30:25 +02:00
.gitignore .gitignore: Ignore /_build entirely 2025年04月19日 14:18:17 +02:00
ast.c ast: Parse .break 2025年05月13日 14:42:17 +02:00
ast.h ast: Parse .break 2025年05月13日 14:42:17 +02:00
build.ninja build: switch to ninja 2021年11月16日 20:33:32 +01:00
build.ninja.spec build: Use gnu23 2025年05月13日 14:09:39 +02:00
buildinfo.h Update license headers 2023年05月29日 10:09:42 +02:00
CHANGELOG.md Release 1.1.6 2025年04月04日 14:35:37 +02:00
configure build: if BUILDDIR is a symlink resolve it first 2025年04月12日 10:13:57 +02:00
constants.c Update constants 2025年05月13日 14:09:39 +02:00
constants.h rules: Unroll VAR_FOR_EACH_* at runtime 2023年12月19日 12:58:15 +01:00
diagnostic.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
diagnostic.h main: add argument parser and other diagnostics 2024年04月28日 19:58:55 +02:00
guix.scm Start enabling UTF-8 support 2024年03月23日 16:26:24 +01:00
LICENSE Update license headers 2023年05月29日 10:09:42 +02:00
lint.h lint/order: Start work to decouple from Parser class 2023年12月25日 13:06:53 +01:00
main.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
main.h main: Add --show-range option to ast command 2025年05月05日 12:29:40 +02:00
mainutils.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
mainutils.h Convert to UTF-8 aware string type 2024年04月16日 08:43:41 +02:00
mkbuild.c build: Use gnu23 2025年05月13日 14:09:39 +02:00
options.spec main: Add --show-range option to ast command 2025年05月05日 12:29:40 +02:00
portscan.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
range.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
range.h main: Add --show-range option to ast command 2025年05月05日 12:29:40 +02:00
README.md Replace references to GitHub 2022年08月19日 19:04:08 +02:00
regexp.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
regexp.h regexp: Remove improper returns_nonnull attribute 2024年04月21日 08:06:48 +02:00
rules.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
rules.h rules: Add USES=ocaml block 2025年04月04日 14:34:54 +02:00
sandbox.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
sandbox.h main: add sandbox module 2024年04月20日 10:37:25 +02:00
sexp.c *: Use nullptr 2025年05月13日 14:09:39 +02:00
sexp.h sexp: Add generic (over buffer and file) render function 2024年10月02日 16:36:04 +02:00

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>