Anonymous Penguin
Anonymous Penguin

Reputation: 2137

What would happen when a makefile edits itself?

I'm creating a makefile for one of my projects. One of the things I want to do with this is to pull from a git repository when it is appropriate. However, I plan to have the makefile within the repo so I can edit it and push the changes.

What would happen if this code was ran and there was a change in the makefile on the remote server in the repository?

# ... More code before here

git:
    git pull

(Pretend those are tabs as I can't type a tab in the editor)

Would:

Upvotes: 0

Views: 60

Answers (2)

damoiser
damoiser

Reputation: 6238

As G. Blake Meike suggests, I think too that when you run make, it executes a copy of the original makefile. Then if your remote repo updates the local make, with a git pull, the new changes do not affect the current process.

Just to give you a possible workaround, you could try the following:

on current local run make:

 default:
   git clone remote_repo to_tmp_dir
   cd to_tmp_dir && make app
   # rm tmp_app
 app:
   # compile your app

With this pseudo code you should ever work with the last version of your app.

The disadvantage is that you clone every time (you loose time), even if you don't have changes on your remote repo.

Upvotes: 0

G. Blake Meike
G. Blake Meike

Reputation: 6715

Make holds a copy of your makefile open. That copy will not be replaced, if git replaces makefile in the project directory.

That said, it seems like a very weird thing to do.

Upvotes: 1

Related Questions