Skip to main content

Console menu for Makefiles

Project description

makefilemenu

Provide a console menu interface for a Makefile.

The canonical use of the system is to have a quick and stupid way to document commands one would like to run, while at the same time making it extremely easy to run, without memorizing anything. Because I'm (ab)using "make", it is also very easy to run a particular target from the command line without using the menu system.

Of course nothing stops you from using the tool for a more regular Makefile.

Description

This is a very simple system to create a menu from the Makefile. You annotate your Makefile as follows:

# menu title: My title

# menu item: a
.PHONY: hello
hello:
	echo hello world

# menu item: b
.PHONY: foo
foo:
	echo foo bar

# menu comment: Section 2

# menu item: c
.PHONY: world
world:
	echo 42

In other words, just add "# menu title" in the file once, and "# menu item: <ch>" to create a command from a make file target. Then running "makefilemenu Makefile" shows:

===== My title =====
a: hello  b: foo  q: quit
Section 2
c: world

Choice:

You can choose one of the commands, and the corresponding target is made. Note that a "quit" command is automatically added to quit the program. If you don't want it, you can use "--quit_cmd ''" to disable it. In such case, to exit, press Control-C or Control-D.

Regular "make" usage is not interfered, so you can still say "make foo hello" on the command line to make both targets.

You can also add a few clauses to the Makefile, so that running makefilemenu is the default target, and your file can be simply executed:

#!/usr/bin/env -S make -f
# -*- makefile -*-

thisfile := $(lastword $(MAKEFILE_LIST))

.PHONY: menu
menu:
	@makefilemenu $(thisfile)

Variables

Two types of variables may be set using makefilemenu: environment variables and Makefile variables. Environment variables are set using # menu envvar, like this.

# menu envvar var
# menu envvar d:var

This adds an initially unset variable var, and a menu entry to set the variable. In the first case the menu entry is invoked by var, in the second case it is by d.

You can set the initial value of the variable to be val as follows:

# menu envvar var=val
# menu envvar d:var=val

In this case, if an empty value is set on the command line, it is given an empty value (if there is no default value, an empty value would unset the variable).

After the environment variable is given a value, when a command is invoked the make command is invoked with the environment variable set.

You can replace envvar by makevar in the # menu directive above. In this case, the environment variable is not used, but instead the make command is invoked like:

make var=val ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

makefilemenu-0.4.5.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

makefilemenu-0.4.5-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file makefilemenu-0.4.5.tar.gz.

File metadata

  • Download URL: makefilemenu-0.4.5.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for makefilemenu-0.4.5.tar.gz
Algorithm Hash digest
SHA256 a5d3b29a45ef8b51287455cf18a19dc5203eb9806e88b2097ff683352aaa48d9
MD5 c3f7a14be4610587e9458826eb30e015
BLAKE2b-256 dd54e2a537c7d787189c617c9ab9a1649cf02957e652ff8110f018a555504ba7

See more details on using hashes here.

File details

Details for the file makefilemenu-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: makefilemenu-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for makefilemenu-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 58eb5cc79b243ac3e3e880b139a1e797479d70d837344f6fc7ed605bd2724566
MD5 cf3e75af4ca7d15aaa6490e2106a8191
BLAKE2b-256 4c081c1526f753f7369c1a8a9bc8ef69964b9149b183d7510cda2615677116c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page