Search code examples
makefile

Why is `make install` always being called?


This is my makefile:

ifeq ($(PREFIX),)
    PREFIX := /usr
endif

install: libriscy.so.1.0
    install -d $(DESTDIR)$(PREFIX)/lib/
    install -m 755 libriscy.so.1.0 $(DESTDIR)$(PREFIX)/lib/
    ln -s $(DESTDIR)$(PREFIX)/lib/libriscy.so.1.0 $(DESTDIR)$(PREFIX)/lib/libriscy.so
libriscy.so.1.0: riscy.o riscyA.o riscyinit.o
    ld -fpic --shared -o libriscy.so.1.0 riscy.o riscyA.o riscyinit.o -lc -ldl
riscy.o: riscy.c riscyvar.S
    gcc -c -fPIC riscy.c -o riscy.o
riscyA.o: riscy.S riscyvar.S
    as -c -fpic riscy.S -o riscyA.o
riscyinit.o: riscyinit.c
    gcc -c -g -fpic riscyinit.c -o riscyinit.o

And this is the current state of the directory:

adrian@starfive:~/riscyforth/riscylib$ ls -l
total 112
-rwxr-xr-x 1 adrian adrian 25680 Aug 25 18:16 libriscy.so.1.0
-rw-r--r-- 1 adrian adrian   558 Aug 25 18:05 makefile
-rw-r--r-- 1 adrian adrian 22426 Aug 24 17:41 riscy.S
-rw-r--r-- 1 adrian adrian  3549 Aug 24 17:41 riscy.c
-rw-r--r-- 1 adrian adrian  9560 Aug 24 17:54 riscy.o
-rw-r--r-- 1 adrian adrian 13440 Aug 24 17:54 riscyA.o
-rw-r--r-- 1 adrian adrian  1601 Aug 24 17:41 riscyinit.c
-rw-r--r-- 1 adrian adrian 15520 Aug 24 17:54 riscyinit.o
-rw-r--r-- 1 adrian adrian  1561 Aug 24 17:41 riscyvar.S

So why is make install being run on every invocation of make - when the dependency libriscy.so.1.0 exists?


Solution

  • I'm not sure I understand the question, but what a rule like this:

    foo: bar
            recipe
    

    means to make is, "if the file foo doesn't exist or is older than bar, then run the shell and give it recipe to update it".

    Since your rule for install never creates a file named install, the rule for the install target will always be considered "out of date" (because the file install does not exist) and so it will always be run.