Add copyright and GPL3, optimize comments.

This commit is contained in:
Stefan 2023-10-02 15:06:21 +02:00
parent 16b3f2b99c
commit c03fdc6264
5 changed files with 184 additions and 82 deletions

View file

@ -1,3 +1,22 @@
;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2023 Stefan <stefan-guix@vodafonemail.de>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (embedded)
#:use-module (guix build-system)
#:use-module (guix build-system gnu)
@ -91,7 +110,7 @@ STARTFILE-DIR to (string-append \"/\" target \"/lib/\")."
;; Prevent auto-host.h in output:lib to create a cyclic dependency
;; referencing output:out.
(("PREFIX_INCLUDE_DIR \"\\$prefix/include\"")
(string-append "PREFIX_INCLUDE_DIR \"$libdir/include\"")))
"PREFIX_INCLUDE_DIR \"$libdir/include\""))
(substitute* "gcc/genmultilib"
;; Enforce proper invokations of sh.
(("#!/bin/sh") (string-append "#!" (which "sh"))))
@ -103,10 +122,10 @@ STARTFILE-DIR to (string-append \"/\" target \"/lib/\")."
(string-append "startfile_prefix_spec = \""
#$libc #$startfile-dir "\";")))
(substitute* "libstdc++-v3/python/Makefile.in"
;; Change pythondir from output:out to output:lib to prevent
;; output:lib/lib/libstdc++.so.*-gdb.py to create a cyclic dependency to
;; output:out/share/…/python. This moves all python files to
;; output:lib. The option --with-python-dir is still usable.
;; Change pythondir from #$output:out to #$output:lib to prevent
;; #$output:lib/lib/libstdc++.so.*-gdb.py to create a cyclic dependency
;; to #$output:out/share/…/python. This moves all python files to
;; #$output:lib. The option --with-python-dir is still usable.
(("pythondir = \\$\\(datadir\\)") "pythondir = $(libdir)/share")
(("pythondir = \\$\\(prefix\\)") "pythondir = $(libdir)"))
#!(substitute* "libsanitizer/asan/asan_linux.cpp"
@ -132,23 +151,23 @@ STARTFILE-DIR to (string-append \"/\" target \"/lib/\")."
KERNEL-HEADERS packages. The defaults refer to glibc and the kernel-headers
used to build glibc."
#~(list
;; The first include paths are gcc/include-c++ and gcc:lib/…/include.
;; Second is usually /usr/local, which we replace with the empty
;; output:lib/include path.
;; The first set of include paths consinsts of #$gcc/include-c++/… and
;; #$gcc:lib/…/include. Second is usually /usr/local, which we replace
;; with the empty #$output:lib/include path.
(string-append "--with-local-prefix=" #$output:lib)
;; Third is gcc:lib/…/include-fixed, which expects libc/include and
;; kernel-headers/include to follow in this order.
;; Third is #$gcc:lib/…/include-fixed, which expects #$libc/include and
;; #$kernel-headers/include to follow in this order.
;; Fourth and usually the last include path is /usr/include containing all
;; system headers. It is only possible to specify one path for this. Set
;; the libc/include path and prevent the use of /usr/include.
;; the #$libc/include path and prevent the use of /usr/include.
(string-append "--with-native-system-header-dir=" #$libc "/include")
;; The final include path has to be kernel-headers/include, which has to
;; be after libc/include. There is only -idirafter left to achieve this.
;; Add output:lib/lib as a built-in link-time search path.
;; Add libc/lib and libc/static as built-in link-time search paths.
;; Add a runtime search path to libc/lib, if not linked statically. This
;; search path to libc/lib may not be technically necessary because of
;; the dynamic linker in there, but better use a complete list.
;; The final include path has to be #$kernel-headers/include, which has to
;; be after #$libc/include. There is only -idirafter left to achieve
;; this. Add #$output:lib/lib as a built-in link-time search path.
;; Add #$libc/lib and #$libc/static as built-in link-time search paths.
;; Add a runtime search path to #$libc/lib, if not linked statically.
;; This search path to #$libc/lib may not be technically necessary because
;; of the dynamic linker in there, but better use a complete list.
;; Actually libc needs a DT_RUNPATH entry to the libgcc_s.so of the GCC
;; used to build it. This is missing and may requires a fix. As a
;; workaround one can force any program built by this GCC and not linked
@ -160,9 +179,10 @@ used to build glibc."
"-idirafter " #$kernel-headers "/include "
;; Embed the link-time search path to libgcc_s.so, libstdc++.so, etc.
"%x{-L" #$output:lib "/lib} "
;; Embed the link-time search paths to libc/lib and libc:static/lib.
;; Embed the link-time search paths to #$libc/lib and #$libc:static/lib.
"%x{-L" #$libc "/lib} %x{-L" #$libc:static "/lib} "
;; Embed the runtime search path to libc/lib, if not staticlally linked.
;; Embed the runtime search path to #$libc/lib, if not staticlally
;; linked.
"%{nolibc|nostdlib|static:; :%x{-rpath=" #$libc "/lib}} "
;; This is a workaround to ensure a pre-loaded libgcc_s.so for libc if
;; not statically linking. The libstdc++.so and other shared libraries
@ -176,9 +196,9 @@ used to build glibc."
;; build it, the -rpath is added unconditionally here.
"%{nodefaultlibs|nostdlib|static|static-libgcc|static-pie:; "
":%x{-lgcc_s}} %x{-rpath=" #$output:lib "/lib}")
;; Prevent the C++ headers in output:lib, put them in output:out instead.
;; Use an unconventional path to prevent it from being added to the
;; environment variables C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.
;; Prevent the C++ headers in #$output:lib, put them in #$output:out
;; instead. Use an unconventional path to prevent it from being added to
;; the environment variables C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.
"--with-gxx-include-dir=$(prefix)/include-c++"
;; As libc is limited, gcc will not be usable for 32 and 64 bit builds.
"--disable-multilib"
@ -275,11 +295,11 @@ necessary paths build-in to preserve a necessary include-order."
(cons (list "ld-wrapper" ld-wrapper) build-inputs)
build-inputs)))
(define*-public (make-gcc-toolchain-package toolchain)
"Make a GCC-toolchain package from TOOLCHAIN. The TOOLCHAIN argument must be
a list of inputs (label/package tuples) providing equivalent functionality as
(define*-public (make-gcc-toolchain-package c-toolchain)
"Make a GCC-toolchain package from C-TOOLCHAIN. The C-TOOLCHAIN argument must
be a list of inputs (label/package tuples) providing equivalent functionality as
the 'gcc-toolchain' package as passed to 'package-with-c-toolchain'."
(let ((gcc (car (assoc-ref toolchain "gcc"))))
(let ((gcc (car (assoc-ref c-toolchain "gcc"))))
(package
(name (string-append (package-name gcc) "-toolchain"))
(version (package-version gcc))
@ -291,7 +311,7 @@ the 'gcc-toolchain' package as passed to 'package-with-c-toolchain'."
#:builder
#~(begin
(use-modules ((guix build union)))
(union-build #$output (quote #$(map second toolchain))))))
(union-build #$output (quote #$(map second c-toolchain))))))
(synopsis "Complete GCC toolchain for C/C++ development")
(description "This package provides a complete GCC toolchain for C/C++
development to be installed in user profiles. This includes GCC and Binutils.
@ -362,8 +382,8 @@ usable on embedded products.")
#:key
(cross-gcc (cross-gcc target))
(cross-binutils (cross-binutils target)))
"Make a newlib-nano package for TARGET with the given CONFIGURE-FLAGS,
CROSS-GCC and CROSS-BINUTLIS packages for building."
"Make a newlib-nano package for TARGET with the given CROSS-GCC and
CROSS-BINUTLIS packages for building."
(package
(inherit (make-newlib-4.3 target
#:configure-flags
@ -394,35 +414,35 @@ CROSS-GCC and CROSS-BINUTLIS packages for building."
(define-public (gcc-cross-newlib-arm-configure-flags target libc)
"Modify configure-flags to build a GCC cross-compiler for the Arm target
TARGET using the a newlib as LIBC."
TARGET using newlib as LIBC."
#~(list
(string-append "--target=" #$target)
;; All paths to --with-… options are relative to the sysroot. As store
;; pathes are absolute, the sysroot needs to be set to /.
"--with-sysroot=/"
;; The first include paths are gcc/include-c++ and gcc:lib/…/include.
;; Second is usually /usr/local, which we replace with the empty
;; output:lib/include path.
;; The first set of include paths consinsts of #$gcc/include-c++/… and
;; #$gcc:lib/…/include. Second is usually /usr/local, which we replace
;; with the empty #$output:lib/include path.
(string-append "--with-local-prefix=" #$output:lib)
;; Third is gcc:lib/…/include-fixed, which expects libc/include and
;; kernel-headers/include to follow in this order.
;; Third is #$gcc:lib/…/include-fixed, which expects #$libc/include and
;; #$kernel-headers/include to follow in this order.
;; Fourth and usually the last include path is /usr/include containing all
;; system headers. It is only possible to specify one path for this. Set
;; the libc/target/include path and prevent the use of /usr/include.
;; the #$libc/include path and prevent the use of /usr/include.
;; Using newlib as libc for bare-metal does not require kernel-headers.
(string-append
"--with-native-system-header-dir=" #$libc "/" #$target "/include")
;; Add output/target/lib as a built-in link-time search path.
;; Add libc/target lib and as a built-in link-time search path.
;; Add #$output/#$target/lib and #$libc/#$target/lib as a built-in
;; link-time search path.
(string-append
"--with-specs="
;; Embed the link-time search path to libgcc, libstdc++, etc.
"%x{-L" #$output "/" #$target "/lib} "
;; Embed the link-time search paths to libc.
"%x{-L" #$libc "/" #$target "/lib}")
;; Prevent the C++ headers in output:lib, put them in output:out instead.
;; Use an unconventional path to prevent it from being added to the
;; environment variables C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.
;; Prevent the C++ headers in #$output:lib, put them in #$output:out
;; instead. Use an unconventional path to prevent it from being added to
;; the environment variables C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.
"--with-gxx-include-dir=$(prefix)/include-c++"
;; Ensure GCC is build for newlib.
"--with-newlib"
@ -431,10 +451,6 @@ TARGET using the a newlib as LIBC."
"--with-multilib-list=aprofile,rmprofile"
;; As newlib does not have a dynamik-linker, disable shared builds.
"--disable-shared"
;; Ensure that the default assembler will be found.
;(string-append "--with-as=" #$cross-binutils "/bin/" #$target "-as")
;; Ensure that the default linker will be found.
;(string-append "--with-ld=" #$cross-binutils "/bin/" #$target "-ld")
;; Disable all language frontends except for C and C++.
"--enable-languages=c,c++"
;; Save space by disabling pre-compiled libstdc++ headers.
@ -472,9 +488,9 @@ necessary paths build-in to preserve a necessary include-order."
;; However, the cross-binutils package contains only executables
;; pefixed with the target name in its bin directory. The ones
;; not prefixed reside in its target/bin directory. We create a
;; new package which links that target/bin directory as bin.
;; new package, which links that #$target/bin directory as bin.
;; Note: The linker is invoked by collect2, which has different lookup
;; rules and finds a prefixed target-ld.
;; rules as GCC and finds a prefixed target-ld.
(list
(list "binutils-for-toolchain"
(package
@ -499,7 +515,7 @@ necessary paths build-in to preserve a necessary include-order."
make-cross-newlib)
"Make a C-toolchain targeting arm-none-eabi consisting of a cross-compiler,
cross-compiled Binutils, and a newlib C-library. The cross-compiler will be
build with with another toolchain using the given host GCC and Binutils. The
build with another toolchain using the given host GCC and Binutils. The
function MAKE-GCC is used to create a GCC cross-compiler package using the
newlib C-library package created with MAKE-CROSS-NEWLIB. The result can be used
by the transformation function 'package-with-c-toolchain' and to build a

View file

@ -1,3 +1,22 @@
;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2023 Stefan <stefan-guix@vodafonemail.de>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (zephyr)
#:use-module (embedded)
#:use-module (gnu packages bootloaders)
@ -17,8 +36,8 @@
;; property, then the parent directory name is used as the module name. Having
;; two modules with the same name is treated as an error. As Guix needs a
;; common directory name for search-path-specification, we need this
;; intermediate directory as a pattern and to have unique module names.
;; Unfortunately search-path-specification is still not powerful enough, so
;; intermediate directory as a pattern to find unique module names.
;; Unfortunately search-path-specification is not powerful enough, so
;; complete-zephyr-application needs the correct-ZEPHYR_MODULES build-phase.
(define-public %zephyr-module "zephyr-module")

View file

@ -1,3 +1,22 @@
;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2023 Stefan <stefan-guix@vodafonemail.de>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (zephyr apps)
#:use-module (embedded)
#:use-module (gnu packages)

View file

@ -1,3 +1,22 @@
;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2023 Stefan <stefan-guix@vodafonemail.de>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (zephyr modules)
#:use-module (guix gexp)
#:use-module (guix build-system copy)

View file

@ -1,3 +1,22 @@
;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2023 Stefan <stefan-guix@vodafonemail.de>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (zephyr zmk)
#:use-module (guix build union)
#:use-module (guix build utils)
@ -101,6 +120,22 @@ built on the Zephyr™ Project Real Time Operating System (RTOS).")
#:zephyr zephyr-3.2+zmk-fixes
#:source-prefix "zmk"))
(define*-public (make-zmk-union zmk-packages #:key name synopsis)
"Make a union of several ZMK Firmware packages for left and right hand or
settings-reset firmware files."
(package
(inherit (car zmk-packages))
(name (or name (package-name (car zmk-packages))))
(source #f)
(build-system trivial-build-system)
(arguments
(list #:modules '((guix build union))
#:builder
#~(begin
(use-modules ((guix build union)))
(union-build #$output (quote #$zmk-packages)))))
(synopsis (or synopsis (package-synopsis (car zmk-packages))))))
(define*-public (make-nrfmicro-13-zmk shield #:key zmk-config (extra-name ""))
"Make a ZMK firmware package for a keyboard consisting of the nrfmicro 1.3/1.4
board with a SHIELD PCB. Use the ZMK-CONFIG directory containing optional
@ -118,6 +153,7 @@ shield or board names."
(use-modules (guix build utils))
(substitute* "app/CMakeLists.txt"
;; Move combo.c and behaviour_tap_dance.c above all other behaviors.
;; This fix is needed to get working layer-tap-dance.
(("^ target_sources\\(app PRIVATE src/combo.c\\)\n") "")
(("^ target_sources\\(app PRIVATE src/behaviors/behavior_tap_dance.c\\)\n")
"")
@ -127,29 +163,17 @@ shield or board names."
" target_sources(app PRIVATE src/combo.c)\n"
" target_sources(app PRIVATE src/behaviors/behavior_tap_dance.c)\n"))))))
(define*-public (make-zmk-union zmk-packages #:key name synopsis)
"Make a union of several ZMK Firmware packages for left and right hand or
settings-reset firmware files."
(package
(inherit (car zmk-packages))
(name (or name (package-name (car zmk-packages))))
(source #f)
(build-system trivial-build-system)
(arguments
(list #:modules '((guix build union))
#:builder
#~(begin
(use-modules ((guix build union)))
(union-build #$output (quote #$zmk-packages)))))
(synopsis (or synopsis (package-synopsis (car zmk-packages))))))
(define (hid-modifier modifier)
"Map a symbol for a MODIFIER key into a macro symbol for a ZMK keymap file.
An unknown MODIFIER symbol is just returned."
(define hid-modifier->zmk-macro
'(( . LS) ( . LC) ( . LA) ( . LG)
(R . RG) (R . RA) (R . RC) (R . RS)))
(or (assoc-ref hid-modifier->zmk-macro modifier) modifier))
(define-public (special-bindings key-label)
"Map a KEY-LABEL matching a special-binding into a binding symbol for a
ZMK keymap file. An unknown KEY-LABEL symbol is just returned."
(define special-bindings->zmk-name
'(;; A whole in the keyboard matrix without meaning to ZMK.
( . "")
@ -168,6 +192,8 @@ settings-reset firmware files."
(or (assoc-ref special-bindings->zmk-name key-label) key-label))
(define-public (hid key-label)
"Map a HID KEY-LABEL into a macro symbol for a ZMK keymap file. Any other
KEY-LABEL will be treated by 'special-bindings'."
(define hid->zmk-name
'(( . ESC) ( . PSCRN) ( . SLCK) ( . PAUSE_BREAK)
(^ . GRAVE) (- . MINUS)
@ -194,6 +220,8 @@ settings-reset firmware files."
(special-bindings (or (assoc-ref hid->zmk-name key-label) key-label)))
(define-public (de key-label)
"Map a german KEY-LABEL based on the QWERTZ-layout into an international HID
key-label, if needed, and return a symbol for a ZMK keymap file."
(define de->hid
'((ß . -) (´ . =)
(Z . Y) (Ü . ) (+ . )
@ -203,6 +231,8 @@ settings-reset firmware files."
(hid (or (assoc-ref de->hid key-label) key-label)))
(define-public (neo key-label)
"Map a german KEY-LABEL based on the neo-layout into the international HID
key-label, if needed, and return a symbol as needed by a ZMK keymap file."
(define neo->de
'((T1 . ^)
(X . Q) (V . W) (L . E) (C . R) (W . T)
@ -223,9 +253,9 @@ settings-reset firmware files."
(macros '()))
"Generate the content of a keymap file for ZMK. Each layer in LAYERS has a
name, a layout and multiple rows, of which each contains the key-bindings. The
last row contains the bindings for sensors. The key-bindings use symbols on
LAYOUT. The BEHAVIORS, COMBOS, MACROS and CONDITIONAL-LAYERS contain lists of
strings to inject own appropiate definitions for ZMK. PROPERTIES may contain
last row contains the bindings for sensors. The key-bindings use symbols from
the layout. The BEHAVIORS, COMBOS, MACROS and CONDITIONAL-LAYERS contain lists
of strings to inject own appropiate definitions for ZMK. PROPERTIES may contain
properties for behaviors or even C macro definitions."
(define (include file)
"Return an include statement for file"
@ -244,7 +274,7 @@ properties for behaviors or even C macro definitions."
(define* (keymap-layer name layout rows)
"Return a string with a keymap layer definition NAME for a ZMK keymap file,
consisting of KEYS with their labels based on LAYOUT."
consisting of ROWS of keys with their labels based on LAYOUT."
(define (zmk-name->string zmk-name)
"Tansform a ZMK-NAME into a string."
@ -412,11 +442,10 @@ resolved by flashing this settings reset firmware to both controllers.")))
(- '(&mt -))
(. '(&mt ·))
(l1 '(&lt 1 ))
(to0 '(&to 0)) ; Switch to layer 0.
(l0 '(&ltd0)) ; Layer dancing for layer 0.
(l1 '(&ltd1)) ; Layer dancing for layer 1.
(l2 '(&ltd2)) ; Layer dancing for layer 2.
(l3 '(&ltd3)) ; Layer dancing for layer 3.
(l0 '(&ltd0)) ; Layer tap-dance for layer 0.
(l1 '(&ltd1)) ; Layer tap-dance for layer 1.
(l2 '(&ltd2)) ; Layer tap-dance for layer 2.
(l3 '(&ltd3)) ; Layer tap-dance for layer 3.
(1 '( BT_SEL 0))
(2 '( BT_SEL 1))
(3 '( BT_SEL 2))