-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
158 lines (125 loc) · 5.92 KB
/
Makefile
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
pages_url := https://the-ai-alliance.github.io/REPO_NAME/
docs_dir := docs
site_dir := ${docs_dir}/_site
clean_dirs := ${site_dir} ${docs_dir}/.sass-cache
# Environment variables
MAKEFLAGS = -w # --warn-undefined-variables
MAKEFLAGS_RECURSIVE ?= # --print-directory (only useful for recursive makes...)
UNAME ?= $(shell uname)
ARCHITECTURE ?= $(shell uname -m)
# Override when running `make view-local` using e.g., `JEKYLL_PORT=8000 make view-local`
JEKYLL_PORT ?= 4000
# Used for version tagging release artifacts.
GIT_HASH ?= $(shell git show --pretty="%H" --abbrev-commit |head -1)
TIMESTAMP ?= $(shell date +"%Y%m%d-%H%M%S")
define help_message
Quick help for this make process.
make all # Clean and locally view the document.
make clean # Remove built artifacts, etc.
make view-pages # View the published GitHub pages in a browser.
make view-local # View the pages locally (requires Jekyll).
# Tip: "JEKYLL_PORT=8000 make view-local" uses port 8000 instead of 4000!
Miscellaneous tasks for help, debugging, setup, etc.
make help # Prints this output.
make print-info # Print the current values of some make and env. variables.
make setup-jekyll # Install Jekyll. Make sure Ruby is installed.
# (Only needed for local viewing of the document.)
make run-jekyll # Used by "view-local"; assumes everything is already built.
# Tip: "JEKYLL_PORT=8000 make run-jekyll" uses port 8000 instead of 4000!
endef
define missing_shell_command_error_message
is needed by ${PWD}/Makefile. Try 'make help' and look at the README.
endef
ifndef docs_dir
$(error ERROR: There is no ${docs_dir} directory!)
endif
define gem-error-message
ERROR: Did the gem command fail with a message like this?
ERROR: "You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory."
ERROR: To run the "gem install ..." command for the MacOS default ruby installation requires "sudo".
ERROR: Instead, use Homebrew (https://brew.sh) to install ruby and make sure "/usr/local/.../bin/gem"
ERROR: is on your PATH before "user/bin/gem".
ERROR:
ERROR: Or did the gem command fail with a message like this?
ERROR: Bundler found conflicting requirements for the RubyGems version:
ERROR: In Gemfile:
ERROR: foo-bar (>= 3.0.0) was resolved to 3.0.0, which depends on
ERROR: RubyGems (>= 3.3.22)
ERROR:
ERROR: Current RubyGems version:
ERROR: RubyGems (= 3.3.11)
ERROR: In this case, try "brew upgrade ruby" to get a newer version.
endef
define bundle-error-message
ERROR: Did the bundle command fail with a message like this?
ERROR: "/usr/local/opt/ruby/bin/bundle:25:in `load': cannot load such file -- /usr/local/lib/ruby/gems/3.1.0/gems/bundler-X.Y.Z/exe/bundle (LoadError)"
ERROR: Check that the /usr/local/lib/ruby/gems/3.1.0/gems/bundler-X.Y.Z directory actually exists.
ERROR: If not, try running the clean-jekyll command first:
ERROR: make clean-jekyll setup-jekyll
ERROR: Answer "y" (yes) to the prompts and ignore any warnings that you can't uninstall a "default" gem.
endef
define missing_ruby_gem_or_command_error_message
is needed by ${PWD}/Makefile. Try "gem install ..."
endef
define ruby_and_gem_required_message
'ruby' and 'gem' are required. See ruby-lang.org for installation instructions.
endef
define gem_required_message
Ruby's 'gem' is required. See ruby-lang.org for installation instructions.
endef
.PHONY: all view-pages view-local clean help
.PHONY: setup-jekyll run-jekyll
all:: clean view-local
help::
$(info ${help_message})
@echo
print-info:
@echo "GitHub Pages URL: ${pages_url}"
@echo "current dir: ${PWD}"
@echo "docs dir: ${docs_dir}"
@echo "site dir: ${site_dir}"
@echo "clean dirs: ${clean_dirs} (deleted by 'make clean')"
@echo
@echo "GIT_HASH: ${GIT_HASH}"
@echo "TIMESTAMP: ${TIMESTAMP}"
@echo "MAKEFLAGS: ${MAKEFLAGS}"
@echo "MAKEFLAGS_RECURSIVE: ${MAKEFLAGS_RECURSIVE}"
@echo "UNAME: ${UNAME}"
@echo "ARCHITECTURE: ${ARCHITECTURE}"
@echo "GIT_HASH: ${GIT_HASH}"
@echo "TIMESTAMP: ${TIMESTAMP}"
@echo "JEKYLL_PORT: ${JEKYLL_PORT}"
clean::
rm -rf ${clean_dirs}
view-pages::
@python -m webbrowser "${pages_url}" || \
(echo "ERROR: I could not open the GitHub Pages URL. Try ⌘-click or ^-click on this URL instead:" && \
echo "ERROR: ${pages_url}" && exit 1 )
view-local:: setup-jekyll run-jekyll
# Passing --baseurl '' allows us to use `localhost:4000` rather than require
# `localhost:4000/The-AI-Alliance/REPO_NAME` when running locally.
run-jekyll: clean
@echo
@echo "Once you see the http://127.0.0.1:${JEKYLL_PORT}/ URL printed, open it with command+click..."
@echo
cd ${docs_dir} && bundle exec jekyll serve --port ${JEKYLL_PORT} --baseurl '' --incremental || ( echo "ERROR: Failed to run Jekyll. Try running 'make setup-jekyll'." && exit 1 )
setup-jekyll:: ruby-installed-check bundle-ruby-command-check
@echo "Updating Ruby gems required for local viewing of the docs, including jekyll."
gem install jekyll bundler jemoji || ${MAKE} gem-error
bundle install || ${MAKE} bundle-error
bundle update html-pipeline || ${MAKE} bundle-error
ruby-installed-check:
@command -v ruby > /dev/null || \
( echo "ERROR: ${ruby_and_gem_required_message}" && exit 1 )
@command -v gem > /dev/null || \
( echo "ERROR: ${gem_required_message}" && exit 1 )
%-error:
$(error ${${@}-message})
%-ruby-command-check:
@command -v ${@:%-ruby-command-check=%} > /dev/null || \
( echo "ERROR: Ruby command/gem ${@:%-ruby-command-check=%} ${missing_ruby_gem_or_command_error_message}" && \
exit 1 )
%-shell-command-check:
@command -v ${@:%-shell-command-check=%} > /dev/null || \
( echo "ERROR: shell command ${@:%-shell-command-check=%} ${missing_shell_command_error_message}" && \
exit 1 )