Skip to content

Commit 835e732

Browse files
GNUmakefile: add "help" target (#4390)
Example output: $ make help clean Remove build directory fmt Reformat source fmt-check Warn if any source needs reformatting gen-device Generate microcontroller-specific sources llvm-source Get LLVM sources llvm-build Build LLVM lint Lint source tree spell Spellcheck source tree Might even work on windows, since git for windows comes with awk.
1 parent eab1a5d commit 835e732

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

BUILDING.md

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ build tools to be built. Go is of course necessary to build TinyGo itself.
2828
The rest of this guide assumes you're running Linux, but it should be equivalent
2929
on a different system like Mac.
3030

31+
## Using GNU Make
32+
33+
The static build of TinyGo is driven by GNUmakefile, which provides a help target for quick reference:
34+
35+
% make help
36+
clean Remove build directory
37+
fmt Reformat source
38+
fmt-check Warn if any source needs reformatting
39+
gen-device Generate microcontroller-specific sources
40+
llvm-source Get LLVM sources
41+
llvm-build Build LLVM
42+
tinygo Build the TinyGo compiler
43+
lint Lint source tree
44+
spell Spellcheck source tree
45+
3146
## Download the source
3247

3348
The first step is to download the TinyGo sources (use `--recursive` if you clone

GNUmakefile

+18-13
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@ ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","")
175175
CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA)
176176
endif
177177

178-
clean:
178+
clean: ## Remove build directory
179179
@rm -rf build
180180

181181
FMT_PATHS = ./*.go builder cgo/*.go compiler interp loader src transform
182-
fmt:
182+
fmt: ## Reformat source
183183
@gofmt -l -w $(FMT_PATHS)
184-
fmt-check:
184+
fmt-check: ## Warn if any source needs reformatting
185185
@unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1
186186

187187

188-
gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp
188+
gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp ## Generate microcontroller-specific sources
189189
ifneq ($(STM32), 0)
190190
gen-device: gen-device-stm32
191191
endif
@@ -237,18 +237,16 @@ gen-device-renesas: build/gen-device-svd
237237
./build/gen-device-svd -source=https://github.com/tinygo-org/renesas-svd lib/renesas-svd/ src/device/renesas/
238238
GO111MODULE=off $(GO) fmt ./src/device/renesas
239239

240-
# Get LLVM sources.
241240
$(LLVM_PROJECTDIR)/llvm:
242241
git clone -b tinygo_xtensa_release_18.1.2 --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR)
243-
llvm-source: $(LLVM_PROJECTDIR)/llvm
242+
llvm-source: $(LLVM_PROJECTDIR)/llvm ## Get LLVM sources
244243

245244
# Configure LLVM.
246245
TINYGO_SOURCE_DIR=$(shell pwd)
247246
$(LLVM_BUILDDIR)/build.ninja:
248247
mkdir -p $(LLVM_BUILDDIR) && cd $(LLVM_BUILDDIR) && cmake -G Ninja $(TINYGO_SOURCE_DIR)/$(LLVM_PROJECTDIR)/llvm "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;AVR;Mips;RISCV;WebAssembly" "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=Xtensa" -DCMAKE_BUILD_TYPE=Release -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF -DLLVM_ENABLE_OCAMLDOC=OFF -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF $(LLVM_OPTION)
249248

250-
# Build LLVM.
251-
$(LLVM_BUILDDIR): $(LLVM_BUILDDIR)/build.ninja
249+
$(LLVM_BUILDDIR): $(LLVM_BUILDDIR)/build.ninja ## Build LLVM
252250
cd $(LLVM_BUILDDIR) && ninja $(NINJA_BUILD_TARGETS)
253251

254252
ifneq ($(USE_SYSTEM_BINARYEN),1)
@@ -291,8 +289,7 @@ ifeq (, $(shell which node))
291289
endif
292290
@if [ $(NODEJS_VERSION) -lt $(MIN_NODEJS_VERSION) ]; then echo "Install NodeJS version 18+ to run tests."; exit 1; fi
293291

294-
# Build the Go compiler.
295-
tinygo:
292+
tinygo: ## Build the TinyGo compiler
296293
@if [ ! -f "$(LLVM_BUILDDIR)/bin/llvm-config" ]; then echo "Fetch and build LLVM first by running:"; echo " $(MAKE) llvm-source"; echo " $(MAKE) $(LLVM_BUILDDIR)"; exit 1; fi
297294
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GOENVFLAGS) $(GO) build -buildmode exe -o build/tinygo$(EXE) -tags "byollvm osusergo" -ldflags="-X github.com/tinygo-org/tinygo/goenv.GitSha1=`git rev-parse --short HEAD`" .
298295
test: wasi-libc check-nodejs-version
@@ -955,7 +952,7 @@ tools:
955952
go generate -C ./internal/tools -tags tools ./
956953

957954
.PHONY: lint
958-
lint:
955+
lint: ## Lint source tree
959956
go run github.com/mgechev/revive -version
960957
# TODO: lint more directories!
961958
# revive.toml isn't flexible enough to filter out just one kind of error from a checker, so do it with grep here.
@@ -964,6 +961,14 @@ lint:
964961
go run github.com/mgechev/revive -config revive.toml compiler/... src/{os,reflect}/*.go | grep -v "should have comment or be unexported" | grep '.' | awk '{print}; END {exit NR>0}'
965962

966963
.PHONY: spell
967-
spell:
968-
# Check for typos in comments. Skip git submodules etc.
964+
spell: ## Spellcheck source tree
969965
go run github.com/client9/misspell/cmd/misspell -i 'ackward,devided,extint,inbetween,programmmer,rela' $$( find . -depth 1 -type d | egrep -w -v 'lib|llvm|src/net' )
966+
967+
# https://www.client9.com/self-documenting-makefiles/
968+
.PHONY: help
969+
help:
970+
@awk -F ':|##' '/^[^\t].+?:.*?##/ {\
971+
gsub(/\$$\(LLVM_BUILDDIR\)/, "$(LLVM_BUILDDIR)"); \
972+
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \
973+
}' $(MAKEFILE_LIST)
974+
#.DEFAULT_GOAL=help

0 commit comments

Comments
 (0)