From 28ffb9638d7a06b4bfcb87ce6af28c66c2210de3 Mon Sep 17 00:00:00 2001 From: Alex Cornejo Date: Tue, 13 Oct 2015 09:40:40 -0700 Subject: [PATCH] add android build --- src/Dockerfile.android | 44 ++++++++++++++++++++++++++++++++++++++++++ src/Makefile | 33 +++++++++++++++++++++++++------ src/curses/curses.go | 8 +++++++- 3 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 src/Dockerfile.android diff --git a/src/Dockerfile.android b/src/Dockerfile.android new file mode 100644 index 0000000..540858f --- /dev/null +++ b/src/Dockerfile.android @@ -0,0 +1,44 @@ +FROM ubuntu:14.04 +MAINTAINER Junegunn Choi + +# apt-get +RUN apt-get update && apt-get -y upgrade && \ + apt-get install -y --force-yes git curl build-essential + +# Install Go 1.4 +RUN cd / && curl \ + https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \ + tar -xz && mv go go1.4 && \ + sed -i 's@#define PTHREAD_KEYS_MAX 128@@' /go1.4/src/runtime/cgo/gcc_android_arm.c + +ENV GOPATH /go +ENV GOROOT /go1.4 +ENV PATH /go1.4/bin:$PATH + +RUN cd / && \ + curl -O http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin && \ + chmod 755 /android-ndk* && /android-ndk-r10e-linux-x86_64.bin && \ + mv android-ndk-r10e /android-ndk + +RUN cd /android-ndk && bash ./build/tools/make-standalone-toolchain.sh --platform=android-21 --install-dir=/ndk --arch=arm + +ENV NDK_CC /ndk/bin/arm-linux-androideabi-gcc + +RUN cd $GOROOT/src && \ + CC_FOR_TARGET=$NDK_CC GOOS=android GOARCH=arm GOARM=7 ./make.bash + +RUN cd / && curl \ + http://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz | \ + tar -xz && cd /ncurses-5.9 && \ + ./configure CC=$NDK_CC CFLAGS="-fPIE -march=armv7-a -mfpu=neon -mhard-float -Wl,--no-warn-mismatch" LDFLAGS="-march=armv7-a -Wl,--no-warn-mismatch" --host=arm-linux --enable-overwrite --enable-const --without-cxx-binding --without-shared --without-debug --enable-widec --enable-ext-colors --enable-ext-mouse --enable-pc-files --with-pkg-config-libdir=$PKG_CONFIG_LIBDIR --without-manpages --without-ada --disable-shared --without-tests --prefix=/ndk/sysroot/usr --with-default-terminfo-dirs=/usr/share/terminfo --with-terminfo-dirs=/usr/share/terminfo ac_cv_header_locale_h=n ac_cv_func_getpwent=no ac_cv_func_getpwnam=no ac_cv_func_getpwuid=no && \ + sed -i 's@#define HAVE_LOCALE_H 1@/* #undef HAVE_LOCALE_H */@' include/ncurses_cfg.h && \ + make && \ + sed -i '0,/echo.*/{s/echo.*/exit 0/}' misc/run_tic.sh && \ + make install && \ + mv /ndk/sysroot/usr/lib/libncursesw.a /ndk/sysroot/usr/lib/libncurses.a + +# Volume +VOLUME /go + +# Default CMD +CMD cd /go/src/github.com/junegunn/fzf/src && /bin/bash diff --git a/src/Makefile b/src/Makefile index ff40897..6b564fc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,12 +2,14 @@ ifndef GOPATH $(error GOPATH is undefined) endif +ifndef GOOS UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) GOOS := darwin else ifeq ($(UNAME_S),Linux) GOOS := linux endif +endif ifneq ($(shell uname -m),x86_64) $(error "Build on $(UNAME_M) is not supported, yet.") @@ -16,11 +18,13 @@ endif SOURCES := $(wildcard *.go */*.go) BINDIR := ../bin -BINARY32 := fzf-$(GOOS)_386 -BINARY64 := fzf-$(GOOS)_amd64 -VERSION = $(shell fzf/$(BINARY64) --version) -RELEASE32 = fzf-$(VERSION)-$(GOOS)_386 -RELEASE64 = fzf-$(VERSION)-$(GOOS)_amd64 +BINARY32 := fzf-$(GOOS)_386 +BINARY64 := fzf-$(GOOS)_amd64 +BINARYARM7 := fzf-$(GOOS)_arm7 +VERSION := $(shell awk -F= '/version =/ {print $$2}' constants.go | tr -d "\" ") +RELEASE32 = fzf-$(VERSION)-$(GOOS)_386 +RELEASE64 = fzf-$(VERSION)-$(GOOS)_amd64 +RELEASEARM7 = fzf-$(VERSION)-$(GOOS)_arm7 all: release @@ -31,6 +35,11 @@ release: build build: test fzf/$(BINARY32) fzf/$(BINARY64) +android-build: + cd fzf && GOARCH=arm GOARM=7 CGO_ENABLED=1 go build -a -ldflags="-extldflags=-pie" -o $(BINARYARM7) + cd fzf && cp $(BINARYARM7) $(RELEASEARM7) && tar -czf $(RELEASEARM7).tgz $(RELEASEARM7) && \ + rm -f $(RELEASEARM7) + test: go get go test -v ./... @@ -65,6 +74,9 @@ docker-ubuntu: docker-centos: docker build -t junegunn/centos-sandbox - < Dockerfile.centos +docker-android: + docker build -t junegunn/android-sandbox - < Dockerfile.android + arch: docker-arch docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \ sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash' @@ -81,5 +93,14 @@ linux: docker-centos docker run -i -t -v $(GOPATH):/go junegunn/centos-sandbox \ /bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; make TAGS=static' +ubuntu-android: docker-android + docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \ + sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash' + +android: docker-android + docker run -i -t -v $(GOPATH):/go junegunn/android-sandbox \ + /bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; GOOS=android make android-build' + .PHONY: all build release test install uninstall clean docker \ - linux arch ubuntu centos docker-arch docker-ubuntu docker-centos + linux arch ubuntu centos docker-arch docker-ubuntu docker-centos \ + android-build docker-android ubuntu-android android diff --git a/src/curses/curses.go b/src/curses/curses.go index 8311719..a8d33f6 100644 --- a/src/curses/curses.go +++ b/src/curses/curses.go @@ -5,6 +5,12 @@ package curses #include #cgo !static LDFLAGS: -lncurses #cgo static LDFLAGS: -l:libncursesw.a -l:libtinfo.a -l:libgpm.a -ldl +#cgo android static LDFLAGS: -l:libncurses.a -fPIE -march=armv7-a -mfpu=neon -mhard-float -Wl,--no-warn-mismatch + +SCREEN *c_newterm () { + return newterm(NULL, stderr, stdin); +} + */ import "C" @@ -259,7 +265,7 @@ func Init(theme *ColorTheme, black bool, mouse bool) { } C.setlocale(C.LC_ALL, C.CString("")) - _screen = C.newterm(nil, C.stderr, C.stdin) + _screen = C.c_newterm() if _screen == nil { fmt.Println("Invalid $TERM: " + os.Getenv("TERM")) os.Exit(2)