59 lines
1.7 KiB
Bash
Executable File
59 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Default architecture
|
|
DEFAULT_ARCH="linux/amd64"
|
|
|
|
# Supported architectures (adjust as needed)
|
|
ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7" "darwin/amd64" "darwin/arm64")
|
|
|
|
# Ensure all necessary directories exist and go modules are ready
|
|
prepare_build() {
|
|
# Create necessary directories if they don't exist
|
|
mkdir -p dist
|
|
mkdir -p build_logs
|
|
|
|
# Initialize go modules if go.mod does not exist
|
|
if [ ! -f go.mod ]; then
|
|
echo "Initializing Go modules"
|
|
go mod init imap-json-fetcher # Adjust the module name as needed
|
|
fi
|
|
|
|
# Fetch and ensure all dependencies are up to date
|
|
echo "Checking dependencies..."
|
|
go mod tidy
|
|
}
|
|
|
|
# Build function
|
|
build_binary() {
|
|
local os=$1
|
|
local arch=$2
|
|
local output_name="imap-json-fetcher"
|
|
|
|
# Adjust output name for non-default architectures
|
|
if [[ "$os/$arch" != "$DEFAULT_ARCH" ]]; then
|
|
output_name="${output_name}_${os}_${arch}"
|
|
fi
|
|
|
|
output_name="dist/${output_name}"
|
|
|
|
# Build both dynamic and static binaries as needed
|
|
echo "Building for ${os}/${arch} -> ${output_name}"
|
|
CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go build -a -ldflags '-extldflags "-static"' -o ${output_name} main.go 2>build_logs/${os}_${arch}_build.log
|
|
if [ $? -eq 0 ]; then
|
|
echo "Successfully built ${output_name}"
|
|
else
|
|
echo "Failed to build ${output_name}. Check build_logs/${os}_${arch}_build.log for errors."
|
|
fi
|
|
}
|
|
|
|
# Main Build Process
|
|
prepare_build
|
|
for arch in "${ARCHITECTURES[@]}"; do
|
|
IFS='/' read -r -a parts <<< "$arch" # Split architecture string into OS and arch
|
|
os=${parts[0]}
|
|
arch=${parts[1]}
|
|
build_binary $os $arch
|
|
done
|
|
|
|
echo "Build process completed."
|