103 lines
3.9 KiB
Makefile
103 lines
3.9 KiB
Makefile
#
|
|
# VARIABLES/MACROS
|
|
#
|
|
CFLAGS= -Wfatal-errors -Wall -Wextra -Werror=discarded-qualifiers -Werror=ignored-qualifiers
|
|
LDFLAGS= -no-pie -z noexecstack -lm
|
|
ASFLAGS=
|
|
OBJS= str.o tok.o vec.o lex.o pnode.o reg.o mem.o state.o err.o x86_64.o run.o ir.o gen.o i386.o sprint.o
|
|
LIB= liblr.a
|
|
TESTS_i386= $(notdir $(basename $(shell find tests/i386/ -name '*.lr'))) $(notdir $(basename $(shell find tests/all/ -name '*.lr')))
|
|
TESTS_x86_64= $(notdir $(basename $(shell find tests/x86_64/ -name '*.lr'))) $(notdir $(basename $(shell find tests/all/ -name '*.lr')))
|
|
TESTS_CORE= $(notdir $(basename $(shell find tests/core/ -name '*.c')))
|
|
LR ?= ./lr
|
|
#VALGRIND ?= valgrind --leak-check=full --log-file=$(@D)/valgrind.$*
|
|
PREFIX ?= /usr/local
|
|
|
|
# If DEBUG is defined, use further memory checks
|
|
ifdef DEBUG
|
|
CFLAGS += -fsanitize=address
|
|
LDFLAGS += -fsanitize=address -static-libasan
|
|
endif
|
|
|
|
# If RELEASE is defined, remove debug info, strip executable
|
|
ifdef RELEASE
|
|
CFLAGS += -g0
|
|
LDFLAGS += -s -static
|
|
else
|
|
CFLAGS += -g3
|
|
endif
|
|
|
|
#
|
|
# MAIN TARGETS
|
|
#
|
|
.PHONY: FORCE
|
|
all: lr
|
|
liblr.a: $(OBJS)
|
|
$(AR) rc $@ $^
|
|
version.h:
|
|
./update_ver.sh
|
|
lr: version.h main.o liblr.a
|
|
$(CC) $(filter-out %.h, $^) -o $@ $(LDFLAGS)
|
|
tests_i386: lr tests/i386/bin $(addprefix tests/i386/bin/, $(TESTS_i386)) $(addprefix tests/i386/bin/, $(TESTS_i386)) FORCE
|
|
tests_x86_64: lr tests/x86_64/bin $(addprefix tests/x86_64/bin/, $(TESTS_x86_64)) FORCE
|
|
tests: lr tests_i386 tests_x86_64 FORCE
|
|
@./tests/dotests.sh tests
|
|
tests_core: $(LIB) tests/core/bin $(addprefix tests/core/bin/, $(TESTS_CORE)) FORCE
|
|
fails: lr tests_i386 tests_x86_64 FORCE
|
|
@./tests/dotests.sh tests --color=always|grep -v OK
|
|
|
|
#
|
|
# IMPLICIT RULES
|
|
#
|
|
%.o: %.c %.h
|
|
$(CC) $< -c $(CFLAGS)
|
|
tests/i386/bin tests/x86_64/bin tests/core/bin:
|
|
@mkdir $@
|
|
tests/core/bin/%: tests/core/%.c $(LIB)
|
|
$(CC) $< -o $@ $(CFLAGS) $(LDFLAGS) $(LIB) -I.
|
|
tests/x86_64/bin/%.s: tests/x86_64/%.lr lr
|
|
$(VALGRIND) $(LR) -m x86_64 -o $@ $<
|
|
tests/x86_64/bin/%.s: tests/all/%.lr lr
|
|
$(VALGRIND) $(LR) -m x86_64 -o $@ $<
|
|
tests/i386/bin/%.s: tests/all/%.lr lr
|
|
$(VALGRIND) $(LR) -m i386 -o $@ $<
|
|
tests/i386/bin/%.s: tests/i386/%.lr lr
|
|
$(VALGRIND) $(LR) -m i386 -o $@ $<
|
|
tests/i386/bin/%: tests/i386/bin/%.s
|
|
$(CC) -m32 $^ -o $@ $(LDFLAGS)
|
|
%.s: %.lr lr
|
|
$(LR) $<
|
|
%.o: %.s
|
|
$(AS) $(ASFLAGS) $< -o $@
|
|
%: %.o
|
|
$(CC) $^ -o $@ $(LDFLAGS)
|
|
|
|
#
|
|
# HELP, INSTALL, CLEAN
|
|
#
|
|
/usr/share/bash-completion/completions $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/man/man1 $(DESTDIR)$(HOME)/.vim/ftdetect $(DESTDIR)$(HOME)/.vim/syntax:
|
|
@mkdir -p $@
|
|
help:
|
|
@printf "Targets\n"
|
|
@printf " all Build lr (default)\n"
|
|
@printf " clean Remove build files\n"
|
|
@printf " tests Build and run tests\n"
|
|
@printf " tests_core Build lib tests\n"
|
|
@printf " install_vimfiles Install syntax files in ~/.vim/\n"
|
|
@printf " install_shell_completion Install bash completion files in /usr/\n"
|
|
install_vimfiles: FORCE | $(DESTDIR)$(HOME)/.vim/ftdetect $(DESTDIR)$(HOME)/.vim/syntax
|
|
install -m 644 ./vimfiles/syntax/lr.vim $(DESTDIR)$(HOME)/.vim/syntax/
|
|
install -m 644 ./vimfiles/ftdetect/lr.vim $(DESTDIR)$(HOME)/.vim/ftdetect/
|
|
completion/lr: completion/lr_template
|
|
cd completion && LR=../lr ./make_completion.sh
|
|
install_shell_completion: lr completion/lr FORCE | /usr/share/bash-completion/completions
|
|
@sed -i "s/ARCHES=.*/ARCHES='$(shell ./lr --list-arches|column)'/" completion/lr
|
|
install -m 644 completion/lr /usr/share/bash-completion/completions/
|
|
install_docs: FORCE | $(DESTDIR)$(PREFIX)/man/man1
|
|
install lr.1 $(DESTDIR)$(PREFIX)/man/man1/
|
|
install_all: install install_vimfiles install_shell_completion FORCE
|
|
install: lr install_docs $(DESTDIR)$(PREFIX)/bin FORCE
|
|
install -m 755 lr $(DESTDIR)$(PREFIX)/bin/
|
|
clean:
|
|
$(RM) a.out *.o $(OBJS) lr liblr.a $(addprefix tests/x86_64/bin/, *.s *.o $(TESTS_x86_64)) tests/core/bin/* tests/x86_64/bin/* listing version.h completion/lr
|