2020-05-10 08:47:10 +03:00
|
|
|
CFLAGS=-std=c11 -g -fno-common -Wall -Wno-switch
|
2020-09-04 13:03:01 +03:00
|
|
|
|
2020-10-07 14:11:16 +03:00
|
|
|
SRCS=$(wildcard *.c)
|
|
|
|
OBJS=$(SRCS:.c=.o)
|
2019-08-03 05:29:50 +03:00
|
|
|
|
2020-09-04 13:03:01 +03:00
|
|
|
TEST_SRCS=$(wildcard test/*.c)
|
|
|
|
TESTS=$(TEST_SRCS:.c=.exe)
|
|
|
|
|
2019-08-24 06:08:12 +03:00
|
|
|
# Stage 1
|
|
|
|
|
2020-10-07 14:11:16 +03:00
|
|
|
chibicc: $(OBJS)
|
|
|
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
|
|
|
|
|
|
|
$(OBJS): chibicc.h
|
2019-08-03 05:29:50 +03:00
|
|
|
|
2020-09-04 13:03:01 +03:00
|
|
|
test/%.exe: chibicc test/%.c
|
2020-08-30 12:49:29 +03:00
|
|
|
./chibicc -Iinclude -Itest -c -o test/$*.o test/$*.c
|
2020-09-07 04:02:10 +03:00
|
|
|
$(CC) -pthread -o $@ test/$*.o -xc test/common
|
2020-09-04 13:03:01 +03:00
|
|
|
|
|
|
|
test: $(TESTS)
|
|
|
|
for i in $^; do echo $$i; ./$$i || exit 1; echo; done
|
2019-08-24 06:08:12 +03:00
|
|
|
test/driver.sh ./chibicc
|
|
|
|
|
|
|
|
test-all: test test-stage2
|
|
|
|
|
|
|
|
# Stage 2
|
|
|
|
|
|
|
|
stage2/chibicc: $(OBJS:%=stage2/%)
|
|
|
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
|
|
|
|
2020-08-30 12:49:29 +03:00
|
|
|
stage2/%.o: chibicc %.c
|
2019-08-24 06:08:12 +03:00
|
|
|
mkdir -p stage2/test
|
2020-08-30 12:49:29 +03:00
|
|
|
./chibicc -c -o $(@D)/$*.o $*.c
|
2019-08-24 06:08:12 +03:00
|
|
|
|
|
|
|
stage2/test/%.exe: stage2/chibicc test/%.c
|
|
|
|
mkdir -p stage2/test
|
2020-08-30 12:58:41 +03:00
|
|
|
./stage2/chibicc -Iinclude -Itest -c -o stage2/test/$*.o test/$*.c
|
2020-09-07 04:02:10 +03:00
|
|
|
$(CC) -pthread -o $@ stage2/test/$*.o -xc test/common
|
2019-08-24 06:08:12 +03:00
|
|
|
|
|
|
|
test-stage2: $(TESTS:test/%=stage2/test/%)
|
|
|
|
for i in $^; do echo $$i; ./$$i || exit 1; echo; done
|
|
|
|
test/driver.sh ./stage2/chibicc
|
|
|
|
|
|
|
|
# Misc.
|
2019-08-03 05:29:50 +03:00
|
|
|
|
|
|
|
clean:
|
2019-08-24 06:08:12 +03:00
|
|
|
rm -rf chibicc tmp* $(TESTS) test/*.s test/*.exe stage2
|
2020-09-04 13:03:01 +03:00
|
|
|
find * -type f '(' -name '*~' -o -name '*.o' ')' -exec rm {} ';'
|
2019-08-03 05:29:50 +03:00
|
|
|
|
2019-08-24 06:08:12 +03:00
|
|
|
.PHONY: test clean test-stage2
|