tags:

views:

25

answers:

2

Hi,

in a Makefile, I have:

all: $(PROG)

$(PROG): $(CPP_OBJS)
        $(CPP_LD) $(CPP_LD_FLAGS) $(CPP_OBJS)  -o $(PROG)

I would like to add some script before the compilation so I tried:

all: $(PROG)

$(PROG): $(CPP_OBJS)
        sh script.sh ; $(CPP_LD) $(CPP_LD_FLAGS) $(CPP_OBJS)  -o $(PROG)

but it does not work.

What is the right way of running a script in this case before the compilation?

Thanks

+1  A: 

Put the script execution on a separate line.

$(PROG): $(CPP_OBJS)
        sh script.sh
        $(CPP_LD) $(CPP_LD_FLAGS) $(CPP_OBJS)  -o $(PROG)

This is because make is pretty stupid and doesn't understand semicolons in the way you want. Good thing that newlines are cheap!

Donal Fellows
A: 

I think you could just use multiple targets, but this won't run the script if $(PROG) is used instead of all as the target.

all: $(SCRIPT) $(PROG)

$(SCRIPT):
        sh myScript.sh

$(PROG): $(CPP_OBJS)
        $(CPP_LD) $(CPP_LD_FLAGS) $(CPP_OBJS)  -o $(PROG)

Otherwise, you could use separate lines, which would always be applied.

$(PROG): $(CPP_OBJS)
        sh myScript.sh
        $(CPP_LD) $(CPP_LD_FLAGS) $(CPP_OBJS)  -o $(PROG)
greglev