user2492270
user2492270

Reputation: 2285

Makefile that gives permission to my python script?

I have a python script named "myprogram.py" and a shell script named "myprogram" for running this

# "myprogram"

#!/bin/sh
python myprogram.py

I created this shell script because I wanted to run my program like this:

./myprogram arg1 arg2

However, when I do this, I get this "Permission Denied" error.

I know I need to type "chmod 755 myprogram" to grant permission, but I want to do this

in my makefile instead of making the user manually type chmod.

In other words, I want my makefile so that typing

./make

runs "chmod 755 myprogram"

Is there a way to do this?? What should the content of my makefile be?

Thanks

Upvotes: 3

Views: 7619

Answers (2)

Mark Galeck
Mark Galeck

Reputation: 6395

There is no point using Make to do this. Make is not designed for it. You should just issue the command chmod 755 myprogram yourself and bedone. This command can be ensapsulated in a script or alias, if you like, but not in a makefile, and you can then enter myprogram into your favourite version control system that preserves permissions, so that if you recreate it elsewhere, the permissions are set. Make is not the way to do it.

If you however must do it this way (because the boss says so for example), it would be incorrect to have all depend on myprogram. myprogram already exists and all has nothing to do with changes to the contents of myprogram or modification time thereof. It should be:

all:
    chmod 755 myprogram

Upvotes: 1

AAA
AAA

Reputation: 1384

Try putting something like this into Makefile:

all: myprogram
    chmod 755 myprogram

That registers myprogram as a dependency to the all target.

Note that the second line there should start with a hard tab character, not spaces, as Makefiles are very particular about indentation.

Regarding the shell script: there's two ways to write it.

python myprogram.py $1 $2

This will pass the first two arguments to the script through to the python program.

However, if you do

python myprogram.py $@

then all arguments passed to the shell script will be propagated through to the python program.

Upvotes: 5

Related Questions