Skip to content

Instantly share code, notes, and snippets.

@zachriggle

zachriggle/Makefile

Last active Feb 2, 2021
Embed
What would you like to do?
Makefile polyglot

Makefile and C Polyglot

Neat little trick to have a file that is both a valid Makefile and valid C source, and compiles and runs itself.

Usage

make
#if 0
.PHONY: run
run: a.out
@./a.out
a.out: $(MAKEFILE_LIST)
@gcc -xc $(MAKEFILE_LIST)
ifeq (0, 1)
#endif
#include <stdio.h>
int main()
{
puts("Hello, world");
return 0;
}
#define endif
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment