Skip to content

Commit

Permalink
add install target
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhurt committed Jul 12, 2024
1 parent c40f326 commit f471ae6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export GO111MODULE = on
build:
@build/build.sh

install:
@build/build.sh -i

test:
@go test -v ./...

Expand Down
17 changes: 12 additions & 5 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#!/usr/bin/env bash
#
## package declarations
BUILD_NAME="ipman"
BUILD_NAME=$(basename "$(grep ^module go.mod|cut -f2 -d' ')")
RELEASE_VERSION="0.1"
RELEASE_BUILD=0

## default to build
GO_ACTION=build

## simple usage example
showUsage() {
printf "Usage: %s [-d|-c|-r]
-d Remove binary and vendor directory
-c Clean distribution files
-r Build and package release binaries\n\n" "$0"
-r Build and package release binaries
-i Run 'go install' instead of 'go build'\n\n" "$0"
exit 0
}

Expand All @@ -29,7 +33,7 @@ export GO111MODULE=on
should_exit=false

## read options
while getopts ":dcr" opt; do
while getopts ":dcri" opt; do
case $opt in
d)
printf "Removing binary and vendor directory ... "
Expand All @@ -47,6 +51,9 @@ while getopts ":dcr" opt; do
ensureGox
RELEASE_BUILD=1
;;
i)
GO_ACTION=install
;;
*)
showUsage
;;
Expand Down Expand Up @@ -79,7 +86,7 @@ if [ $RELEASE_BUILD -eq 1 ]; then
else

## build it
CGO_ENABLED=0 go build -o "${BUILD_NAME}" \
CGO_ENABLED=0 go ${GO_ACTION} \
-ldflags="-X main.appVersion=${RELEASE_VERSION} -s -w" \
> /dev/null >&1

Expand Down Expand Up @@ -108,7 +115,7 @@ if [ $RELEASE_BUILD -eq 1 ]; then
printf "done.\nRelease files may be found in the ./dist/ directory.\n"
else
## all done
printf "done.\nUsage: ./%s -h\n" "${BUILD_NAME}"
printf "done.\nUsage: %s -h\n" "${BUILD_NAME}"
fi

## exit same as build
Expand Down

0 comments on commit f471ae6

Please sign in to comment.