Skip to content

Instantly share code, notes, and snippets.

@skeeto
Created Dec 25, 2021
Embed
What would you like to do?
Makefile generator for Enchive (example)
#!/bin/sh
set -e
cat <<EOF
CC = cc
CFLAGS = -Os -Wall -Wextra
LDFLAGS = -s
LDLIBS =
obj = $(find src/ -name '*.c' | LC_ALL=C sort | xargs printf 'build/%s.o ')
enchive: \$(obj)
\$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$(obj) \$(LDLIBS)
build:
mkdir -p build/src
clean:
rm -rf enchive build/
EOF
for file in $(find src/ -name '*.c' | LC_ALL=C sort); do
printf 'build/%s.o: build\n' $file
gcc -MM -MT build/$file.o $file
printf '\t$(CC) -c $(CFLAGS) -o $@ %s\n' $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment