Skip to content

Commit

Permalink
Rewrite MakeFile.
Browse files Browse the repository at this point in the history
  • Loading branch information
AYMENJD committed Nov 9, 2024
1 parent daaed61 commit 8412716
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
59 changes: 43 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,56 @@
.PHONY: build clean install
.DEFAULT_GOAL := build

EXECUTABLE := $(shell pwd)/bin/tdlib-server
BIN := $(shell pwd)/bin/tdlib-server
SRC := ./cmd/tdlib-server/tdlib-server.go
INSTALL_DIR := /usr/local/bin
LINK := $(INSTALL_DIR)/tdlib-server
BIN_PREFIX ?= /usr/local/bin
SYMLINK := $(BIN_PREFIX)/tdlib-server

build:
go build -o $(EXECUTABLE) $(SRC)
@echo "\ntdlib-server installed at $(EXECUTABLE)"
TDLIB_DIR ?= /usr/local
TD_INC ?= $(TDLIB_DIR)/include
TD_LIB ?= $(TDLIB_DIR)/lib

build-wide:
CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS="-Wl,-rpath=/usr/local/lib -ltdjson" go build -o $(EXECUTABLE) $(SRC)
@echo "\ntdlib-server installed at $(EXECUTABLE)"
.PHONY: build
build: check_tdlib
CGO_LDFLAGS="-L$(TD_LIB) -Wl,-rpath=$(TD_LIB) -ltdjson" \
CGO_CFLAGS=-I$(TD_INC) \
go build -o $(BIN) $(SRC)
@echo "\ntdlib-server installed at $(BIN)"

.PHONY: clean
clean:
rm -rf ./bin

.PHONY: install
install:
ln -sf $(PWD)/$(EXECUTABLE) $(LINK)
@echo "\ntdlib-server installed at $(LINK)"
ln -sf $(BIN) $(SYMLINK)
@echo "\ntdlib-server installed at $(SYMLINK)"

.PHONY: uninstall
uninstall:
rm -f $(SYMLINK)
@echo "\ntdlib-server uninstalled from $(SYMLINK)"

.PHONY: check_tdlib
check_tdlib:
@if [ ! -d "$(TD_INC)" ]; then \
echo "Error: TDLib include directory not found at $(TD_INC)."; \
echo "Please ensure that TDLIB_DIR environment variable is set correctly."; \
echo "Alternatively, you can set the TD_INC environment variable manually for include directory."; \
exit 1; \
fi

@if [ ! -d "$(TD_LIB)" ]; then \
echo "Error: TDLib library directory not found at $(TD_LIB)."; \
echo "Please ensure that TDLIB_DIR environment variable is set correctly."; \
echo "Alternatively, you can set the TD_LIB environment variable manually for library directory."; \
exit 1; \
fi

.PHONY: help
help:
@echo "Available commands:"
@echo " make build - Build the tdlib-server binary"
@echo " make clean - Remove the built binary and clean up"
@echo " make install - Install tdlib-server system-wide"
@echo " make help - Display this help message"
@echo " make build - Build the tdlib-server binary"
@echo " make clean - Remove the built binary and clean up"
@echo " make install - Install tdlib-server system-wide"
@echo " make uninstall - Uninstall tdlib-server system-wide"
@echo " make help - Display this help message"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ Once TDLib and RabbitMQ are installed, you're ready to build **TDLib Server**:
- Build TDLib Server
- If **TDLib is not installed system-wide** (a.k.a ``/usr/local``):
```bash
CGO_CFLAGS=-I/path/to/include CGO_LDFLAGS="-Wl,-rpath=/path/to/lib -ltdjson" make build
TDLIB_DIR="/path/to/tdlib" make build
```
Ensure you adjust the paths to match your installation directories.
By default TDLib install files at ``td/tdlib``

- If **TDLib is installed system-wide** (recommended):
- If **TDLib is installed system-wide** (recommended), just do:
```bash
make build-wide
make build
```

- Optionally, you can install ``tdlib-server`` system-wide:
Expand Down

0 comments on commit 8412716

Please sign in to comment.