0

I wrote a makefile as given below:

.PHONY: clean_lib all

a: lib
        make $@.exe

c: lib
        make $@.exe

clean_lib:
        rm -f lib

all: a clean_lib c

When I call make all I would like the "a" target to build a lib and a.exe and after that "clean" that lib and then call "c". which would build again lib for "c" and build c.exe.

Here the a.exe and c.exe only builds if lib builds. The problem is that after "clean" the lib that I want to rebuild for "c" is not building, so c.exe cannot build.

Can anyone can help me?

1
  • Why have to clean lib in the middle? It should work without cleaning it. – LatinSuD Sep 9 '14 at 11:57
0

I can't understand why you need to clean lib in the middle. I think it should work without cleaning.

.PHONY: all

lib: somesource
        make lib

a: lib
        make $@.exe

c: lib
        make $@.exe

all: a c

Both a and c depend on lib. Whenever you want to build a, c or both lib will be built. Once it is built it shouldn't need to be built again unless its source code (somecode) is changed.

That's how makefiles work, they keep track of dependencies and only need to rebuild something if the thing they depend on has been modified more recently than the target.

4
  • but if the different lib is builds for a and c?\ – shiva Sep 10 '14 at 9:21
  • Then why not keep 2 copies of "lib" with 2 different names? – LatinSuD Sep 10 '14 at 15:55
  • i want to change a variable in each case builds the lib – shiva Sep 12 '14 at 5:43
  • Indeed, have 2 copies of "lib", called "lib1" and "lib2", each one with its own set of variables. – LatinSuD Sep 12 '14 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.