1 of 6

Metaprogramming

Adapted from “The Missing Semester of Your CS Education” from MIT, found at https://missing.csail.mit.edu/, licensed under CC BY-NC-SA 4.0.

2 of 6

What is metaprogramming?

  • It is a broad general term to describe programming tools that assist in the writing and compiling of code
  • Generally includes the use of build tools like make for general use and also language specific build tools like cargo, pip, gomod, etc.

Adapted from “The Missing Semester of Your CS Education” from MIT, found at https://missing.csail.mit.edu/, licensed under CC BY-NC-SA 4.0.

3 of 6

Make

  • Make is the most popular and widespread build system, especially on Unix systems.
  • Make uses a syntax like this:

test: test.c test-case.txt

Gcc -g3 -std=gnu99 -Wall -Wextra -Werror -O2 -o test

  • Which is included in the makefile for a project
  • This is called a target

Adapted from “The Missing Semester of Your CS Education” from MIT, found at https://missing.csail.mit.edu/, licensed under CC BY-NC-SA 4.0.

4 of 6

Target

  • Targets in make have a name, dependencies, and a sequence of commands associated with it
  • The first target in the list is the default target so if you type make with no arguments it will default to the first target
  • Otherwise, to execute a target you simply use make + target name
  • There are also two special targets called clean and all
    • Clean deletes all of the generated files as specified in the makefile
    • All will run all the targets except clean
    • These are ‘phony’ targets since they don’t correspond to a file of the same name

Adapted from “The Missing Semester of Your CS Education” from MIT, found at https://missing.csail.mit.edu/, licensed under CC BY-NC-SA 4.0.

5 of 6

Activity

  • Clone this repository and play around with the different targets

https://github.com/Michael-R-Waggoner/metaprogramming/tree/main

Adapted from “The Missing Semester of Your CS Education” from MIT, found at https://missing.csail.mit.edu/, licensed under CC BY-NC-SA 4.0.

6 of 6

Other Build Systems

  • Individual languages come with their own build and dependency management tools
  • Rust uses cargo/rustup/rustc for building but cargo specifically is responsible for dependency management
  • Go uses go mod for the same
  • Python uses pip for dependency management

Adapted from “The Missing Semester of Your CS Education” from MIT, found at https://missing.csail.mit.edu/, licensed under CC BY-NC-SA 4.0.