v
1CC ?= cc
2CFLAGS ?=
3LDFLAGS ?=
4TMPDIR ?= /tmp
5VROOT ?= .
6VC ?= ./vc
7V ?= ./v
8VCREPO ?= https://github.com/vlang/vc
9TCCREPO ?= https://github.com/vlang/tccbin
10
11VCFILE := v.c
12TMPTCC := $(VROOT)/thirdparty/tcc
13TCCOS := unknown
14TCCARCH := unknown
15GITCLEANPULL := git clean -xf && git pull --quiet
16GITFASTCLONE := git clone --depth 1 --quiet --single-branch
17
18#### Platform detections and overrides:
19_SYS := $(shell uname 2>/dev/null || echo Unknown)
20_SYS := $(patsubst MSYS%,MSYS,$(_SYS))
21_SYS := $(patsubst MINGW%,MinGW,$(_SYS))
22
23ifneq ($(filter $(_SYS),MSYS MinGW),)
24WIN32 := 1
25V:=./v.exe
26endif
27
28ifeq ($(_SYS),Linux)
29LINUX := 1
30TCCOS := linux
31endif
32
33ifeq ($(_SYS),Darwin)
34MAC := 1
35TCCOS := macos
36endif
37
38ifeq ($(_SYS),FreeBSD)
39TCCOS := freebsd
40LDFLAGS += -lexecinfo
41endif
42
43ifdef ANDROID_ROOT
44ANDROID := 1
45undefine LINUX
46TCCOS := android
47endif
48#####
49
50ifdef WIN32
51TCCOS := windows
52VCFILE := v_win.c
53endif
54
55TCCARCH := $(shell uname -m 2>/dev/null || echo unknown)
56
57ifeq ($(TCCARCH),x86_64)
58 TCCARCH := amd64
59else
60ifneq ($(filter x86%,$(TCCARCH)),)
61 TCCARCH := i386
62else
63ifeq ($(TCCARCH),aarch64)
64 TCCARCH := arm64
65else
66ifneq ($(filter arm%,$(TCCARCH)),)
67 TCCARCH := arm
68# otherwise, just use the arch name
69endif
70endif
71endif
72endif
73
74# note that a branch may not exist yet for the user's system configuration,
75# in that case they'll get an error from git while cloning it.
76# TODO: print a pretty error ourselves in that case, and ask the user to open a feature request
77TCCBRANCH := thirdparty-$(TCCOS)-$(TCCARCH)
78
79all: latest_vc latest_tcc
80ifdef WIN32
81 $(CC) $(CFLAGS) -g -std=c99 -municode -w -o $(V) $(VC)/$(VCFILE) $(LDFLAGS)
82ifdef prod
83 $(V) -prod self
84else
85 $(V) self
86endif
87else
88 $(CC) $(CFLAGS) -g -std=gnu99 -w -o $(V) $(VC)/$(VCFILE) -lm -lpthread $(LDFLAGS)
89ifdef ANDROID
90 chmod 755 v
91endif
92
93ifdef prod
94 $(V) -prod self
95else
96 $(V) self
97endif
98
99ifndef ANDROID
100 $(MAKE) modules
101endif
102endif
103 @echo "V has been successfully built"
104 @$(V) -version
105
106#clean: clean_tmp
107#git clean -xf
108
109clean:
110 rm -rf $(TMPTCC)
111 rm -rf $(VC)
112
113latest_vc: $(VC)/.git/config
114ifndef local
115 cd $(VC) && $(GITCLEANPULL)
116else
117 @echo "Using local vc"
118endif
119
120fresh_vc:
121 $(GITFASTCLONE) $(VCREPO) $(VC)
122
123latest_tcc: $(TMPTCC)/.git/config
124ifndef ANDROID
125ifndef local
126 cd $(TMPTCC) && $(GITCLEANPULL)
127else
128 @echo "Using local tcc"
129endif
130endif
131
132fresh_tcc:
133 rm -rf $(TMPTCC)
134 $(GITFASTCLONE) --branch $(TCCBRANCH) $(TCCREPO) $(TMPTCC)
135
136$(TMPTCC)/.git/config:
137 $(MAKE) fresh_tcc
138
139$(VC)/.git/config:
140 $(MAKE) fresh_vc
141
142selfcompile:
143 $(V) -cg -o v cmd/v
144
145selfcompile-static:
146 $(V) -cg -cflags '--static' -o v-static cmd/v
147
148modules: module_builtin module_strings module_strconv
149module_builtin:
150 #$(V) build module vlib/builtin > /dev/null
151module_strings:
152 #$(V) build module vlib/strings > /dev/null
153module_strconv:
154 #$(V) build module vlib/strconv > /dev/null