Skip to content

Commit

Permalink
add build,dist, move sha calc out of archive
Browse files Browse the repository at this point in the history
  • Loading branch information
yelsaw committed Sep 13, 2024
1 parent e1dd84e commit a375c88
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,59 @@ OS_BUILDS = linux darwin windows

APP := gotp
BUILD_DIR := "build"
SHA_FILE := $(APP)-sha256.txt
LIC_FILE := LICENSE

SHA_FILE = sha256.txt
LIC_FILE = LICENSE

GO_LDFLAGS = "-s -extldflags=-static"

all: rmbuild $(OS_BUILDS) checksum archive
# Builds all binaries to BUILD_DIR/{linux,darwin,windows}
build: clean $(OS_BUILDS)

# Builds all binaries, archives with LIC_FILE, and creates sha256sum
dist: clean $(OS_BUILDS) archive checksum

# Builds binary and outputs to BUILD_DIR/linux
linux:
@GOOS=linux CGO_ENABLED=0 go build -ldflags=$(GO_LDFLAGS) -o build/linux/$(APP)
@echo "output build/linux/$(APP)"

# Builds binary and outputs to BUILD_DIR/darwin
darwin:
@GOOS=darwin go build -ldflags=$(GO_LDFLAGS) -o build/darwin/$(APP)
@echo "output build/darwin/$(APP)"

# Builds binary and outputs to BUILD_DIR/windows
windows:
@GOOS=windows go build -ldflags=$(GO_LDFLAGS) -o build/windows/$(APP).exe
@echo "output build/windows/$(APP).exe"

# Creates archives for distribution
archive:
@echo "Creating tar/zip archives"
@for os in $(OS_BUILDS); do \
if [ "$$os" = "windows" ]; then \
echo "Creating zip archive for $$os"; \
if [ "$$os" = "windows" ]; then \
cp -a $(LIC_FILE) $(BUILD_DIR)/$$os/$(LIC_FILE).txt; \
zip -r $(BUILD_DIR)/$(APP)-$$os-v$(VERSION).zip -j $(BUILD_DIR)/$$os/; \
else \
echo "Creating tar archive for $$os"; \
cp -a $(LIC_FILE) $(BUILD_DIR)/$$os/; \
tar -cf $(BUILD_DIR)/$(APP)-$$os-v$(VERSION).tar -C $(BUILD_DIR)/$$os $(APP) $(LIC_FILE) $(SHA_FILE); \
tar -cf $(BUILD_DIR)/$(APP)-$$os-v$(VERSION).tar -C $(BUILD_DIR)/$$os $(APP) $(LIC_FILE); \
fi \
done

# Creates sha256sum for distribution
checksum:
@echo "Creating checksum hashes"
@for os in $(OS_BUILDS); do \
( \
cd $(BUILD_DIR)/$$os && \
if [ "$$os" = "windows" ]; then \
sha256sum $(APP).exe > $(SHA_FILE); \
sha256sum $(BUILD_DIR)/$(APP)-$$os-v$(VERSION).zip > $(BUILD_DIR)/$(APP)-$$os-v$(VERSION)-$(SHA_FILE); \
else \
sha256sum $(APP) > $(SHA_FILE); \
sha256sum $(BUILD_DIR)/$(APP)-$$os-v$(VERSION).tar > $(BUILD_DIR)/$(APP)-$$os-v$(VERSION)-$(SHA_FILE); \
fi \
) \
done

rmbuild:
@rm -rf $(BUILD_DIR)
# Removes BUILD_DIR
clean:
@echo "Removing $(BUILD_DIR) dir"
@rm -rf $(BUILD_DIR)

0 comments on commit a375c88

Please sign in to comment.