new_contents = "hello:\n\\techo \$$(cooly)" all: mkdir -p subdir echo -e $(new_contents) | sed -e 's/^ //' > subdir/makefile @echo "---MAKEFILE CONTENTS---" @cd subdir && cat makefile @echo "---END MAKEFILE CONTENTS---" cd subdir && $(MAKE) # Note that variables and exports. They are set/affected globally. cooly = "The subdirectory can see me!" export cooly # This would nullify the line above: unexport cooly clean: rm -rf subdir