-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
222 lines (204 loc) · 8.71 KB
/
Makefile
File metadata and controls
222 lines (204 loc) · 8.71 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# OpenJTalk Multi-platform Makefile
# This Makefile builds OpenJTalk for Windows, macOS, and Linux
# Based on the GitHub Actions build.yml configuration
# Detect the operating system
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
# Use Unix-style commands even on Windows in GitHub Actions
MKDIR_P = mkdir -p
RM_RF = rm -rf
RM_F = rm -f
CP = cp
TEST_DIR = test -d
else
DETECTED_OS := $(shell uname -s)
MKDIR_P = mkdir -p
RM_RF = rm -rf
RM_F = rm -f
CP = cp
TEST_DIR = test -d
endif
# Directory paths
PROJECT_ROOT := $(shell pwd)
BIN_DIR := $(PROJECT_ROOT)/bin
HTSENGINE_DIR := $(PROJECT_ROOT)/lib/hts_engine_API-1.10
OPENJTALK_DIR := $(PROJECT_ROOT)/lib/open_jtalk-1.11
# Default target
.PHONY: all clean build-hts build-openjtalk test install prepare-artifacts check-deps
all: build
# Main build target - detects platform and builds accordingly
build:
ifeq ($(DETECTED_OS),Windows)
@echo Building for Windows...
$(MAKE) build-windows
else ifeq ($(DETECTED_OS),Darwin)
@echo Building for macOS...
$(MAKE) build-macos
else ifeq ($(DETECTED_OS),Linux)
@echo Building for Linux...
$(MAKE) build-linux
else
@echo Unsupported operating system: $(DETECTED_OS)
@exit 1
endif
# Windows build process
CHARSET ?= SHIFT_JIS
build-windows: prepare-bin-dir
@echo Setting up Windows build environment...
@echo Building HTS Engine API for Windows...
cd "$(HTSENGINE_DIR)" && cmd //c "chcp 932 >nul 2>&1 & set CFLAGS=/source-charset:shift_jis /execution-charset:shift_jis & nmake /f Makefile.mak"
cd "$(HTSENGINE_DIR)" && cmd //c "chcp 932 >nul 2>&1 & nmake /f Makefile.mak install"
ifeq ($(CHARSET),UTF-8)
@echo Building Open JTalk for Windows (UTF-8)...
cd "$(OPENJTALK_DIR)" && cmd //c "chcp 65001 >nul 2>&1 & set CFLAGS=/source-charset:utf-8 /execution-charset:utf-8 & nmake /f Makefile.mak CHARSET=UTF_8"
else
@echo Building Open JTalk for Windows (Shift_JIS)...
cd "$(OPENJTALK_DIR)" && cmd //c "chcp 932 >nul 2>&1 & set CFLAGS=/source-charset:shift_jis /execution-charset:shift_jis & nmake /f Makefile.mak"
endif
@echo Copying Windows executable to bin directory...
$(CP) "$(OPENJTALK_DIR)/bin/open_jtalk.exe" "$(BIN_DIR)/"
@echo Windows build completed successfully!
# Linux build process
build-linux: prepare-bin-dir
@echo Building HTS Engine API for Linux...
cd "$(HTSENGINE_DIR)" && autoreconf -f -i
cd "$(HTSENGINE_DIR)" && chmod +x ./configure
cd "$(HTSENGINE_DIR)" && ./configure
cd "$(HTSENGINE_DIR)" && make
@echo Building Open JTalk for Linux...
cd "$(OPENJTALK_DIR)" && autoreconf -f -i
cd "$(OPENJTALK_DIR)" && chmod +x ./configure
cd "$(OPENJTALK_DIR)" && ./configure --with-charset=UTF-8 --with-hts-engine-header-path="$(HTSENGINE_DIR)/include" --with-hts-engine-library-path="$(HTSENGINE_DIR)/lib"
cd "$(OPENJTALK_DIR)" && make
@echo Copying Linux executable to bin directory...
$(CP) "$(OPENJTALK_DIR)/bin/open_jtalk" "$(BIN_DIR)/"
@echo Linux build completed successfully!
# macOS build process
build-macos: prepare-bin-dir
@echo Building HTS Engine API for macOS...
cd "$(HTSENGINE_DIR)" && autoreconf -f -i
cd "$(HTSENGINE_DIR)" && chmod +x ./configure
cd "$(HTSENGINE_DIR)" && ./configure
cd "$(HTSENGINE_DIR)" && make
@echo Building Open JTalk for macOS...
cd "$(OPENJTALK_DIR)" && autoreconf -f -i
cd "$(OPENJTALK_DIR)" && chmod +x ./configure
cd "$(OPENJTALK_DIR)" && ./configure --with-charset=UTF-8 --with-hts-engine-header-path="$(HTSENGINE_DIR)/include" --with-hts-engine-library-path="$(HTSENGINE_DIR)/lib"
cd "$(OPENJTALK_DIR)" && make
@echo Copying macOS executable to bin directory...
$(CP) "$(OPENJTALK_DIR)/bin/open_jtalk" "$(BIN_DIR)/"
@echo macOS build completed successfully!
# Prepare bin directory
prepare-bin-dir:
@echo Preparing bin directory...
@$(MKDIR_P) "$(BIN_DIR)"
# Check dependencies for all platforms
check-deps:
ifeq ($(DETECTED_OS),Linux)
$(MAKE) check-linux-deps
else ifeq ($(DETECTED_OS),Darwin)
$(MAKE) check-macos-deps
else ifeq ($(DETECTED_OS),Windows)
@echo Windows dependency check not implemented
else
@echo Unsupported operating system for dependency check
endif
# Check Linux dependencies
check-linux-deps:
@echo Checking Linux dependencies...
@command -v autoconf >/dev/null 2>&1 || (echo "Error: autoconf not found. Please install: sudo apt-get install autoconf" && exit 1)
@command -v automake >/dev/null 2>&1 || (echo "Error: automake not found. Please install: sudo apt-get install automake" && exit 1)
@command -v libtoolize >/dev/null 2>&1 || command -v libtool >/dev/null 2>&1 || (echo "Error: libtool not found. Please install: sudo apt-get install libtool" && exit 1)
@command -v gcc >/dev/null 2>&1 || (echo "Error: gcc not found. Please install: sudo apt-get install build-essential" && exit 1)
# Check macOS dependencies
check-macos-deps:
@echo Checking macOS dependencies...
@command -v autoconf >/dev/null 2>&1 || (echo "Error: autoconf not found. Please install: brew install autoconf" && exit 1)
@command -v automake >/dev/null 2>&1 || (echo "Error: automake not found. Please install: brew install automake" && exit 1)
@command -v libtool >/dev/null 2>&1 || command -v glibtool >/dev/null 2>&1 || (echo "Error: libtool not found. Please install: brew install libtool" && exit 1)
@command -v gcc >/dev/null 2>&1 || (echo "Error: gcc not found. Please install Xcode command line tools" && exit 1)
# Test the built executable
test:
@echo Testing built executable...
ifeq ($(DETECTED_OS),Windows)
"$(BIN_DIR)/open_jtalk.exe" --help || echo Built successfully
else
"$(BIN_DIR)/open_jtalk" --help || echo "Built successfully"
endif
# Install dependencies (for CI/automated builds)
install-deps:
ifeq ($(DETECTED_OS),Linux)
@echo Installing Linux dependencies...
@if command -v sudo >/dev/null 2>&1; then \
sudo apt-get update && sudo apt-get install -y build-essential autoconf automake libtool; \
else \
echo "Warning: sudo not available. Please install dependencies manually: apt-get install build-essential autoconf automake libtool"; \
fi
else ifeq ($(DETECTED_OS),Darwin)
@echo Installing macOS dependencies...
brew install autoconf automake libtool
else ifeq ($(DETECTED_OS),Windows)
@echo Windows dependencies should be installed via Visual Studio or Windows SDK
else
@echo Unsupported operating system for automatic dependency installation
endif
# Prepare artifacts for distribution
prepare-artifacts: build
@echo Preparing artifacts...
@$(MKDIR_P) artifacts
ifeq ($(DETECTED_OS),Windows)
$(CP) "$(BIN_DIR)/open_jtalk.exe" "artifacts/"
else
$(CP) "$(BIN_DIR)/open_jtalk" "artifacts/"
endif
$(CP) "LICENSE" "artifacts/"
$(CP) "Readme.md" "artifacts/"
@echo Artifacts prepared in ./artifacts/
# Clean build files
clean:
@echo Cleaning build files...
ifeq ($(DETECTED_OS),Windows)
cd "$(HTSENGINE_DIR)" && cmd //c "nmake /f Makefile.mak clean" || true
cd "$(OPENJTALK_DIR)" && cmd //c "nmake /f Makefile.mak clean" || true
@$(RM_F) "$(BIN_DIR)/open_jtalk.exe"
else
cd "$(HTSENGINE_DIR)" && make clean || true
cd "$(OPENJTALK_DIR)" && make clean || true
@$(RM_F) "$(BIN_DIR)/open_jtalk"
endif
@$(RM_RF) "artifacts"
@echo Clean completed!
# Deep clean - remove all generated files including configure scripts
distclean: clean
@echo Performing deep clean...
ifneq ($(DETECTED_OS),Windows)
cd "$(HTSENGINE_DIR)" && make distclean || true
cd "$(OPENJTALK_DIR)" && make distclean || true
find "$(HTSENGINE_DIR)" -name "Makefile" -not -name "Makefile.mak" -not -name "Makefile.am" -delete || true
find "$(OPENJTALK_DIR)" -name "Makefile" -not -name "Makefile.mak" -not -name "Makefile.am" -delete || true
endif
@echo Deep clean completed!
# Help target
help:
@echo OpenJTalk Multi-platform Build System
@echo ====================================
@echo Available targets:
@echo all - Build for current platform (default)
@echo build - Build for current platform
@echo build-windows - Build specifically for Windows
@echo build-linux - Build specifically for Linux
@echo build-macos - Build specifically for macOS
@echo test - Test the built executable
@echo install-deps - Install build dependencies
@echo prepare-artifacts- Prepare distribution artifacts
@echo clean - Clean build files
@echo distclean - Deep clean all generated files
@echo help - Show this help message
@echo
@echo Current platform: $(DETECTED_OS)
@echo
@echo Examples:
@echo make - Build for current platform
@echo make test - Build and test
@echo make install-deps- Install dependencies first
@echo make clean - Clean up build files