@@ -43,16 +43,38 @@ PACKAGE := github.com/lima-vm/lima/v2
4343VERSION := $(shell git describe --match 'v[0-9]* ' --dirty='.m' --always --tags)
4444VERSION_TRIMMED := $(VERSION:v%=% )
4545
46+ # `DEBUG` flag to build binaries with debug information for use by `dlv exec`.
47+ # This implies KEEP_DWARF=1 and KEEP_SYMBOLS=1.
48+ DEBUG ?=
49+ GO_BUILD_GCFLAGS ?=
50+ KEEP_DWARF ?=
4651KEEP_SYMBOLS ?=
52+ ifeq ($(DEBUG ) ,1)
53+ # Disable optimizations and inlining to make debugging easier.
54+ GO_BUILD_GCFLAGS = -gcflags="all=-N -l"
55+ # Keep the symbol table
56+ KEEP_DWARF = 1
57+ # Enable DWARF generation
58+ KEEP_SYMBOLS = 1
59+ endif
60+
61+ GO_BUILD_LDFLAGS_W := true
62+ ifeq ($(KEEP_DWARF ) ,1)
63+ GO_BUILD_LDFLAGS_W = false
64+ endif
65+
4766GO_BUILD_LDFLAGS_S := true
4867ifeq ($(KEEP_SYMBOLS ) ,1)
4968 GO_BUILD_LDFLAGS_S = false
5069endif
51- GO_BUILD_LDFLAGS := -ldflags="-s=$(GO_BUILD_LDFLAGS_S ) -w -X $(PACKAGE ) /pkg/version.Version=$(VERSION ) "
70+ # `-s`: Strip the symbol table according to the KEEP_SYMBOLS config
71+ # `-w`: Disable DWARF generation according to the KEEP_DWARF config
72+ # `-X`: Embed version information.
73+ GO_BUILD_LDFLAGS := -ldflags="-s=$(GO_BUILD_LDFLAGS_S ) -w=$(GO_BUILD_LDFLAGS_W ) -X $(PACKAGE ) /pkg/version.Version=$(VERSION ) "
5274# `go -version -m` returns -tags with comma-separated list, because space-separated list is deprecated in go1.13.
5375# converting to comma-separated list is useful for comparing with the output of `go version -m`.
5476GO_BUILD_FLAG_TAGS := $(addprefix -tags=,$(shell echo "$(GO_BUILDTAGS ) "|tr " " "\n"|paste -sd "," -) )
55- GO_BUILD := $(GO ) build $(GO_BUILD_LDFLAGS ) $(GO_BUILD_FLAG_TAGS )
77+ GO_BUILD := $(strip $( GO ) build $(GO_BUILD_GCFLAGS ) $( GO_BUILD_LDFLAGS ) $(GO_BUILD_FLAG_TAGS ) )
5678
5779# ###############################################################################
5880# Features
@@ -78,7 +100,9 @@ help-variables:
78100 @echo ' # Variables that can be overridden.'
79101 @echo
80102 @echo ' - PREFIX (directory) : Installation prefix (default: /usr/local)'
103+ @echo ' - KEEP_DWARF (1 or 0) : Whether to keep DWARF information (default: 0)'
81104 @echo ' - KEEP_SYMBOLS (1 or 0) : Whether to keep symbols (default: 0)'
105+ @echo ' - DEBUG (1 or 0) : Whether to build with debug information (default: 0)'
82106
83107.PHONY : help-targets
84108help-targets :
@@ -88,6 +112,8 @@ help-targets:
88112 @echo ' - limactl : Build limactl, and lima'
89113 @echo ' - lima : Copy lima, and lima.bat'
90114 @echo ' - helpers : Copy nerdctl.lima, apptainer.lima, docker.lima, podman.lima, and kubectl.lima'
115+ # TODO: move CLI plugins to _output/libexec/lima/
116+ @echo ' - limactl-plugins : Build limactl-* CLI plugins'
91117 @echo
92118 @echo ' Targets for files in _output/share/lima/:'
93119 @echo ' - guestagents : Build guestagents'
@@ -150,7 +176,7 @@ CONFIG_GUESTAGENT_COMPRESS=y
150176
151177# ###############################################################################
152178.PHONY : binaries
153- binaries : limactl helpers guestagents \
179+ binaries : limactl helpers limactl-plugins guestagents \
154180 templates template_experimentals \
155181 documentation create-links-in-doc-dir
156182
@@ -177,7 +203,7 @@ dependencies_for_cmd = go.mod $(call find_files_excluding_dir_and_test, ./cmd/$(
177203# $(1): target binary
178204extract_build_vars = $(shell \
179205 ($(GO ) version -m $(1 ) 2>&- || echo $(1 ) :) | \
180- awk 'FNR==1{print "GOVERSION="$$2}$$2~/^(CGO|GO|-ldflags|-tags).*=.+$$/{sub("^.*"$$2,$$2); print $$0}' \
206+ awk 'FNR==1{print "GOVERSION="$$2}$$2~/^(CGO|GO|-gcflags|- ldflags|-tags).*=.+$$/{sub("^.*"$$2,$$2); print $$0}' \
181207)
182208
183209# a list of keys from the GO build variables to be used for calling `go env`.
@@ -192,7 +218,7 @@ go_build_vars = $(shell \
192218 $(ENVS_$(1 ) ) $(GO ) env $(2 ) | \
193219 awk '/ /{print "\""$$0"\""; next}{print}' | \
194220 for k in $(2 ) ; do read -r v && echo "$$k=$${v}"; done \
195- ) $(GO_BUILD_LDFLAGS ) $(GO_BUILD_FLAG_TAGS )
221+ ) $(GO_BUILD_GCFLAGS ) $( GO_BUILD_LDFLAGS ) $(GO_BUILD_FLAG_TAGS )
196222
197223# returns the difference between $(1) and $(2).
198224diff = $(filter-out $(2 ) ,$(1 ) )$(filter-out $(1 ) ,$(2 ) )
@@ -256,6 +282,11 @@ ifeq ($(GOOS),darwin)
256282 codesign -f -v --entitlements vz.entitlements -s - $@
257283endif
258284
285+ limactl-plugins : _output/bin/limactl-mcp$(exe )
286+
287+ _output/bin/limactl-mcp$(exe ) : $(call dependencies_for_cmd,limactl-mcp) $$(call force_build,$$@ )
288+ $(ENVS_$@ ) $(GO_BUILD ) -o $@ ./cmd/limactl-mcp
289+
259290DRIVER_INSTALL_DIR := _output/libexec/lima
260291
261292.PHONY : additional-drivers
@@ -356,16 +387,20 @@ MKDIR_TARGETS += _output/share/lima
356387# ###############################################################################
357388# _output/share/lima/templates
358389TEMPLATES = $(addprefix _output/share/lima/templates/,$(filter-out experimental,$(notdir $(wildcard templates/* ) ) ) )
390+ TEMPLATE_DEFAULTS = ${addprefix _output/share/lima/templates/_default/,$(notdir $(wildcard templates/_default/* ) ) }
391+ TEMPLATE_IMAGES = $(addprefix _output/share/lima/templates/_images/,$(notdir $(wildcard templates/_images/* ) ) )
359392TEMPLATE_EXPERIMENTALS = $(addprefix _output/share/lima/templates/experimental/,$(notdir $(wildcard templates/experimental/* ) ) )
360393
361394.PHONY : default_template templates template_experimentals
362395default_template : _output/share/lima/templates/default.yaml
363- templates : $(TEMPLATES )
396+ templates : $(TEMPLATES ) $( TEMPLATE_DEFAULTS ) $( TEMPLATE_IMAGES )
364397template_experimentals : $(TEMPLATE_EXPERIMENTALS )
365398
366399$(TEMPLATES ) : | _output/share/lima/templates
400+ $(TEMPLATE_DEFAULTS ) : | _output/share/lima/templates/_default
401+ $(TEMPLATE_IMAGES ) : | _output/share/lima/templates/_images
367402$(TEMPLATE_EXPERIMENTALS ) : | _output/share/lima/templates/experimental
368- MKDIR_TARGETS += _output/share/lima/templates _output/share/lima/templates/experimental
403+ MKDIR_TARGETS += _output/share/lima/templates _output/share/lima/templates/_default _output/share/lima/templates/_images _output/share/lima/templates/ experimental
369404
370405_output/share/lima/templates/% : templates/%
371406 cp -aL $< $@
@@ -488,14 +523,19 @@ uninstall:
488523 " $( DEST) /bin/lima" \
489524 " $( DEST) /bin/lima$( bat) " \
490525 " $( DEST) /bin/limactl$( exe) " \
526+ " $( DEST) /bin/limactl-mcp$( exe) " \
491527 " $( DEST) /bin/nerdctl.lima" \
492528 " $( DEST) /bin/apptainer.lima" \
493529 " $( DEST) /bin/docker.lima" \
494530 " $( DEST) /bin/podman.lima" \
495531 " $( DEST) /bin/kubectl.lima" \
496532 " $( DEST) /share/man/man1/lima.1" \
497533 " $( DEST) /share/man/man1/limactl" * " .1" \
498- " $( DEST) /share/lima" " $( DEST) /share/doc/lima"
534+ " $( DEST) /share/lima" \
535+ " $( DEST) /share/doc/lima" \
536+ " $( DEST) /libexec/lima/lima-driver-qemu$( exe) " \
537+ " $( DEST) /libexec/lima/lima-driver-vz$( exe) " \
538+ " $( DEST) /libexec/lima/lima-driver-wsl2$( exe) "
499539 if [ " $$ (readlink " $( DEST) /bin/nerdctl" )" = " nerdctl.lima" ]; then rm " $( DEST) /bin/nerdctl" ; fi
500540 if [ " $$ (readlink " $( DEST) /bin/apptainer" )" = " apptainer.lima" ]; then rm " $( DEST) /bin/apptainer" ; fi
501541
0 commit comments