Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Created June 25, 2011 03:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlrobinson/1046105 to your computer and use it in GitHub Desktop.
Save tlrobinson/1046105 to your computer and use it in GitHub Desktop.
Remote Makefiles fun
$ make hello
hello world from localhost!
$ make foohost remote-hello
make: `foohost' is up to date.
make: Entering directory `/home/foouser/tmp'
hello world from foohost!
make: Leaving directory `/home/foouser/tmp'
$ make barhost remote-hello
make: `barhost' is up to date.
make: Entering directory `/home/baruser/tmp'
hello world from barhost!
make: Leaving directory `/home/baruser/tmp'
MAKEFILE=$(lastword $(MAKEFILE_LIST))
REMOTE?=$(REMOTE_USER)@$(REMOTE_HOST)
REMOTE_SSH?=ssh -p $(REMOTE_PORT)
REMOTE_SHELL?=$(REMOTE_SSH) $(REMOTE) $(REMOTE_LOGIN)
REMOTE_MAKE?=cat $(MAKEFILE) | $(REMOTE_SHELL) make -f /dev/stdin -C $(REMOTE_BASE)
# LOCAL COMMANDS:
hello:
@echo hello world from $(shell hostname)!
# REMOTE COMMANDS:
remote-%:
@$(REMOTE_MAKE) $*
# SERVERS:
foohost:
$(eval REMOTE_HOST := foohost)
$(eval REMOTE_PORT := 22)
$(eval REMOTE_USER := foouser)
$(eval REMOTE_BASE := /home/foouser/tmp)
barhost:
$(eval REMOTE_HOST := barhost)
$(eval REMOTE_PORT := 22)
$(eval REMOTE_USER := baruser)
$(eval REMOTE_BASE := /home/baruser/tmp)
@To1ne
Copy link

To1ne commented Jun 25, 2011

You don't need to use eval.
You can use target specific variables instead.

@tlrobinson
Copy link
Author

@To1ne: thanks for the tip but I don't quite see how I can use that. I'm relying on being able to set the host properties in a separate target that gets run first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment