-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·132 lines (124 loc) · 4.26 KB
/
Makefile
File metadata and controls
executable file
·132 lines (124 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Variables
INSTALL_DIR = /usr/local/bin
SYSTEMD_DIR = /etc/systemd/system
CARGO = $(HOME)/.cargo/bin/cargo
JQ = jq
PYTHON = python3
# Check if the required tools are available
check_deps:
@if ! command -v $(CARGO) &>/dev/null; then \
echo "cargo not found. Installing Rust..."; \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; \
echo "Rust installed."; \
fi
@if ! command -v $(JQ) &>/dev/null; then \
echo "jq not found. Installing jq..."; \
sudo apt-get install -y jq; \
echo "jq installed."; \
fi
@if ! command -v $(PYTHON) &>/dev/null; then \
echo "python3 not found. Installing Python..."; \
sudo apt-get install -y python3 python3-pip; \
echo "Python installed."; \
fi
@if ! command -v llvm-config &>/dev/null; then \
echo "llvm-config not found. Installing LLVM development tools..."; \
sudo apt-get install -y llvm-dev libclang-dev clang; \
echo "LLVM tools installed."; \
fi
# Check Python dependencies
check_python_deps:
@for dir in libs/*/; do \
if [ -d "$$dir" ] && [ -f "$$dir/requirements.txt" ]; then \
echo "Installing Python dependencies for $$dir..."; \
pip3 install -r $$dir/requirements.txt; \
else \
echo "No requirements.txt found in $$dir. Skipping Python dependencies check."; \
fi; \
done
# Build Rust project (in each lib directory)
build_rust:
@for dir in libs/*/; do \
if [ -d "$$dir" ] && [ -f "$$dir/Cargo.toml" ]; then \
echo "Building Rust project in $$dir..."; \
cd $$dir && cargo build --release && cd -; \
fi; \
done
# Install Rust binaries
install_rust:
@for dir in libs/*/; do \
if [ -d "$$dir" ] && [ -f "$$dir/Cargo.toml" ]; then \
echo "Installing Rust binaries from $$dir..."; \
BINARY_NAME=$$(cargo metadata --no-deps --format-version 1 --manifest-path $$dir/Cargo.toml | $(JQ) -r '.packages[0].targets[0].name'); \
BINARY_PATH="$$dir/target/release/$$BINARY_NAME"; \
if [ -f "$$BINARY_PATH" ]; then \
sudo install -Dm755 "$$BINARY_PATH" $(INSTALL_DIR)/$$BINARY_NAME; \
make add_to_startup PROGRAM_NAME=$$BINARY_NAME; \
else \
echo "Warning: Compiled Rust binary not found in $$dir. Skipping..."; \
fi; \
fi; \
done
# Install Java binaries (for Maven or Gradle projects)
install_java:
@for dir in libs/*/; do \
if [ -d "$$dir" ] && [ -f "$$dir/pom.xml" ]; then \
JAR_FILE="$$dir/target/$$basename-1.0.jar"; \
if [ -f "$$JAR_FILE" ]; then \
sudo install -Dm644 "$$JAR_FILE" $(INSTALL_DIR)/$$basename-1.0.jar; \
make add_to_startup PROGRAM_NAME=$$basename-1.0.jar; \
fi; \
elif [ -d "$$dir" ] && [ -f "$$dir/build.gradle" ]; then \
JAR_FILE="$$dir/build/libs/$$basename-1.0.jar"; \
if [ -f "$$JAR_FILE" ]; then \
sudo install -Dm644 "$$JAR_FILE" $(INSTALL_DIR)/$$basename-1.0.jar; \
make add_to_startup PROGRAM_NAME=$$basename-1.0.jar; \
fi; \
fi; \
done
# Add program to system startup using systemd
add_to_startup:
@if [ "$(PROGRAM_NAME)" ]; then \
printf "Do you want to add '$(PROGRAM_NAME)' to startup? (y/n): "; \
read add_startup; \
if [ "$$add_startup" = "y" ] || [ "$$add_startup" = "Y" ]; then \
SERVICE_FILE=$(SYSTEMD_DIR)/$(PROGRAM_NAME).service; \
echo "Creating systemd service for $(PROGRAM_NAME)..."; \
sudo bash -c "cat > $$SERVICE_FILE" <<EOF; \
[Unit] \
Description=$(PROGRAM_NAME) Service \
After=network.target \
\
[Service] \
ExecStart=$(INSTALL_DIR)/$(PROGRAM_NAME) \
Restart=always \
User=nobody \
Group=nogroup \
WorkingDirectory=$(INSTALL_DIR) \
\
[Install] \
WantedBy=multi-user.target \
EOF \
sudo systemctl daemon-reload; \
sudo systemctl enable $(PROGRAM_NAME).service; \
echo "'$(PROGRAM_NAME)' has been added to startup!"; \
else \
echo "Skipping startup configuration for $(PROGRAM_NAME)."; \
fi; \
fi
# Uninstall all binaries and remove from startup
uninstall:
@sudo rm -rf $(INSTALL_DIR)/*
@echo "All binaries removed from $(INSTALL_DIR)."
@echo "Removing systemd services..."
@for service in $(SYSTEMD_DIR)/*.service; do \
SERVICE_NAME=$$(basename $$service .service); \
sudo systemctl disable $$SERVICE_NAME.service; \
sudo rm $$service; \
echo "Removed $$SERVICE_NAME from startup."; \
done
@echo "Uninstallation complete!"
# Main targets
install: check_deps check_python_deps build_rust install_rust install_java
@echo "Installation complete!"
@make add_to_startup