v
1CC ?= cc
2CFLAGS ?=
3LDFLAGS ?=
4TMPDIR ?= /tmp
5VC ?= ./vc
6
7VCFILE := v.c
8TMPTCC := /var/tmp/tcc
9VCREPO := https://github.com/vlang/vc
10TCCREPO := https://github.com/vlang/tccbin
11GITCLEANPULL := git clean -xf && git pull --quiet
12GITFASTCLONE := git clone --depth 1 --quiet
13
14#### Platform detections and overrides:
15_SYS := $(shell uname 2>/dev/null || echo Unknown)
16_SYS := $(patsubst MSYS%,MSYS,$(_SYS))
17_SYS := $(patsubst MINGW%,MinGW,$(_SYS))
18
19ifneq ($(filter $(_SYS),MSYS MinGW),)
20WIN32 := 1
21endif
22
23ifeq ($(_SYS),Linux)
24LINUX := 1
25endif
26
27ifeq ($(_SYS),Darwin)
28MAC := 1
29endif
30
31ifeq ($(_SYS),FreeBSD)
32LDFLAGS += -lexecinfo
33endif
34
35ifdef ANDROID_ROOT
36ANDROID := 1
37undefine LINUX
38endif
39#####
40
41ifdef WIN32
42TCCREPO := https://github.com/vlang/tccbin_win
43VCFILE := v_win.c
44endif
45
46all: latest_vc latest_tcc
47ifdef WIN32
48 $(CC) $(CFLAGS) -g -std=c99 -municode -w -o v.exe $(VC)/$(VCFILE) $(LDFLAGS)
49ifdef prod
50 ./v.exe -prod self
51else
52 ./v.exe self
53endif
54else
55 $(CC) $(CFLAGS) -g -std=gnu11 -w -o v $(VC)/$(VCFILE) $(LDFLAGS) -lm -lpthread
56ifdef ANDROID
57 chmod 755 v
58endif
59
60ifdef prod
61 ./v -prod self
62else
63 ./v self
64endif
65
66ifndef ANDROID
67 $(MAKE) modules
68endif
69endif
70 @echo "V has been successfully built"
71 @./v -version
72
73#clean: clean_tmp
74#git clean -xf
75
76clean:
77 rm -rf $(TMPTCC)
78 rm -rf $(VC)
79
80latest_vc: $(VC)/.git/config
81ifndef local
82 cd $(VC) && $(GITCLEANPULL)
83else
84 @echo "Using local vc"
85endif
86
87fresh_vc:
88 $(GITFASTCLONE) $(VCREPO) $(VC)
89
90latest_tcc: $(TMPTCC)/.git/config
91ifndef ANDROID
92ifndef MAC
93ifndef local
94 cd $(TMPTCC) && $(GITCLEANPULL)
95else
96 @echo "Using local tcc"
97endif
98endif
99endif
100
101fresh_tcc:
102ifndef ANDROID
103ifndef MAC
104 rm -rf $(TMPTCC)
105 $(GITFASTCLONE) $(TCCREPO) $(TMPTCC)
106endif
107endif
108
109$(TMPTCC)/.git/config:
110ifndef MAC
111 $(MAKE) fresh_tcc
112endif
113
114$(VC)/.git/config:
115 $(MAKE) fresh_vc
116
117selfcompile:
118 ./v -cg -o v cmd/v
119
120selfcompile-static:
121 ./v -cg -cflags '--static' -o v-static cmd/v
122
123modules: module_builtin module_strings module_strconv
124module_builtin:
125 #./v build module vlib/builtin > /dev/null
126module_strings:
127 #./v build module vlib/strings > /dev/null
128module_strconv:
129 #./v build module vlib/strconv > /dev/null