Skip to content

Instantly share code, notes, and snippets.

@skeeto
Created December 25, 2021 23:14
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 skeeto/b07bbfbf8ec7d4075685e8e9f0a7a888 to your computer and use it in GitHub Desktop.
Save skeeto/b07bbfbf8ec7d4075685e8e9f0a7a888 to your computer and use it in GitHub Desktop.
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