Skip to content

Instantly share code, notes, and snippets.

@subnut
Created January 1, 2024 08:16
Show Gist options
  • Save subnut/b931993c3cf5cbb12516b2501059816a to your computer and use it in GitHub Desktop.
Save subnut/b931993c3cf5cbb12516b2501059816a to your computer and use it in GitHub Desktop.
Makefile.in example
.POSIX:
all:
LDFLAGS = -ltree-sitter
CFLAGS = -Wall -O3
CC = cc
TARGETS = main
main_SRCS = \
main.c \
parser.c
all: $(TARGETS)
clean: ; rm -f $(TARGETS) *.o
.SUFFIXES:
.SUFFIXES: .c .o
.c.o: ; $(CC) $(CFLAGS) -c -o $@ $<
.o: ; $(CC) $(LDFLAGS) -o $@ $($*_SRCS:.c=.o)
### EOF ###
Makefile: Makefile.in
@ sed -n '/^### EOF ###$$/q;p' Makefile.in > Makefile $@
@ echo >>Makefile 'all: Makefile'
@ echo >>Makefile 'Makefile: Makefile.in'
@ echo >>Makefile 'Makefile: ; @ $$(MAKE) -f $$@.in $$@; sh -c "exit 1"; '
@ echo >>Makefile
@ for target in $(TARGETS); do \
printf '%s: $$(%s_SRCS:.c=.o)\n' "$${target}" "$${target}" >> $@; \
done
@ echo "Makefile updated. Please re-run make."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment