Skip to content

Instantly share code, notes, and snippets.

@zachriggle
Last active February 2, 2021 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachriggle/37bf8e360aeec512ce5a0a5bbde20e2b to your computer and use it in GitHub Desktop.
Save zachriggle/37bf8e360aeec512ce5a0a5bbde20e2b to your computer and use it in GitHub Desktop.
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