-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
181 lines (155 loc) · 5.44 KB
/
Copy pathMakefile
File metadata and controls
181 lines (155 loc) · 5.44 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
# Description: Makefile for building and installing a Go application
# Author: Rafael Mori
# Copyright (c) 2025 Rafael Mori
# License: MIT License
# Define the application name and root directory
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TARGET_MANIFEST = $(ROOT_DIR)internal/module/info/manifest.json
APP_NAME := $(shell jq -r '.name' < $(TARGET_MANIFEST))
_RUN_PRE_SCRIPTS := $(shell echo "true")
_RUN_POST_SCRIPTS := $(shell echo "true")
ifeq ($(APP_NAME),)
APP_NAME := $(shell echo $(basename $(CURDIR)) | tr '[:upper:]' '[:lower:]')
endif
ORGANIZATION := $(shell jq -r '.organization' < $(TARGET_MANIFEST))
ifeq ($(ORGANIZATION),)
ORGANIZATION := $(shell git config --get user.name | tr '[:upper:]' '[:lower:]')
endif
ifeq ($(ORGANIZATION),)
ORGANIZATION := $(shell git config --get user.email | cut -d '@' -f 1 | tr '[:upper:]' '[:lower:]')
endif
ifeq ($(ORGANIZATION),)
ORGANIZATION := $(shell echo $(USER) | tr '[:upper:]' '[:lower:]')
endif
REPOSITORY := $(shell jq -r '.repository' < $(TARGET_MANIFEST))
ifeq ($(REPOSITORY),)
REPOSITORY := $(shell git config --get remote.origin.url)
endif
ifeq ($(REPOSITORY),)
REPOSITORY := $(shell git config --get remote.upstream.url)
endif
ifeq ($(REPOSITORY),)
REPOSITORY := $(printf 'https://github.com/%s/%s.git' $(ORGANIZATION) $(APP_NAME))
endif
DESCRIPTION := $(shell jq -r '.description' < $(TARGET_MANIFEST))
ifeq ($(DESCRIPTION),)
DESCRIPTION := $(shell git log -1 --pretty=%B | head -n 1)
endif
BINARY_NAME := $(shell jq -r '.bin' < $(TARGET_MANIFEST))
ifeq ($(BINARY_NAME),)
BINARY_NAME := $(ROOT_DIR)dist/$(APP_NAME)
else
BINARY_NAME := $(ROOT_DIR)dist/$(BINARY_NAME)
endif
CMD_DIR := $(ROOT_DIR)cmd
# Define the color codes
COLOR_GREEN := \033[32m
COLOR_YELLOW := \033[33m
COLOR_RED := \033[31m
COLOR_BLUE := \033[34m
COLOR_RESET := \033[0m
# Logging Functions
log = @printf "%b%s%b %s\n" "$(COLOR_BLUE)" "[LOG]" "$(COLOR_RESET)" "$(1)"
log_info = @printf "%b%s%b %s\n" "$(COLOR_BLUE)" "[INFO]" "$(COLOR_RESET)" "$(1)"
log_success = @printf "%b%s%b %s\n" "$(COLOR_GREEN)" "[SUCCESS]" "$(COLOR_RESET)" "$(1)"
log_warning = @printf "%b%s%b %s\n" "$(COLOR_YELLOW)" "[WARNING]" "$(COLOR_RESET)" "$(1)"
log_break = @printf "%b%s%b\n" "$(COLOR_BLUE)" "[INFO]" "$(COLOR_RESET)"
log_error = @printf "%b%s%b %s\n" "$(COLOR_RED)" "[ERROR]" "$(COLOR_RESET)" "$(1)"
ARGUMENTS := $(MAKECMDGOALS)
INSTALL_SCRIPT = $(ROOT_DIR)support/main.sh
CMD_STR := $(strip $(firstword $(ARGUMENTS)))
ARGS := $(filter-out $(strip $(CMD_STR)), $(ARGUMENTS))
# Default target: help
.DEFAULT_GOAL := help
# Build the binary using the install script.
build:
@bash $(INSTALL_SCRIPT) build $(ARGS)
$(shell exit 0)
build-dev:
@bash $(INSTALL_SCRIPT) build-dev $(ARGS)
$(shell exit 0)
# Install the binary and configure the environment.
install:
@bash $(INSTALL_SCRIPT) install $(ARGS)
$(shell exit 0)
# Uninstall the binary and clean up.
uninstall:
@bash $(INSTALL_SCRIPT) uninstall $(ARGS)
$(shell exit 0)
# Clean up build artifacts.
clean:
@bash $(INSTALL_SCRIPT) clean $(ARGS)
$(shell exit 0)
# Run tests.
test:
@bash $(INSTALL_SCRIPT) test $(ARGS)
$(shell exit 0)
optimize-images:
@bash $(INSTALL_SCRIPT) optimize-images $(ARGS)
$(shell exit 0)
# Platform-specific targets (prevent wildcard capture)
linux:
@echo "Process finished for platform: linux"
amd64:
@echo "Process finished for architecture: amd64"
windows:
@echo "Process finished for platform: windows"
darwin:
@echo "Process finished for platform: darwin"
arm64:
@echo "Process finished for architecture: arm64"
armv6l:
@echo "Process finished for architecture: armv6l"
386:
@echo "Process finished for architecture: 386"
all:
@echo "Process finished for all platforms and architectures"
build-docs:
@echo "Building documentation..."
@bash $(INSTALL_SCRIPT) build-docs $(ARGS)
$(shell exit 0)
serve-docs:
@echo "Starting documentation server..."
@bash $(INSTALL_SCRIPT) serve-docs $(ARGS)
pub-docs:
@echo "Publishing documentation..."
@bash $(INSTALL_SCRIPT) pub-docs $(ARGS)
$(shell exit 0)
## Run dynamic commands with arguments calling the install script.
%:
@:
$(call log_info, Running command: $(CMD_STR))
$(call log_info, Args: $(ARGS))
@bash $(INSTALL_SCRIPT) $(CMD_STR) $(ARGS)
$(shell exit 0)
# Display help message
help:
$(call log, $(APP_NAME) Build System Help)
$(call log_break)
$(call log, Available targets:)
$(call log, make build - Build the binary using install script)
$(call log, make install - Install the binary and configure environment)
$(call log, make docs - Start API documentation server)
$(call log, make build-docs - Build documentation server binary)
$(call log, make clean - Clean up build artifacts)
$(call log, make test - Run tests)
$(call log, make help - Display this help message)
$(call log_break)
$(call log, Documentation:)
$(call log, make docs - Starts beautiful API documentation at http://localhost:8080/docs)
$(call log, ./start-docs.sh - Alternative way to start documentation server)
$(call log_break)
$(call log, Usage with arguments:)
$(call log, make install ARGS='--custom-arg value' - Pass custom arguments to the install script)
$(call log_break)
$(call log, Example:)
$(call log, make install ARGS='--prefix /usr/local')
$(call log_break)
$(call log, Description:)
$(call log, $(DESCRIPTION))
$(call log_break)
$(call log, For more information, visit:)
$(call log, $(REPOSITORY))
$(call log_break)
$(call log_success, End of help message)
$(shell exit 0)