Skip to content

Instantly share code, notes, and snippets.

@jpralves
Created November 6, 2024 18:17
Show Gist options
  • Save jpralves/3ac49f7232554f505bd2a833c519c945 to your computer and use it in GitHub Desktop.
Save jpralves/3ac49f7232554f505bd2a833c519c945 to your computer and use it in GitHub Desktop.
Makefile without tabs

Purpose

Original Makefile require the use of TABs to express recipes. I really hate TABs. They are the remnants of the dot matrix printers. In this simple example I'll show you how to use Makefiles without TABs!

Add the following to the beginning of the Makefile

.RECIPEPREFIX = >

Then each recipe can be written like this:

helloworld: helloworld.c
> $(CC) $(CFLAGS) -o $@ $<

Download all files for working example.

#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello World\n");
return 0;
}
.RECIPEPREFIX = >
.PHONY: all
CFLAGS = -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion
%.o : %.c
> $(CC) -c $(CFLAGS) -o $@ $<
all: helloworld
helloworld: helloworld.c
> $(CC) $(CFLAGS) -o $@ $<
clean:
> rm -f *.o helloworld
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment