aboutsummaryrefslogtreecommitdiff
path: root/make
blob: 0c2d46564e2103fac6bb12d9f4afe7309a281266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
# Anduril / FSM "make" script
# Copyright (C) 2023 Selene ToyKeeper
# SPDX-License-Identifier: GPL-3.0-or-later
#
# replaces system "make" command,
# because this project doesn't need make's features;
# it just needs a little wrapper script for common tasks

# enable "**" for recursive glob (requires bash)
shopt -s globstar

# figure out which operation was requested
MODE="$1"

function help() {
  cat << ENDOFHELP
Anduril make: a build helper tool for Anduril flashlight firmware
Usage: ./make TASK
... where TASK is:

  help            Show this help text
  (nothing)       Compile all build targets
  flash FILE      Flash firmare FILE to a hardware device
  clean           Delete generated files
  dfp             Download and install Atmel DFPs
  docs            Convert all .md files to .html
  models          Generate the MODELS file
  release         Zip up all .hex files to prep for publishing a release
  version         Show the current version string
  todo            Show tasks noted in source code files

... or TASK can be the partial name of a build target.

Examples:

  # get rid of old clutter files
  ./make clean
  # compile all anduril build targets
  ./make anduril
  # compile all builds matching "emisar" AND "nofet"
  ./make emisar nofet
  # compile all builds matching "q8" (i.e. Sofirn BLF Q8)
  ./make q8
  # Flash the Q8 firmware built in the previous command
  # (copy/paste the file path printed by the build script)
  ./make flash hex/sofirn-blf-q8.hex
ENDOFHELP
}

# sub-command parser / dispatcher
function main() {
  case "$MODE" in
    -h|--help|help|/\?|/h|/help)
      help
      ;;
    clean)
      echo 'rm -vf -- **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp'
      rm -vf -- **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp
      ;;
    dfp)
      shift
      exec ./bin/dfp-install.sh "$@"
      ;;
    docs)
      make-docs
      ;;
    flash)
      echo "Not implemented yet."
      #./bin/flash.sh "$@"
      ;;
    models)
      ./bin/models.py > MODELS
      cat MODELS
      ;;
    release)
      ./bin/make-release.sh "$@"
      ;;
    version)
      ./bin/version-string.sh "$@"
      ;;
    todo)
      grep -E 'TODO:|FIXME:' -- **/*.[ch] **/*.md
      ;;
    me)
      memes "$@"
      ;;
    *)
      exec ./bin/build-all.sh "$@"
      ;;
  esac
}

function make-docs () {
  for md in **/*.md ; do
    html=${md//.md/.html}
    echo "$md --> $html"
    cmark-gfm "$md" > "$html"
  done
}

function memes () {
    # memes
    shift ; shift
    if [ "$UID" = "0" ]; then
        echo "Okay."
        for l in . . . ' 10%' ' .' . . ' 20%' ' .' . . '' "!" '' . . . ' 35%' ' .' . . . . ' 69%' '' '' '' ' (nice)' '' '' '' '\b\b\b\b\b\b      \b\b\b\b\b\b.' . . ' 95%' ' .' . . ' 99%' ' .' . . ' 99.5%' ' .' . . '' ' ?' '' ' .' . . ' 99.7%' ' .' . . '' '' ' processing...' '' ' .' . . ' 99.8%' ' .' . . '' . '' '' ' urgh!' '' ' .' . . '' '' '' ' #@*%!\a' '' '' ' .' . . '' '' ' PROCESSING!' '' ' .' '' . '' . '' . '' . ' 99.9% ' '' . '' . '' . '' '' '' ' HRRRNNGH!!' '' '' ' .' '' '' . '' '' ' 99.95%' '' '' ' .' '' '' '' . '' '' " j/k NOT!" ; do
            t=$( printf '%.3f' $(( 500 + $RANDOM / 32 ))e-3 )
            sleep "$t"
            echo -ne "$l"
        done ; echo
        echo "Make your own $*, dammit!"
    else
        echo "Make your own $*."
    fi
    exit 1
}

# go to the repo root
BASEDIR=$(dirname "$0")
cd "$BASEDIR" || (echo "Error: Can't cd to basedir." && exit 1)

# do whatever the user requested
main "$@"