2021-09-04 14:32:42 +03:00
|
|
|
CC ?= cc
|
|
|
|
CFLAGS ?=
|
|
|
|
LDFLAGS ?=
|
|
|
|
TMPDIR ?= /tmp
|
|
|
|
VROOT ?= .
|
|
|
|
VC ?= ./vc
|
2022-07-27 21:04:29 +03:00
|
|
|
VEXE ?= ./v
|
2021-09-04 14:32:42 +03:00
|
|
|
VCREPO ?= https://github.com/vlang/vc
|
|
|
|
TCCREPO ?= https://github.com/vlang/tccbin
|
2022-08-31 11:03:25 +03:00
|
|
|
LEGACYREPO ?= https://github.com/macports/macports-legacy-support
|
2021-09-04 14:32:42 +03:00
|
|
|
|
|
|
|
VCFILE := v.c
|
|
|
|
TMPTCC := $(VROOT)/thirdparty/tcc
|
2022-08-31 11:03:25 +03:00
|
|
|
LEGACYLIBS := $(VROOT)/thirdparty/legacy
|
|
|
|
TMPLEGACY := $(LEGACYLIBS)/source
|
2021-09-04 14:32:42 +03:00
|
|
|
TCCOS := unknown
|
|
|
|
TCCARCH := unknown
|
|
|
|
GITCLEANPULL := git clean -xf && git pull --quiet
|
|
|
|
GITFASTCLONE := git clone --depth 1 --quiet --single-branch
|
|
|
|
|
|
|
|
#### Platform detections and overrides:
|
|
|
|
_SYS := $(shell uname 2>/dev/null || echo Unknown)
|
|
|
|
_SYS := $(patsubst MSYS%,MSYS,$(_SYS))
|
|
|
|
_SYS := $(patsubst MINGW%,MinGW,$(_SYS))
|
|
|
|
|
|
|
|
ifneq ($(filter $(_SYS),MSYS MinGW),)
|
|
|
|
WIN32 := 1
|
2022-07-27 21:04:29 +03:00
|
|
|
VEXE := ./v.exe
|
2021-09-04 14:32:42 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(_SYS),Linux)
|
|
|
|
LINUX := 1
|
|
|
|
TCCOS := linux
|
2022-06-09 00:44:29 +03:00
|
|
|
ifneq ($(shell ldd /bin/ls | grep musl),)
|
|
|
|
TCCOS := linuxmusl
|
|
|
|
endif
|
2021-09-04 14:32:42 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(_SYS),Darwin)
|
|
|
|
MAC := 1
|
|
|
|
TCCOS := macos
|
2022-08-31 11:03:25 +03:00
|
|
|
ifeq ($(shell expr $(shell uname -r | cut -d. -f1) \<= 15), 1)
|
|
|
|
LEGACY := 1
|
|
|
|
endif
|
2021-09-04 14:32:42 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(_SYS),FreeBSD)
|
|
|
|
TCCOS := freebsd
|
|
|
|
LDFLAGS += -lexecinfo
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(_SYS),NetBSD)
|
|
|
|
TCCOS := netbsd
|
|
|
|
LDFLAGS += -lexecinfo
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef ANDROID_ROOT
|
|
|
|
ANDROID := 1
|
|
|
|
undefine LINUX
|
|
|
|
TCCOS := android
|
|
|
|
endif
|
|
|
|
#####
|
|
|
|
|
|
|
|
ifdef WIN32
|
|
|
|
TCCOS := windows
|
|
|
|
VCFILE := v_win.c
|
|
|
|
endif
|
|
|
|
|
|
|
|
TCCARCH := $(shell uname -m 2>/dev/null || echo unknown)
|
|
|
|
|
|
|
|
ifeq ($(TCCARCH),x86_64)
|
|
|
|
TCCARCH := amd64
|
|
|
|
else
|
|
|
|
ifneq ($(filter x86%,$(TCCARCH)),)
|
|
|
|
TCCARCH := i386
|
|
|
|
else
|
|
|
|
ifeq ($(TCCARCH),arm64)
|
|
|
|
TCCARCH := arm64
|
|
|
|
else
|
|
|
|
ifneq ($(filter arm%,$(TCCARCH)),)
|
|
|
|
TCCARCH := arm
|
|
|
|
# otherwise, just use the arch name
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2022-11-08 17:51:29 +03:00
|
|
|
.PHONY: all clean rebuild check fresh_vc fresh_tcc fresh_legacy check_for_working_tcc
|
2021-09-04 14:32:42 +03:00
|
|
|
|
|
|
|
ifdef prod
|
|
|
|
VFLAGS+=-prod
|
|
|
|
endif
|
|
|
|
|
2022-08-31 11:03:25 +03:00
|
|
|
all: latest_vc latest_tcc latest_legacy
|
2021-09-04 14:32:42 +03:00
|
|
|
ifdef WIN32
|
2022-04-21 00:12:50 +03:00
|
|
|
$(CC) $(CFLAGS) -std=c99 -municode -w -o v1.exe $(VC)/$(VCFILE) $(LDFLAGS)
|
2021-09-28 11:38:33 +03:00
|
|
|
v1.exe -no-parallel -o v2.exe $(VFLAGS) cmd/v
|
2022-07-27 21:04:29 +03:00
|
|
|
v2.exe -o $(VEXE) $(VFLAGS) cmd/v
|
2021-09-28 11:38:33 +03:00
|
|
|
del v1.exe
|
|
|
|
del v2.exe
|
2021-09-04 14:32:42 +03:00
|
|
|
else
|
2022-08-31 11:03:25 +03:00
|
|
|
ifdef LEGACY
|
|
|
|
$(MAKE) -C $(TMPLEGACY)
|
|
|
|
$(MAKE) -C $(TMPLEGACY) PREFIX=$(realpath $(LEGACYLIBS)) CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) install
|
|
|
|
rm -rf $(TMPLEGACY)
|
|
|
|
$(eval override LDFLAGS+=-L$(realpath $(LEGACYLIBS))/lib -lMacportsLegacySupport)
|
|
|
|
endif
|
2022-04-21 00:12:50 +03:00
|
|
|
$(CC) $(CFLAGS) -std=gnu99 -w -o v1.exe $(VC)/$(VCFILE) -lm -lpthread $(LDFLAGS)
|
2021-09-28 11:38:33 +03:00
|
|
|
./v1.exe -no-parallel -o v2.exe $(VFLAGS) cmd/v
|
2022-07-27 21:04:29 +03:00
|
|
|
./v2.exe -o $(VEXE) $(VFLAGS) cmd/v
|
2021-09-28 11:38:33 +03:00
|
|
|
rm -rf v1.exe v2.exe
|
2021-09-04 14:32:42 +03:00
|
|
|
endif
|
2022-07-27 21:04:29 +03:00
|
|
|
@$(VEXE) run cmd/tools/detect_tcc.v
|
2021-09-04 14:32:42 +03:00
|
|
|
@echo "V has been successfully built"
|
2022-07-27 21:04:29 +03:00
|
|
|
@$(VEXE) -version
|
2021-09-04 14:32:42 +03:00
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf $(TMPTCC)
|
2022-08-31 11:03:25 +03:00
|
|
|
rm -rf $(LEGACYLIBS)
|
2021-09-04 14:32:42 +03:00
|
|
|
rm -rf $(VC)
|
|
|
|
|
2022-11-08 17:51:29 +03:00
|
|
|
rebuild: clean all
|
|
|
|
|
2021-09-04 14:32:42 +03:00
|
|
|
ifndef local
|
|
|
|
latest_vc: $(VC)/.git/config
|
|
|
|
cd $(VC) && $(GITCLEANPULL)
|
|
|
|
else
|
|
|
|
latest_vc:
|
|
|
|
@echo "Using local vc"
|
|
|
|
endif
|
|
|
|
|
2022-01-18 18:25:11 +03:00
|
|
|
check_for_working_tcc:
|
|
|
|
@$(TMPTCC)/tcc.exe --version > /dev/null 2> /dev/null || echo "The executable '$(TMPTCC)/tcc.exe' does not work."
|
2022-06-09 00:44:29 +03:00
|
|
|
|
2021-09-04 14:32:42 +03:00
|
|
|
fresh_vc:
|
|
|
|
rm -rf $(VC)
|
|
|
|
$(GITFASTCLONE) $(VCREPO) $(VC)
|
|
|
|
|
|
|
|
ifndef local
|
|
|
|
latest_tcc: $(TMPTCC)/.git/config
|
2022-01-18 18:42:29 +03:00
|
|
|
cd $(TMPTCC) && $(GITCLEANPULL)
|
2022-01-18 18:25:11 +03:00
|
|
|
@$(MAKE) --quiet check_for_working_tcc 2> /dev/null
|
2021-09-04 14:32:42 +03:00
|
|
|
else
|
|
|
|
latest_tcc:
|
|
|
|
@echo "Using local tcc"
|
2022-01-18 18:25:11 +03:00
|
|
|
@$(MAKE) --quiet check_for_working_tcc 2> /dev/null
|
2021-09-04 14:32:42 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
fresh_tcc:
|
|
|
|
rm -rf $(TMPTCC)
|
|
|
|
ifndef local
|
|
|
|
# Check wether a TCC branch exists for the user's system configuration.
|
|
|
|
ifneq (,$(findstring thirdparty-$(TCCOS)-$(TCCARCH), $(shell git ls-remote --heads $(TCCREPO) | sed 's/^[a-z0-9]*\trefs.heads.//')))
|
|
|
|
$(GITFASTCLONE) --branch thirdparty-$(TCCOS)-$(TCCARCH) $(TCCREPO) $(TMPTCC)
|
2022-01-18 18:25:11 +03:00
|
|
|
@$(MAKE) --quiet check_for_working_tcc 2> /dev/null
|
2021-09-04 14:32:42 +03:00
|
|
|
else
|
|
|
|
@echo 'Pre-built TCC not available for thirdparty-$(TCCOS)-$(TCCARCH) at $(TCCREPO), will use the system compiler: $(CC)'
|
|
|
|
$(GITFASTCLONE) --branch thirdparty-unknown-unknown $(TCCREPO) $(TMPTCC)
|
2022-01-18 18:25:11 +03:00
|
|
|
@$(MAKE) --quiet check_for_working_tcc 2> /dev/null
|
2021-09-04 14:32:42 +03:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
@echo "Using local tccbin"
|
2022-01-18 18:25:11 +03:00
|
|
|
@$(MAKE) --quiet check_for_working_tcc 2> /dev/null
|
2021-09-04 14:32:42 +03:00
|
|
|
endif
|
|
|
|
|
2022-08-31 11:03:25 +03:00
|
|
|
ifndef local
|
|
|
|
latest_legacy: $(TMPLEGACY)/.git/config
|
|
|
|
ifdef LEGACY
|
|
|
|
cd $(TMPLEGACY) && $(GITCLEANPULL)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
latest_legacy:
|
|
|
|
ifdef LEGACY
|
|
|
|
@echo "Using local legacysupport"
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
fresh_legacy:
|
|
|
|
rm -rf $(LEGACYLIBS)
|
|
|
|
$(GITFASTCLONE) $(LEGACYREPO) $(TMPLEGACY)
|
|
|
|
|
2021-09-04 14:32:42 +03:00
|
|
|
$(TMPTCC)/.git/config:
|
|
|
|
$(MAKE) fresh_tcc
|
|
|
|
|
|
|
|
$(VC)/.git/config:
|
|
|
|
$(MAKE) fresh_vc
|
|
|
|
|
2022-08-31 11:03:25 +03:00
|
|
|
$(TMPLEGACY)/.git/config:
|
|
|
|
ifdef LEGACY
|
|
|
|
$(MAKE) fresh_legacy
|
|
|
|
endif
|
|
|
|
|
2021-09-04 14:32:42 +03:00
|
|
|
asan:
|
|
|
|
$(MAKE) all CFLAGS='-fsanitize=address,undefined'
|
|
|
|
|
|
|
|
selfcompile:
|
2022-07-27 21:04:29 +03:00
|
|
|
$(VEXE) -cg -o v cmd/v
|
2021-09-04 14:32:42 +03:00
|
|
|
|
|
|
|
selfcompile-static:
|
2022-07-27 21:04:29 +03:00
|
|
|
$(VEXE) -cg -cflags '--static' -o v-static cmd/v
|
2021-09-04 14:32:42 +03:00
|
|
|
|
|
|
|
### NB: Please keep this Makefile and make.bat simple.
|
|
|
|
install:
|
|
|
|
@echo 'Please use `sudo ./v symlink` instead.'
|
|
|
|
|
2022-05-01 13:38:30 +03:00
|
|
|
check:
|
2022-07-27 21:04:29 +03:00
|
|
|
$(VEXE) test-all
|