Makefiles

Work In Progress

This article is work in progress! Check back soon for a full writeup.

Makefile Tier: Stupid

main:
  rm -rf main
  gcc file1.c file2.c -o $@

Makefile Tier: Novice

main: file1.c file2.c
  gcc file1.c file2.c -o $@

Makefile Tier Beginner

file1.o: file1.c
  gcc -c file1.c

file2.o: file1.c
  gcc -c file2.c

main: file1.o file2.o
  gcc file1.o file2.o -o $@

Makefile Tier Intermediate

OBJS=file1.o file2.o

%.o: %.c
  gcc -c $^ -o $@
  ${info compiled $^!!}


main: $(OBJS)
  gcc -fsanitize=address -fno-strict-aliasing -fno-stack-protector -fpie $^ -o $@

Makefile Tier Pro

CC=gcc
CFLAGS=-fsanitize=address -fno-strict-aliasing -fno-stack-protector -fpie 
OBJS=file1.o file2.o

main: $(OBJS)
  $(CC) $(CFLAGS) $^ -o $@

Makefile Tier Legend

CC=gcc
CFLAGS=-fsanitize=address -fno-strict-aliasing -fno-stack-protector -fpie 
OBJS=file1.o file2.o

depend: .depend
  gcc -MM *.c > .depend

include .depend

main: $(OBJS) depend
  $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

Tangent: Non C Makefiles

LaTeX

%.pdf: %.tex
  pdflatex $^

clean:
  rm -rf *.log *.aux

.PHONY clean

Other

Basically anytime you want to run command(s) when some input files are NEWER than some output files.

Makefile Tier BRAIN DAMAGE

Brain damage begins here

See LUG Website!

Utils

touch *.c
(org-babel-result-hide-all)