Last active
May 27, 2022 09:08
-
-
Save janmartenjongerius/b48bd498484384975fe7ed338cf9aef4 to your computer and use it in GitHub Desktop.
Composer Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Updates at https://gist.github.com/johmanx10/b48bd498484384975fe7ed338cf9aef4 | |
| # Composer configuration | |
| PHP := $(shell command -v php || echo php) | |
| COMPOSER := $(shell command -v composer.phar || command -v composer || echo composer) | |
| COMPOSER_VENDOR_DIR := $(shell $(COMPOSER) config vendor-dir || echo vendor) | |
| COMPOSER_AUTOLOAD := $(shell echo "$(COMPOSER_VENDOR_DIR)/autoload.php") | |
| # Install vendor dependencies. | |
| $(COMPOSER_VENDOR_DIR) $(COMPOSER_AUTOLOAD): | composer.lock $(COMPOSER) | |
| $(COMPOSER) install | |
| # Ensure one can always require 'vendor' | |
| vendor: | $(COMPOSER_AUTOLOAD) | |
| # Local application dependencies. | |
| $(COMPOSER): | $(PHP) | |
| # Update the lock file if the package file has changed. | |
| composer.lock: composer.json | $(COMPOSER) | |
| $(COMPOSER) update && touch $@ |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation
composer.mkcomposer.mkinsideMakefileinclude composer.mkvendoras dependency to your own targetsFeatures
vendorlocationsinstallandupdatecomposer.jsonand acts accordinglycomposerandcomposer.pharnamesVariables
Exposes the following variables:
$(PHP)/usr/bin/php$(COMPOSER)/usr/bin/composer$(COMPOSER_VENDOR_DIR)vendor-dirsetting.vendor$(COMPOSER_AUTOLOAD)autoload.phpwithin the vendor directory.vendor/autoload.phpExample usage
Say we use
Makefileto build a static website using PHP. Consider the following targets:Now one can run
make dist/index.htmland any Composer dependencies are taken care of automatically.Tips
composer.mkat the top ofMakefile, when runningmakewithout specific target,vendor packages will be installed as needed.
Known limitations:
locksetting set tofalse. The filecomposer.lockis a hard requirement for this template. One can tweak it to only look forcomposer.json, if so desired.