-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
82 lines (66 loc) · 2.37 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
UNAME := $(shell uname) ## Prone to error (in windows)
ARCHT := $(shell uname -m)
UNAMEP:= $(shell uname -smr)
CC=gcc
RNAME := $(shell cat /dev/random | head -c 32 | md5sum | head -c 12)
NM="ndrc"
all: help
## Run
run: build ## Build and run. Use FILE="math file".
@echo "#########-> Running Parser"
@comp/parser -f $(FILE) -o comp/$(RNAME).as
@echo "Built on " >> comp/$(RNAME).as
@date >> comp/$(RNAME).as
@echo "#########-> Running Assembler"
@comp/ndrasm comp/$(RNAME).as -o comp/$(RNAME).mem
@echo "#########-> Running Virtual Machine"
@comp/ndrvm -f comp/$(RNAME).mem
## Build
build: build-psr build-vm build-asm ## Build project and and link all files
## Run Build
runb: ## Run a previous made build
build-psr: ## Build the parser
@cd parser;$(CC) -o ../comp/parser main.c parser.c lexer.c
build-psr-run: build-psr ## Build the parser and run it against FILE="math file"
@cd parser; comp/parser -f $(FILE) -o comp/$(RNAME).as
build-vm: ## Build the virtual machine
@cd vm;$(CC) -o ../comp/ndrvm main.c machine.c
build-vm-run: build-vm ## Build the virtual machine and run it
@cd vm; ../comp/ndrvm
build-asm: ## Build assembler
@cd assembler;$(CC) -o ../comp/ndrasm main.c assembler.c utils.c table/table.c table/LL.c
build-asm-run: build-asm ## Build assembler and run it
@cd assembler; ../comp/ndrasm
## Test
test: build ## Run tests of the project
@echo "#########-> Running Parser"
@echo "5 + 5 + 5" > comp/$(RNAME).mth
@comp/parser -f comp/$(RNAME).mth -o comp/$(RNAME).as
@echo "Built on " >> comp/$(RNAME).as
@date >> comp/$(RNAME).as
@echo "#########-> Running Assembler"
@comp/ndrasm comp/$(RNAME).as -o comp/$(RNAME).mem
@echo "#########-> Running Virtual Machine"
@comp/ndrvm -f comp/$(RNAME).mem
@clear
@echo "No errors reported! COOL!"
@rm comp/*
## Clear
clear: ## Clear compilation garbage
@rm comp/*
## Help
help: ## Show this help
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)