diff --git a/Makefile b/Makefile index 0ff34c6..8b83d43 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +KERNEL = $(shell uname -s) +ifneq ($(KERNEL), Linux) +$(error only support Linux now.) +endif + debug = 0 PREFIX = /usr/local @@ -30,7 +35,7 @@ endif SRC := $(wildcard *.c) -GRAFTCP_LOCAL_BIN = $(GOPATH)/bin/graftcp-local +GRAFTCP_LOCAL_BIN = graftcp-local/graftcp-local TARGET = graftcp $(GRAFTCP_LOCAL_BIN) all:: $(TARGET) @@ -42,15 +47,15 @@ graftcp: main.o util.o string-set.o $(CC) $(CFLAGS) -c -o $@ $< $(GRAFTCP_LOCAL_BIN):: - go get -v github.com/hmgle/graftcp/graftcp-local + $(MAKE) -C graftcp-local install:: graftcp $(GRAFTCP_LOCAL_BIN) - $(INSTALL) $< $(BINDIR); \ - graftcp-local -service install && graftcp-local -service start + $(INSTALL) $< $(BINDIR) + $(MAKE) -C graftcp-local $@ uninstall:: $(GRAFTCP_LOCAL_BIN) - -rm -f $(BINDIR)/graftcp; \ - graftcp-local -service uninstall + -rm -f $(BINDIR)/graftcp + $(MAKE) -C graftcp-local $@ install_graftcp:: graftcp $(INSTALL) $< $(BINDIR) @@ -58,11 +63,11 @@ install_graftcp:: graftcp uninstall_graftcp:: -rm -f $(BINDIR)/graftcp -install_graftcp_local:: $(GRAFTCP_LOCAL_BIN) - graftcp-local -service install && graftcp-local -service restart +install_graftcp_local: + $(MAKE) -C graftcp-local install -uninstall_graftcp_local:: $(GRAFTCP_LOCAL_BIN) - graftcp-local -service stop && graftcp-local -service uninstall +uninstall_graftcp_local: + $(MAKE) -C graftcp-local uninstall sinclude $(SRC:.c=.d) @@ -73,4 +78,5 @@ sinclude $(SRC:.c=.d) rm -f $@.$$$$ clean:: - -rm -f *.o $(TARGET) *.d + -rm -f *.o graftcp *.d + $(MAKE) -C graftcp-local $@ diff --git a/README.md b/README.md index 5d4673f..1c1c3d1 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,13 @@ git clone https://github.com/hmgle/graftcp.git cd graftcp make ``` -After make finishes, you'll be able to use `graftcp-local` and `./graftcp`. +After make finishes, you'll be able to use `graftcp-local/graftcp-local` and `./graftcp`. Optionally, you can also install them to system: ```sh # sudo's PATH may be overridden by the security policy, # so set the PATH for Go -sudo env "PATH=$PATH" make install +sudo make install ``` Then `graftcp-local` will run automatically as the operating system starts. @@ -42,8 +42,8 @@ Then `graftcp-local` will run automatically as the operating system starts. `graftcp-local`: ```console -$ graftcp-local -h -Usage of graftcp-local: +$ graftcp-local/graftcp-local -h +Usage of graftcp-local/graftcp-local: -config string Path to the configuration file -listen string @@ -93,8 +93,9 @@ Options: Assume you are running the SOCKS5 proxy with the default IP address: "localhost:1080". Start the `graftcp-local` first: ```sh -graftcp-local +graftcp-local/graftcp-local ``` + Install the Go package from golang.org (now is blocked by the GFW) via `graftcp`: ```sh diff --git a/README.zh-CN.md b/README.zh-CN.md index 2b4c482..d82de9e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -21,7 +21,7 @@ cd graftcp make ``` -make 执行完后,即可运行 `graftcp-local` 和 `./graftcp`。可以把它们都安装进系统: +make 执行完后,即可运行 `graftcp-local/graftcp-local` 和 `./graftcp`。可以把它们都安装进系统: ```sh # sudo's PATH may be overridden by the security policy, @@ -36,8 +36,8 @@ sudo env "PATH=$PATH" make install `graftcp-local`: ```console -$ graftcp-local -h -Usage of graftcp-local: +$ graftcp-local/graftcp-local -h +Usage of graftcp-local/graftcp-local: -config string Path to the configuration file -listen string @@ -87,7 +87,7 @@ Options: 假设你正在运行默认地址 "localhost:1080" 的 SOCKS5 代理,首先启动 `graftcp-local`: ```sh -graftcp-local +graftcp-local/graftcp-local ``` 通过 `graftcp` 安装来自 golang.org 的 Go 包: diff --git a/graftcp-local/Makefile b/graftcp-local/Makefile new file mode 100644 index 0000000..1c82571 --- /dev/null +++ b/graftcp-local/Makefile @@ -0,0 +1,29 @@ +GO_CMD := $(shell command -v go 2> /dev/null) +ifndef GO_CMD +$(error "go is not available, please install go") +endif + +export GOPATH := $(CURDIR)/.gopath +export PATH := $(PATH):$(CURDIR)/.gopath/bin + +GO_IMPORT_PATH := github.com/hmgle/graftcp/graftcp-local + +all:: graftcp-local + +graftcp-local: .gopath/.created $(wildcard *.go) + go build -v $(GO_IMPORT_PATH) + +.gopath/.created: + rm -rf .gopath + mkdir -p $(dir .gopath/src/$(GO_IMPORT_PATH)) + ln -s $(CURDIR) .gopath/src/$(GO_IMPORT_PATH) + touch $@ + +install:: graftcp-local + ./graftcp-local -service install && ./graftcp-local -service restart + +uninstall:: graftcp-local + ./graftcp-local -service stop && ./graftcp-local -service uninstall + +clean:: + -rm -rf graftcp-local .gopath