Last active
May 27, 2022 09:08
-
-
Save janmartenjongerius/b48bd498484384975fe7ed338cf9aef4 to your computer and use it in GitHub Desktop.
Composer Makefile
This file contains 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 $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation
composer.mk
composer.mk
insideMakefile
include composer.mk
vendor
as dependency to your own targetsFeatures
vendor
locationsinstall
andupdate
composer.json
and acts accordinglycomposer
andcomposer.phar
namesVariables
Exposes the following variables:
$(PHP)
/usr/bin/php
$(COMPOSER)
/usr/bin/composer
$(COMPOSER_VENDOR_DIR)
vendor-dir
setting.vendor
$(COMPOSER_AUTOLOAD)
autoload.php
within the vendor directory.vendor/autoload.php
Example usage
Say we use
Makefile
to build a static website using PHP. Consider the following targets:Now one can run
make dist/index.html
and any Composer dependencies are taken care of automatically.Tips
composer.mk
at the top ofMakefile
, when runningmake
without specific target,vendor packages will be installed as needed.
Known limitations:
lock
setting set tofalse
. The filecomposer.lock
is a hard requirement for this template. One can tweak it to only look forcomposer.json
, if so desired.