~sircmpwn/annotatec

51697e5572b76d91e5d7a2a23ce49428eef79359 — Michael Forney 7 months ago 3bb602f
Improve POSIX-compatibility of Makefile

* Add .POSIX special target so make(1) processes it as a POSIX Makefile.
* Use inference rules instead of GNU make pattern rules.
* Avoid use of $< outside of inference rules.
* Add an `all` target as the first target in the file, making it the
  default.
* Avoid use of $^.
* Split yacc(1) options into separate arguments (causes problems with
  FreeBSD yacc).

Though .PHONY, `:=`, `+=`, and `?=` aren't in POSIX.1-2008, they are
left since they are widely supported and accepted for inclusion in the
next edition of POSIX[0][1].

Tested with GNU make, OpenBSD make, FreeBSD make, and bmake.

[0] http://austingroupbugs.net/view.php?id=523
[1] http://austingroupbugs.net/view.php?id=330
1 files changed, 8 insertions(+), 5 deletions(-)

M Makefile
M Makefile => Makefile +8 -5
@@ 1,4 1,5 @@
.DEFAULT_GOAL=annotatec
.POSIX:

PREFIX?=/usr/local

CFLAGS+=-g -Wall -Wextra -Wpedantic -Werror \


@@ 11,19 12,21 @@ OBJECTS:=\
	main.o \
	graph.o

all: annotatec

lang.yy.c: lang.l lang.tab.h
	lex -t $< > $@
	lex -t lang.l > $@

lang.tab.c: lang.y
	yacc -dblang $<
	yacc -d -b lang lang.y

lang.tab.h: lang.tab.c

%.o: %.c
.c.o:
	$(CC) -std=c99 -pedantic -c -o $@ $(CFLAGS) $<

annotatec: $(OBJECTS)
	$(CC) $(LDFLAGS) -o $@ $^
	$(CC) $(LDFLAGS) -o $@ $(OBJECTS)

clean:
	rm -f *.o lang.yy.c lang.tab.c lang.tab.h annotatec