87 lines
3.5 KiB
Makefile
87 lines
3.5 KiB
Makefile
#
|
|
# VARIABLES/MACROS
|
|
#
|
|
CFLAGS= -Wfatal-errors -Wall -Wextra -Werror=discarded-qualifiers -Werror=ignored-qualifiers
|
|
LDFLAGS= -g3 -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= libpar.a
|
|
TESTS_i386= $(notdir $(basename $(shell find tests/i386/ -name '*.par'))) $(notdir $(basename $(shell find tests/all/ -name '*.par')))
|
|
TESTS_x86_64= $(notdir $(basename $(shell find tests/x86_64/ -name '*.par'))) $(notdir $(basename $(shell find tests/all/ -name '*.par')))
|
|
TESTS_CORE= $(notdir $(basename $(shell find tests/core/ -name '*.c')))
|
|
PAR= ./par
|
|
#VALGRIND ?= valgrind --leak-check=full --log-file=$(@D)/valgrind.$*
|
|
PREFIX ?= /usr/local
|
|
|
|
#
|
|
# MAIN TARGETS
|
|
#
|
|
.PHONY: FORCE
|
|
all: par
|
|
libpar.a: $(OBJS)
|
|
$(AR) rc $@ $^
|
|
version.h:
|
|
./update_ver.sh
|
|
par: version.h main.o libpar.a
|
|
$(CC) $(filter-out %.h, $^) -o $@ $(LDFLAGS)
|
|
tests_i386: par tests/i386/bin $(addprefix tests/i386/bin/, $(TESTS_i386)) $(addprefix tests/i386/bin/, $(TESTS_i386)) FORCE
|
|
tests_x86_64: par tests/x86_64/bin $(addprefix tests/x86_64/bin/, $(TESTS_x86_64)) FORCE
|
|
tests: par tests_i386 tests_x86_64 FORCE
|
|
@./tests/dotests.sh tests
|
|
tests_core: $(LIB) tests/core/bin $(addprefix tests/core/bin/, $(TESTS_CORE)) FORCE
|
|
|
|
#
|
|
# 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/%.par par
|
|
$(VALGRIND) $(PAR) -m x86_64 -o $@ $<
|
|
tests/x86_64/bin/%.s: tests/all/%.par par
|
|
$(VALGRIND) $(PAR) -m x86_64 -o $@ $<
|
|
tests/i386/bin/%.s: tests/all/%.par par
|
|
$(VALGRIND) $(PAR) -m i386 -o $@ $<
|
|
tests/i386/bin/%.s: tests/i386/%.par par
|
|
$(VALGRIND) $(PAR) -m i386 -o $@ $<
|
|
tests/i386/bin/%: tests/i386/bin/%.s
|
|
$(CC) -m32 $^ -o $@ $(LDFLAGS)
|
|
%.s: %.par par
|
|
$(PAR) $<
|
|
%.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 par (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/par.vim $(DESTDIR)$(HOME)/.vim/syntax/
|
|
install -m 644 ./vimfiles/ftdetect/par.vim $(DESTDIR)$(HOME)/.vim/ftdetect/
|
|
completion/par: completion/par_template
|
|
cd completion && PAR=../par ./make_completion.sh
|
|
install_shell_completion: par completion/par FORCE | /usr/share/bash-completion/completions
|
|
@sed -i "s/ARCHES=.*/ARCHES='$(shell ./par --list-arches|column)'/" completion/par
|
|
install -m 644 completion/par /usr/share/bash-completion/completions/
|
|
install_docs: FORCE | $(DESTDIR)$(PREFIX)/man/man1
|
|
install par.1 $(DESTDIR)$(PREFIX)/man/man1/
|
|
install_all: install install_vimfiles install_shell_completion FORCE
|
|
install: par install_docs $(DESTDIR)$(PREFIX)/bin FORCE
|
|
install -m 755 par $(DESTDIR)$(PREFIX)/bin/
|
|
clean:
|
|
$(RM) a.out *.o $(OBJS) par libpar.a $(addprefix tests/x86_64/bin/, *.s *.o $(TESTS_x86_64)) tests/core/bin/* tests/x86_64/bin/* listing version.h completion/par
|