Skip to content

Instantly share code, notes, and snippets.

@m1tk4
Last active January 2, 2018 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m1tk4/48ddd3248129481516a4c5576c70b9a6 to your computer and use it in GitHub Desktop.
Save m1tk4/48ddd3248129481516a4c5576c70b9a6 to your computer and use it in GitHub Desktop.
Embedding PHP , Python and NodeJS code in makefiles
#
# Embedding languages in makefiles
#
# Try making targets in this makefile!
#
# Make variable for testing
MAKE_VARIABLE = 45678
all: php node python
# PHP
define PHP_CODE
<?
echo "Hello World!\n";
$$php_variable = 12345;
echo "My own variable \$$php_variable is $$php_variable.\n";
echo "Makefile variable MAKE_VARIABLE, inlined, is $(MAKE_VARIABLE)\n";
echo "I got " . ($$argc-1) ." command line parameters, and they are: '".
implode("', '", array_slice($$argv,1) )."'\n";
?>
endef
export PHP_CODE
php:
@echo $$PHP_CODE | php -- param1 param2 three
# Node
define NODE_CODE
console.log('Hello World!');
node_variable = 12345;
console.log('My own variable node_variable is ' + node_variable +'.');
console.log('Makefile variable MAKE_VARIABLE, inlined, is $(MAKE_VARIABLE)');
var a = process.argv.slice(2);
console.log('I got ' + a.length + ' command line parameters, and they are: \'' + a.join("', '") + "'");
endef
export NODE_CODE
node:
@T=`mktemp -t XXXXXXXXXXXXXX.js` && echo $$NODE_CODE>$$T && node $$T param1 param2 three; rm -f $$T
# this won't support command line parameters but will work!
node-stdin:
@echo $$NODE_CODE | node
define PYTHON_CODE
print "Hello World!"
python_variable = 12345
print "My own variable python_variable is %s" % python_variable
print "Makefile variable MAKE_VARIABLE, inlined, is $(MAKE_VARIABLE)"
import sys
print "I got %d command line parameters, and they are: %s" % (len(sys.argv)-1 ,str(sys.argv[1::])[1:-1])
endef
export PYTHON_CODE
python:
@echo "$$PYTHON_CODE" | python - param1 param2 three
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment