|
| 1 | +# https://github.com/aclark4life/makefile |
| 2 | +# |
| 3 | +# The MIT License (MIT) |
| 4 | +# |
| 5 | +# Copyright (c) 2016–2020 Alex Clark |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +# of this software and associated documentation files (the "Software"), to deal |
| 9 | +# in the Software without restriction, including without limitation the rights |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +# copies of the Software, and to permit persons to whom the Software is |
| 12 | +# furnished to do so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in all |
| 15 | +# copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | +# SOFTWARE. |
| 24 | + |
| 25 | +#------------------------------------------------------------------------------- |
| 26 | + |
| 27 | +# Default Goal |
| 28 | +# |
| 29 | +# https://www.gnu.org/software/make/manual/html_node/Goals.html |
| 30 | +# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables |
| 31 | +# |
| 32 | +# By default, the goal is the first target in the makefile (not counting targets |
| 33 | +# that start with a period). Therefore, makefiles are usually written so that the |
| 34 | +# first target is for compiling the entire program or programs they describe. If |
| 35 | +# the first rule in the makefile has several targets, only the first target in the |
| 36 | +# rule becomes the default goal, not the whole list. You can manage the selection |
| 37 | +# of the default goal from within your makefile using the .DEFAULT_GOAL variable |
| 38 | +# (see Other Special Variables). |
| 39 | + |
| 40 | +.DEFAULT_GOAL=usage |
| 41 | + |
| 42 | +#------------------------------------------------------------------------------- |
| 43 | + |
| 44 | +# Variables |
| 45 | + |
| 46 | +# A variable is a name defined in a makefile to represent a string of text, called |
| 47 | +# the variable's value. These values are substituted by explicit request into targets, |
| 48 | +# prerequisites, recipes, and other parts of the makefile. |
| 49 | +# |
| 50 | +# https://www.gnu.org/software/make/manual/html_node/Using-Variables.html |
| 51 | + |
| 52 | +# Flavors |
| 53 | + |
| 54 | +# https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors |
| 55 | + |
| 56 | +COMMIT_MESSAGE = "Update" |
| 57 | +PROJECT = project |
| 58 | +APP = app |
| 59 | +# https://stackoverflow.com/a/589260/185820 |
| 60 | +TMPDIR := $(shell mktemp -d) |
| 61 | +RANDIR := $(shell openssl rand -base64 12 | sed 's/\///g') |
| 62 | +UNAME := $(shell uname) |
| 63 | +# http://unix.stackexchange.com/a/37316 |
| 64 | +REMOTE_BRANCHES = `git branch -a | grep remote | grep -v HEAD | grep -v master` |
| 65 | + |
| 66 | +#------------------------------------------------------------------------------- |
| 67 | + |
| 68 | +# Additional Concepts for this Makefile |
| 69 | +# |
| 70 | +# "Alias" - A new target definition that only exists to create a shorter target |
| 71 | +# name for another target that already exists. |
| 72 | +# |
| 73 | +# "Multi-target Alias" - Like an "Alias", but with multiple targets. |
| 74 | +# |
| 75 | +# "BBB" - For backwards compatibility. Via |
| 76 | +# https://docs.plone.org/appendices/glossary.html |
| 77 | + |
| 78 | +#------------------------------------------------------------------------------- |
| 79 | + |
| 80 | +# Rules |
| 81 | +# |
| 82 | +# A rule appears in the makefile and says when and how to remake certain files, |
| 83 | +# called the rule's targets (most often only one per rule). It lists the other |
| 84 | +# files that are the prerequisites of the target, and the recipe to use to |
| 85 | +# create or update the target. |
| 86 | +# |
| 87 | +# https://www.gnu.org/software/make/manual/html_node/Rules.html |
| 88 | + |
| 89 | +########## |
| 90 | +# Django # |
| 91 | +########## |
| 92 | + |
| 93 | +django-init-app: |
| 94 | + -mkdir -p $(PROJECT)/$(APP)/templates |
| 95 | + -touch $(PROJECT)/$(APP)/templates/base.html |
| 96 | + -django-admin startproject $(PROJECT) . |
| 97 | + -django-admin startapp $(APP) $(PROJECT)/$(APP) |
| 98 | +django-init-db: # PostgreSQL |
| 99 | + -dropdb $(PROJECT) |
| 100 | + -createdb $(PROJECT) |
| 101 | +init-db: django-init-db # Alias |
| 102 | +django-graph: |
| 103 | + python manage.py graph_models $(APP) -o graph_models_$(PROJECT)_$(APP).png |
| 104 | +django-init: |
| 105 | + @$(MAKE) pip-install-django |
| 106 | + @$(MAKE) django-init-db |
| 107 | + @$(MAKE) django-init-app |
| 108 | + @$(MAKE) django-up-settings |
| 109 | + git add $(PROJECT) |
| 110 | + git add manage.py |
| 111 | + @$(MAKE) commit-push |
| 112 | +django-migrate: |
| 113 | + python manage.py migrate |
| 114 | +django-migrations-default: |
| 115 | + python manage.py makemigrations $(APP) |
| 116 | + git add $(PROJECT)/$(APP)/migrations/*.py |
| 117 | +django-serve-default: |
| 118 | + python manage.py runserver 0.0.0.0:8000 |
| 119 | +django-test: |
| 120 | + python manage.py test |
| 121 | +django-up-settings: |
| 122 | + echo "STATIC_ROOT = 'static'" >> $(PROJECT)/settings.py |
| 123 | + echo "ALLOWED_HOSTS = ['*']" >> $(PROJECT)/settings.py |
| 124 | + echo "AUTH_PASSWORD_VALIDATORS = [{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', },]" >> $(PROJECT)/settings.py |
| 125 | + echo "import dj_database_url; DATABASES = { 'default': dj_database_url.config(default=os.environ.get( 'DATABASE_URL', 'postgres://%s:%s@%s:%s/%s' % (os.environ.get('DB_USER', ''), os.environ.get('DB_PASS', ''), os.environ.get('DB_HOST', 'localhost'), os.environ.get('DB_PORT', '5432'), os.environ.get('DB_NAME', 'project_app'))))}" >> $(PROJECT)/settings.py |
| 126 | +django-shell: |
| 127 | + python manage.py shell |
| 128 | +django-static: |
| 129 | + python manage.py collectstatic --noinput |
| 130 | +django-su: |
| 131 | + python manage.py createsuperuser |
| 132 | +django-loaddata-default: |
| 133 | + python manage.py loaddata |
| 134 | +django-yapf: |
| 135 | + -yapf -i *.py |
| 136 | + -yapf -i $(PROJECT)/*.py |
| 137 | + -yapf -i $(PROJECT)/$(APP)/*.py |
| 138 | +django-wc: |
| 139 | + -wc -l *.py |
| 140 | + -wc -l $(PROJECT)/*.py |
| 141 | + -wc -l $(PROJECT)/$(APP)/*.py |
| 142 | +graph: django-graph |
| 143 | +migrate: django-migrate # Alias |
| 144 | +migrations: django-migrations # Alias |
| 145 | +static: django-static # Alias |
| 146 | +su: django-su # Alias |
| 147 | +test: django-test # Alias |
| 148 | +loaddata: django-loaddata # Alias |
| 149 | + |
| 150 | +########## |
| 151 | +# Drupal # |
| 152 | +########## |
| 153 | + |
| 154 | +drupal-init-composer-8: |
| 155 | + composer create-project drupal/recommended-project $(RANDIR) --no-interaction |
| 156 | +drupal-init-docksal-7: |
| 157 | + git clone https://github.com/docksal/boilerplate-drupal7.git d7 |
| 158 | + cd d7; fin init |
| 159 | +drupal-init-docksal-8: |
| 160 | + git clone https://github.com/docksal/boilerplate-drupal8.git d8 |
| 161 | + cd d8; fin init |
| 162 | +d7: drupal-init-docksal-7 # Alias |
| 163 | +d8: drupal-init-docksal-8 # Alias |
| 164 | + |
| 165 | +####### |
| 166 | +# Git # |
| 167 | +####### |
| 168 | + |
| 169 | +git-ignore: |
| 170 | + echo ".Python\nbin/\ninclude/\nlib/\n.vagrant/\n" >> .gitignore |
| 171 | + git add .gitignore |
| 172 | + $(MAKE) commit-push |
| 173 | +git-init: |
| 174 | + git init |
| 175 | + hub create $(RANDDIR) |
| 176 | + hub browse |
| 177 | +git-branches: |
| 178 | + -for i in $(REMOTE_BRANCHES) ; do \ |
| 179 | + git checkout -t $$i ; done |
| 180 | +git-prune: |
| 181 | + git remote update origin --prune |
| 182 | +git-commit: |
| 183 | + git commit -a -m $(COMMIT_MESSAGE) |
| 184 | +git-commit-edit: |
| 185 | + git commit -a |
| 186 | +git-push: |
| 187 | + git push |
| 188 | +git-push-up: |
| 189 | + git push --set-upstream origin master |
| 190 | +commit: git-commit # Alias |
| 191 | +ce: commit-edit # Alias |
| 192 | +cp: commit-push # Alias |
| 193 | +push: git-push # Alias |
| 194 | +p: push # Alias |
| 195 | +commit-push: git-commit git-push # Multi-target Alias |
| 196 | +commit-push-up: git-commit git-push-up # Multi-target Alias |
| 197 | +commit-edit: git-commit-edit git-push # Multi-target Alias |
| 198 | +git-commit-auto-push: commit-push # BBB |
| 199 | +git-commit-edit-push: commit-edit-push # BBB |
| 200 | + |
| 201 | +######## |
| 202 | +# Misc # |
| 203 | +######## |
| 204 | + |
| 205 | +rand: |
| 206 | + @openssl rand -base64 12 | sed 's/\///g' |
| 207 | +r: rand # Alias |
| 208 | + |
| 209 | +readme: |
| 210 | + echo "Creating README.rst" |
| 211 | + @echo $(PROJECT) > README.rst |
| 212 | + @echo ================================================================================ >> README.rst |
| 213 | + echo "Done." |
| 214 | + git add README.rst |
| 215 | + @$(MAKE) commit-push |
| 216 | + |
| 217 | +review: |
| 218 | +ifeq ($(UNAME), Darwin) |
| 219 | + @open -a $(EDITOR) `find $(PROJECT) -name \*.py | grep -v __init__.py | grep -v migrations`\ |
| 220 | + `find $(PROJECT) -name \*.html` `find $(PROJECT) -name \*.js` |
| 221 | +else |
| 222 | + @echo "Unsupported" |
| 223 | +endif |
| 224 | + |
| 225 | +list-targets: |
| 226 | + @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F:\ |
| 227 | + '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}'\ |
| 228 | + | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs | tr ' ' '\n' | awk\ |
| 229 | + '{print "make "$$0}' | less # http://stackoverflow.com/a/26339924 |
| 230 | +help: list-targets # Alias |
| 231 | +h: list-targets # Alias |
| 232 | + |
| 233 | +usage: |
| 234 | + @echo "Project Makefile" |
| 235 | + @echo "Usage:\n" |
| 236 | + @echo "\tmake <target>\n" |
| 237 | + @echo "Help:\n" |
| 238 | + @echo "\tmake help" |
| 239 | + |
| 240 | +make: |
| 241 | + git add Makefile |
| 242 | + @$(MAKE) commit-push-up |
| 243 | + |
| 244 | +deploy-default: |
| 245 | + eb deploy |
| 246 | +d: deploy # Alias |
| 247 | + |
| 248 | +####### |
| 249 | +# Pip # |
| 250 | +####### |
| 251 | + |
| 252 | +pip-freeze-default: |
| 253 | + pip freeze | sort > $(TMPDIR)/requirements.txt |
| 254 | + mv -f $(TMPDIR)/requirements.txt . |
| 255 | +pip-install: |
| 256 | + pip install -r requirements.txt |
| 257 | +pip-install-test: |
| 258 | + pip install -r requirements-test.txt |
| 259 | +pip-install-django: |
| 260 | + @echo "Django\ndj-database-url\npsycopg2-binary\n" > requirements.txt |
| 261 | + @$(MAKE) pip-install |
| 262 | + @$(MAKE) freeze |
| 263 | + -git add requirements.txt |
| 264 | + -@$(MAKE) commit-push-up |
| 265 | +pip-install-sphinx: |
| 266 | + echo "Sphinx\n" > requirements.txt |
| 267 | + $(MAKE) pip-install |
| 268 | +pip-upgrade-default: |
| 269 | + cat requirements.txt | awk -F \= '{print $1}' > $(TMPDIR)/requirements.txt |
| 270 | + mv -f $(TMPDIR)/requirements.txt . |
| 271 | + pip install -U -r requirements.txt |
| 272 | + $(MAKE) pip-freeze |
| 273 | +freeze: pip-freeze # Alias |
| 274 | + |
| 275 | +########## |
| 276 | +# Python # |
| 277 | +########## |
| 278 | + |
| 279 | +python-serve: |
| 280 | + @echo "\n\tServing HTTP on http://0.0.0.0:8000\n" |
| 281 | + python -m http.server |
| 282 | +python-virtualenv-2-6: |
| 283 | + virtualenv --python=python2.6 . |
| 284 | +python-virtualenv-2-7: |
| 285 | + virtualenv --python=python2.7 . |
| 286 | +python-virtualenv-3-7: |
| 287 | + virtualenv --python=python3.7 . |
| 288 | +python-virtualenv: python-virtualenv-3-7 # Alias |
| 289 | +virtualenv: python-virtualenv-3-7 # Alias |
| 290 | +virtualenv-2: python-virtualenv-2-7 # Alias |
| 291 | +serve: python-serve # Alias |
| 292 | + |
| 293 | +########## |
| 294 | +# Sphinx # |
| 295 | +########## |
| 296 | + |
| 297 | +sphinx-build: |
| 298 | + sphinx-build -b html -d _build/doctrees . _build/html |
| 299 | +sphinx-init: |
| 300 | + $(MAKE) pip-install-sphinx |
| 301 | + sphinx-quickstart -q -p $(PROJECT) -a $(USER) -v 0.0.1 $(RANDIR) |
| 302 | + mv $(RANDIR)/* . |
| 303 | + rmdir $(RANDIR) |
| 304 | +sphinx-serve: |
| 305 | + cd _build/html;python -m http.server |
| 306 | + |
| 307 | +########### |
| 308 | +# Vagrant # |
| 309 | +########### |
| 310 | + |
| 311 | +vagrant-init: |
| 312 | + vagrant init ubuntu/trusty64 |
| 313 | + git add Vagrantfile |
| 314 | + $(MAKE) git-push-up |
| 315 | + $(MAKE) vagrant-up |
| 316 | +vagrant-up: |
| 317 | + vagrant up --provider virtualbox |
| 318 | +vagrant: vagrant-init # Alias |
| 319 | +vm: vagrant-init # Alias |
| 320 | + |
| 321 | +#------------------------------------------------------------------------------- |
| 322 | + |
| 323 | +# Overrides |
| 324 | +# |
| 325 | +# https://www.gnu.org/software/make/manual/html_node/Overriding-Makefiles.html |
| 326 | +# |
| 327 | +# https://stackoverflow.com/a/49804748 |
| 328 | +%: %-default |
| 329 | + @ true |
| 330 | + |
| 331 | +#PROJECT = project |
| 332 | +#APP = app |
| 333 | +.DEFAULT_GOAL=commit-push |
| 334 | +#install: pip-install |
0 commit comments