#!/usr/bin/env bash # Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com). # All rights reserved. RESOURCE_FILE=".build.rc" BUILD_REGISTER=".build_register" PROGRAM_NAME="" PROGRAM_VERSION="" function usage() { prog=$(basename "${0}") msgln "USAGE:" #msgln " ${prog} /..." msgln " ${prog} /..." msgln " ${prog} --dev Build the local exec" msgln " ${prog} --init Create the resource file in the current directory" msgln if [ -r "${RESOURCE_FILE}" ]; then msgln "Resource file '${RESOURCE_FILE}' content:" cat >&2 ${RESOURCE_FILE} else msgln "Resource file '${RESOURCE_FILE}' not found" fi } function msgln() { echo >&2 "${1}" } function exitUsage() { echo >&2 "${1}" usage exit 1 } function exitMsg() { echo >&2 "${1}" exit 1 } # CMDLINE: help if [ "${1}" == "help,," ] || [ "${1,,}" == "--help" ] || [ "${1,,}" == "-h" ]; then usage exit fi # CMDLINE: init if [ "${1,,}" == "--init" ]; then cat >"${RESOURCE_FILE}" <"${BUILD_REGISTER}" "${PROGRAM_VERSION} ${count}" echo ${count} } function build() { local target=${1} ext cmd IFS=/ read os cpu <<<"${p}" #msgln "OS=${os}; CPU=${cpu}" ext="" if [ "${os}" == 'windows' ]; then ext=".exe" fi cmd="GOOS='${os}' GOARCH='${cpu}' go build -o '${PROGRAM_NAME}_v${PROGRAM_VERSION}_${os}_${cpu}${ext}'" eval "${cmd}" } function buildLocal() { local ext cmd ext="" if [[ "${OSTYPE}" =~ win.* ]]; then ext=".exe" fi cmd="go build -o '${PROGRAM_NAME}${ext}'" eval "${cmd}" } function exprPath() { local path path=$(grep -m1 -F "go-pkg/expr" go.work) echo ${path} } function gitTag() { local expr_path expr_path=$(exprPath) tag=$(git -C "${expr_path}" tag -l --sort=-version:refname "v*"|head -1) echo ${tag} } function createVersionSource() { local tag tag=$(gitTag) cat >version.go <