Skip to content

Instantly share code, notes, and snippets.

@yowcow
Created September 6, 2018 09:51
Show Gist options
  • Save yowcow/9b8ebc7ac7051a5a1271a571373a0480 to your computer and use it in GitHub Desktop.
Save yowcow/9b8ebc7ac7051a5a1271a571373a0480 to your computer and use it in GitHub Desktop.
Statically/dynamically cross-compile with CGO enabled/disabled
STATIC := static-app
DYNAMIC := dynamic-app
all: $(STATIC) $(DYNAMIC)
$(MAKE) -f build.mk check FILE=$(STATIC)
$(MAKE) -f build.mk check FILE=$(DYNAMIC)
$(STATIC):
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags '-extldflags "-static"' -o $@
$(DYNAMIC):
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o $@
check:
file $(FILE) || true
ldd $(FILE) || true
clean:
rm -f $(STATIC) $(DYNAMIC)
.PHONY: all check clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment