v2 / Makefile
123 lines · 117 sloc · 2.76 KB · 292f37da9c1efbc052ce61c3d8e98c174d15ba59
Raw
1CC ?= cc
2VFLAGS ?=
3CFLAGS ?=
4LDFLAGS ?=
5
6all: download_vc v
7
8.PHONY: all check download_vc install v
9
10download_vc:
11 @set -e; \
12 if [ -f vc/v.c ]; then \
13 if command -v git >/dev/null 2>&1; then \
14 git -C vc/ pull --rebase; \
15 else \
16 echo "git not found; using existing vc/v.c"; \
17 fi; \
18 else \
19 if command -v git >/dev/null 2>&1; then \
20 git clone --filter=blob:none https://github.com/vlang/vc vc/; \
21 else \
22 echo "git is required to download vc/. Please install git or provide vc/v.c."; \
23 exit 1; \
24 fi; \
25 fi
26
27v:
28 @set -e; \
29 sys=`uname -s 2>/dev/null || echo unknown`; \
30 arch=`uname -m 2>/dev/null || echo unknown`; \
31 set -- $(CFLAGS); \
32 ccflags=; \
33 unsafe_o=0; \
34 for arg do \
35 case "$$arg" in \
36 -O|-O0|-O1) \
37 ccflags="$$ccflags $$arg"; \
38 ;; \
39 -O*) \
40 ccflags="$$ccflags $$arg"; \
41 unsafe_o=1; \
42 ;; \
43 *) \
44 ccflags="$$ccflags $$arg"; \
45 ;; \
46 esac; \
47 done; \
48 ccflags=$${ccflags# }; \
49 bootstrap_ccflags=$$ccflags; \
50 set -- $(LDFLAGS); \
51 ldflags=; \
52 for arg do \
53 ldflags="$$ldflags $$arg"; \
54 done; \
55 ldflags=$${ldflags# }; \
56 case "$$sys" in \
57 Linux) \
58 case "$$arch" in \
59 arm*) \
60 ldflags="$$ldflags -latomic"; \
61 ;; \
62 esac; \
63 ;; \
64 FreeBSD|NetBSD|OpenBSD) \
65 ldflags="$$ldflags -lexecinfo"; \
66 ;; \
67 esac; \
68 ccflags=$${ccflags# }; \
69 ldflags=$${ldflags# }; \
70 if [ "$$sys" = Linux ]; then \
71 case "$$arch" in \
72 arm64|aarch64) \
73 if [ $$unsafe_o -eq 1 ]; then \
74 set -- $$ccflags; \
75 bootstrap_ccflags=; \
76 for arg do \
77 case "$$arg" in \
78 -O|-O0|-O1) \
79 bootstrap_ccflags="$$bootstrap_ccflags $$arg"; \
80 ;; \
81 -O*) \
82 bootstrap_ccflags="$$bootstrap_ccflags -O1"; \
83 ;; \
84 *) \
85 bootstrap_ccflags="$$bootstrap_ccflags $$arg"; \
86 ;; \
87 esac; \
88 done; \
89 bootstrap_ccflags=$${bootstrap_ccflags# }; \
90 fi; \
91 ;; \
92 esac; \
93 fi; \
94 $(CC) $$bootstrap_ccflags -std=gnu11 -w -o v1 vc/v.c -lm -lpthread $$ldflags || cmd/tools/cc_compilation_failed_non_windows.sh; \
95 set -- ./v1 -no-parallel -o v2 $(VFLAGS); \
96 if [ -n "$$bootstrap_ccflags" ]; then \
97 set -- "$$@" -cflags "$$bootstrap_ccflags"; \
98 fi; \
99 if [ -n "$$ldflags" ]; then \
100 set -- "$$@" -ldflags "$$ldflags"; \
101 fi; \
102 set -- "$$@" cmd/v; \
103 "$$@"; \
104 set -- ./v2 -o v $(VFLAGS); \
105 if [ -n "$$ccflags" ]; then \
106 set -- "$$@" -cflags "$$ccflags"; \
107 fi; \
108 if [ -n "$$ldflags" ]; then \
109 set -- "$$@" -ldflags "$$ldflags"; \
110 fi; \
111 set -- "$$@" cmd/v; \
112 "$$@"; \
113 rm -rf v1 v2; \
114 ./v run ./cmd/tools/detect_tcc.v; \
115 echo "V has been successfully built"; \
116 ./v version; \
117 ./v run .github/problem-matchers/register_all.vsh
118
119check:
120 ./v test-all
121
122install:
123 @echo 'Please use `sudo ./v symlink` instead, or manually add the current directory to your PATH.'
124