nbos

nbos

https://git.tonybtw.com/nbos.git git://git.tonybtw.com/nbos.git
1,400 bytes raw
1
#!/bin/sh
2
# Walks pkgs/ and emits all.h (declarations) and all.c (registry array).
3
# Run via `make registry`.
4
#
5
# A recipe is a directory pkgs/<cat>/<name>/ containing <name>.c and <name>.h.
6
# The .h must declare `extern const pkg pkgs_<name>;` and the .c must define it.
7
8
set -eu
9
10
PKGS_DIR="${PKGS_DIR:-pkgs}"
11
MODE="${1:-h}"
12
13
recipes=$(find "$PKGS_DIR" -mindepth 2 -maxdepth 2 -name '*.h' \
14
            ! -name 'all.h' | sort)
15
16
if [ "$MODE" = "h" ] || [ "$MODE" = "--h" ]; then
17
    printf '/* AUTO-GENERATED. Do not edit. */\n'
18
    printf '#ifndef PKGS_ALL_H\n'
19
    printf '#define PKGS_ALL_H\n\n'
20
    printf '#include "../include/nbos.h"\n\n'
21
22
    for h in $recipes; do
23
        name=$(basename "$h" .h)
24
        printf 'extern const pkg pkgs_%s;\n' "$name"
25
    done
26
27
    printf '\n'
28
    printf 'extern const pkg *const PKGS_REGISTRY[];\n'
29
    printf 'extern const size_t   PKGS_REGISTRY_LEN;\n\n'
30
    printf '#endif\n'
31
elif [ "$MODE" = "c" ] || [ "$MODE" = "--c" ]; then
32
    printf '/* AUTO-GENERATED. Do not edit. */\n'
33
    printf '#include "all.h"\n\n'
34
    printf 'const pkg *const PKGS_REGISTRY[] = {\n'
35
36
    for h in $recipes; do
37
        name=$(basename "$h" .h)
38
        printf '    &pkgs_%s,\n' "$name"
39
    done
40
41
    printf '};\n\n'
42
    printf 'const size_t PKGS_REGISTRY_LEN = sizeof(PKGS_REGISTRY) / sizeof(PKGS_REGISTRY[0]);\n'
43
else
44
    printf 'usage: %s [--h|--c]\n' "$0" >&2
45
    exit 1
46
fi