ZMK.PROGRAM(5)

πŸ’– zmk.Program(5) β€” the vibe guide to compiling your lil C/C++/ObjC babies πŸ’–

okay so bestie, welcome to zmk.Program, a manual page in the zmk family of manuals. it's a template for compiling C/C++/ObjC programs, and honestly? it's giving "build system but make it cute". let's get into it. πŸŽ€


✨ NAME ✨

Program β€” the template for compiling C/C++/ObjC programs. that's it, that's the whole name, no notes. πŸ‘‘


✨ SYNOPSIS ✨

include z.mk
# programName is any valid identifier.
programName.Sources = hello.c
$(eval $(call ZMK.Expand,Program,programName))
so like. programName is any valid identifier, okay? you pick it. it's your moment. 🌟

✨ DESCRIPTION ✨

okay so once you expand the Program template with a program name, it literally creates rules for compiling, cleaning, installing, and removing one single program written in C, C++, or Objective C. one program. one vibe. ✨

here's the tea on source files: they get compiled into object files that are prefixed with $(programName)-. why?? because that way a single source file can be compiled separately with distinct preprocessor, compiler, and linker options. slay. it's the same file, different settings, no drama, no collisions. πŸ’…

and when you're cross-compiling for Windows or DOS, the $(exe) variable expands to .exe. periodt. πŸͺŸ


🎯 TARGETS 🎯

this module provides the following targets, bestie. memorize them, they're your besties too.

  • $(programName)$(exe) β€” this target represents the program executable. the main character, literally. πŸ‘‘
  • all β€” a phony target that depends on $(programName)$(exe). it's the "do the thing" button. 🫢
  • clean β€” phony, and it removes $(programName)$(exe) plus all the constituent object files and dependency files. it's giving spring cleaning. 🧹
  • install β€” phony. copies $(programName) to $(programName.InstallDir), using the name $(programName.InstallName) and mode $(programName.InstallMode). and guess what, the target directory gets automatically created if it's required, so you don't have to lift a finger. πŸ’…
    • also!! the variables Configure.ProgramPrefix, Configure.ProgramSuffix, and Configure.ProgramTransformName automatically impact the installed names of all the programs. no cap. all of them.
  • uninstall β€” phony, removes $(programName)$(exe) as installed by the install target. the reverse uno card. πŸƒ

🧚 VARIABLES 🧚

this module provides the following variables. sit down, hydrate, here we go. πŸ“

  • $(programName).Sources β€” list of source files to compile.
    • there is no default value. this variable must be set before expanding the template. like, it's not optional, bestie, it's the whole point. 😭
  • $(programName).Objects β€” list of object files to link.
    • the default value is all the elements of $(programName).Sources with the added prefix $(programName)- and with the extension replaced by .o.
  • $(programName).Linker β€” the linker required to link object files together.
    • the default value depends on the type of source files used, ensuring that C++ sources are linked with the C++ linker. it just knows. πŸ”₯
  • $(programName).InstallDir β€” the directory $(programName)$(exe) is installed to.
    • the default value is $(bindir), but $(sbindir) or $(libexecdir) are commonly used as well. the special value noinst disables the rules related to installation and uninstallation. so if you don't want it installed, say noinst and it goes away. ghosted. πŸ‘»
  • $(programName).InstallName β€” the name of the program after installation.
    • the default value is $(programName).
  • $(programName).InstallMode β€” the UNIX mode $(programName)$(exe) is installed with.
    • the default value is 0755. iconic permissions, honestly. πŸŽ€
  • DESTDIR β€” path added to all installation targets.
    • this variable is normally set externally, to install a compiled program into a staging area during construction of a compiled binary package. you usually don't touch this one, it's set for you. 🫢
  • CFLAGS, CXXFLAGS, OBJCFLAGS β€” options for the C, C++ and the Objective C compiler, respectively. one for each language, no favoritism. 🌈
  • CPPFLAGS β€” options for the preprocessor.

πŸ”§ IMPLEMENTATION NOTES πŸ”§

Program uses InstallUninstall to handle installation and removal. also, the exe variable is automatically set to .exe where appropriate. so you don't gotta do that yourself, it's already handled. πŸ’œ


🌸 EXAMPLES 🌸

okay so picture this. you've got yourself a true_false.c file that looks like:

#include <stdlib.h>

int main(void) {
    return EXIT_CODE;
}

and now the following Makefile builds the classic programs true and false. yes, THE classic programs. we love a throwback. πŸ‘‘

include z.mk

true.Sources = true_false.c
$(eval $(call ZMK.Expand,Program,true))
true$(exe): CPPFLAGS += -DEXIT_CODE=EXIT_SUCCESS

false.Sources = true_false.c
$(eval $(call ZMK.Expand,Program,false))
false$(exe): CPPFLAGS += -DEXIT_CODE=EXIT_FAILURE

same source file, two whole programs, two different exit codes. the way that CPPFLAGS gets appended per-target?? obsessed. πŸ”₯


πŸ“œ HISTORY πŸ“œ

the Program template first appeared in zmk 0.1. a true OG. ✨


πŸ’– AUTHORS πŸ’–

Zygmunt Krynicki <me@zygoon.pl> β€” thank you for your service, king. πŸ«‘πŸ‘‘


and that's the whole page, bestie!! this was zmk 0.5.1, dated May 3, 2020 β€” go forth and compile something iconic. mwah. πŸ’…βœ¨πŸŽ€