From c956a463c6bc314e05ba48b94927cddf6a16044a Mon Sep 17 00:00:00 2001 From: "mingang.he" Date: Mon, 18 Oct 2021 23:38:32 +0800 Subject: [PATCH] Update Makefile --- Makefile | 12 +++++++++++- local/Makefile | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 624493e..9c7ae98 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,16 @@ endif VERSION = $(shell git describe --tags --always) +# CROSS_COMPILE can be set on the command line +# make CROSS_COMPILE=arm-linux-gnueabi- +# Default value for CROSS_COMPILE is not to prefix executables + +CROSS_COMPILE ?= + +CC = $(CROSS_COMPILE)gcc +CXX = $(CROSS_COMPILE)g++ +AR = $(CROSS_COMPILE)ar + debug = 0 PREFIX = /usr/local @@ -58,7 +68,7 @@ libgraftcp.a: graftcp.o util.o string-set.o conf.o $(CC) $(CFLAGS) -c -o $@ $< $(GRAFTCP_LOCAL_BIN):: - $(MAKE) -C local VERSION=$(VERSION) + $(MAKE) -C local VERSION=$(VERSION) CC=$(CC) CXX=$(CXX) AR=$(AR) install:: graftcp $(GRAFTCP_LOCAL_BIN) $(INSTALL) $< $(DESTDIR)$(BINDIR)/$< diff --git a/local/Makefile b/local/Makefile index 8660532..76caa20 100644 --- a/local/Makefile +++ b/local/Makefile @@ -2,6 +2,14 @@ ifneq ($(shell echo $(VERSION) | head -c 1), v) VERSION=v0.4 endif +ifneq (,$(findstring arm,$(CC))) + GO_BUILD_PREFIX_FLAGS := + CGO_FLAGS := +else + GO_BUILD_PREFIX_FLAGS := GOOS=linux GOARCH=arm + CGO_FLAGS := CGO_ENABLED=1 CC=$(CC) CXX=$(CXX) AR=$(AR) +endif + PREFIX = /usr/local BINDIR = $(PREFIX)/bin @@ -12,10 +20,10 @@ TARGET = graftcp-local mgraftcp all:: $(TARGET) graftcp-local: $(wildcard *.go cmd/graftcp-local/*.go) - go build -ldflags "-s -w -X main.version=${VERSION}" ./cmd/graftcp-local + ${GO_BUILD_PREFIX_FLAGS} go build -ldflags "-s -w -X main.version=${VERSION}" ./cmd/graftcp-local mgraftcp: $(wildcard *.go cmd/mgraftcp/*.go) ../libgraftcp.a - go build -ldflags "-s -w -X main.version=${VERSION}" ./cmd/mgraftcp + ${GO_BUILD_PREFIX_FLAGS} ${CGO_FLAGS} go build -ldflags "-s -w -X main.version=${VERSION}" ./cmd/mgraftcp ../libgraftcp.a: $(MAKE) -C .. libgraftcp.a