Skip to content

Commit

Permalink
Update Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
hmgle committed Oct 18, 2021
1 parent f649b90 commit c956a46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)/$<
Expand Down
12 changes: 10 additions & 2 deletions local/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit c956a46

Please sign in to comment.