Skip to content

Commit

Permalink
Update installation
Browse files Browse the repository at this point in the history
  • Loading branch information
hmgle committed Aug 22, 2018
1 parent 5a84aee commit 00d81b3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
28 changes: 17 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

KERNEL = $(shell uname -s)
ifneq ($(KERNEL), Linux)
$(error only support Linux now.)
endif

debug = 0

PREFIX = /usr/local
Expand All @@ -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)
Expand All @@ -42,27 +47,27 @@ 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)

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)

Expand All @@ -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 $@
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -87,7 +87,7 @@ Options:
假设你正在运行默认地址 "localhost:1080" 的 SOCKS5 代理,首先启动 `graftcp-local`

```sh
graftcp-local
graftcp-local/graftcp-local
```

通过 `graftcp` 安装来自 golang.org 的 Go 包:
Expand Down
29 changes: 29 additions & 0 deletions graftcp-local/Makefile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 00d81b3

Please sign in to comment.