Search code examples
makefilefortrangfortranfortran77

A Makefile does not update objects


Even though I'm following the GNU make online manual step by step, a problem on makefiles still puzzles me.
I'm working on a very simple makefile:

OBJ = main.o funz.o

main :  $(OBJ)
    gfortran -g -o main $(OBJ)

funz.o : funz.for
    gfortran -g -c funz.for
main.o : main.for
    gfortran -g -c main.for

clean : 
    rm main.o funz.o

According to what I've learned on makefiles, funz.for is a prerequisite for funz.o. Everytime I change the source code funz.for, make should update funz.o and link it to main again. But whenever I launch make I get told that main is up to date and does not recognize the changes in funz.for. This question I've found is related to the same problem but doesn't solve mine, since I think my prerequisites are posed correctly.
Am I missing something?

UPDATE 1

As asked by Etan Reisner, here is the output of make -rRd:

This program built for x86_64-redhat-linux-gnu
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
 Considering target file `Makefile'.
  Looking for an implicit rule for `Makefile'.
  No implicit rule found for `Makefile'.
  Finished prerequisites of target file `Makefile'.
 No need to remake target `Makefile'.
Updating goal targets....
Considering target file `main'.
  Considering target file `main.o'.
    Considering target file `main.for'.
     Looking for an implicit rule for `main.for'.
     No implicit rule found for `main.for'.
     Finished prerequisites of target file `main.for'.
    No need to remake target `main.for'.
   Finished prerequisites of target file `main.o'.
   Prerequisite `main.for' is older than target `main.o'.
  No need to remake target `main.o'.
  Considering target file `funz.o'.
    Considering target file `funz.for'.
     Looking for an implicit rule for `funz.for'.
     No implicit rule found for `funz.for'.
     Finished prerequisites of target file `funz.for'.
    No need to remake target `funz.for'.
   Finished prerequisites of target file `funz.o'.
   Prerequisite `funz.for' is older than target `funz.o'.
  No need to remake target `funz.o'.
 Finished prerequisites of target file `main'.
 Prerequisite `main.o' is older than target `main'.
 Prerequisite `funz.o' is older than target `main'.
No need to remake target `main'.
make: `main' is up to date.

And here's the output of stat funz.o funz.for; touch funz.for; stat funz.o funz.for; make -rRd

  File: `funz.o'
  Size: 3176            Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d      Inode: 58197897    Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  505/ lorenzo)   Gid: (  505/ lorenzo)
Access: 2015-11-19 16:23:06.200737262 -0500
Modify: 2015-11-19 16:23:06.192737262 -0500
Change: 2015-11-19 16:23:06.192737262 -0500
  File: `funz.for'
  Size: 129             Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d      Inode: 58196947    Links: 1
Access: (0644/-rw-r--r--)  Uid: (  505/ lorenzo)   Gid: (  505/ lorenzo)
Access: 2015-11-19 16:23:06.183737262 -0500
Modify: 2015-11-19 16:23:06.174737262 -0500
Change: 2015-11-19 16:23:06.174737262 -0500
  File: `funz.o'
  Size: 3176            Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d      Inode: 58197897    Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  505/ lorenzo)   Gid: (  505/ lorenzo)
Access: 2015-11-19 16:23:06.200737262 -0500
Modify: 2015-11-19 16:23:06.192737262 -0500
Change: 2015-11-19 16:23:06.192737262 -0500
  File: `funz.for'
  Size: 129             Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d      Inode: 58196947    Links: 1
Access: (0644/-rw-r--r--)  Uid: (  505/ lorenzo)   Gid: (  505/ lorenzo)
Access: 2015-11-19 16:23:47.478737151 -0500
Modify: 2015-11-19 16:23:47.478737151 -0500
Change: 2015-11-19 16:23:47.478737151 -0500
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-redhat-linux-gnu
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
 Considering target file `Makefile'.
  Looking for an implicit rule for `Makefile'.
  No implicit rule found for `Makefile'.
  Finished prerequisites of target file `Makefile'.
 No need to remake target `Makefile'.
Updating goal targets....
Considering target file `main'.
  Considering target file `main.o'.
    Considering target file `main.for'.
     Looking for an implicit rule for `main.for'.
     No implicit rule found for `main.for'.
     Finished prerequisites of target file `main.for'.
    No need to remake target `main.for'.
   Finished prerequisites of target file `main.o'.
   Prerequisite `main.for' is older than target `main.o'.
  No need to remake target `main.o'.
  Considering target file `funz.o'.
    Considering target file `funz.for'.
     Looking for an implicit rule for `funz.for'.
     No implicit rule found for `funz.for'.
     Finished prerequisites of target file `funz.for'.
    No need to remake target `funz.for'.
   Finished prerequisites of target file `funz.o'.
   Prerequisite `funz.for' is newer than target `funz.o'.
  Must remake target `funz.o'.
gfortran -g -c funz.for
Putting child 0x0197ea80 (funz.o) PID 69914 on the chain.
Live child 0x0197ea80 (funz.o) PID 69914
Reaping winning child 0x0197ea80 PID 69914
Removing child 0x0197ea80 PID 69914 from chain.
  Successfully remade target file `funz.o'.
 Finished prerequisites of target file `main'.
 Prerequisite `main.o' is older than target `main'.
 Prerequisite `funz.o' is newer than target `main'.
Must remake target `main'.
gfortran -g -o main main.o funz.o
Putting child 0x019830d0 (main) PID 69917 on the chain.
Live child 0x019830d0 (main) PID 69917
Reaping winning child 0x019830d0 PID 69917
Removing child 0x019830d0 PID 69917 from chain.
Successfully remade target file `main'.

UPDATE 2

I noticed something really strange (which I always overlooked): I'm editing my source files through the WinSCP client, and it seems like, after updating my source files, the "last modified" time goes wrong. As you can see in this picture, even if I modified funz.for a few minutes ago, the shown time of its last change is unexplicably 6 hours before my actual time (it's almost 5 P.M. here).


Solution

  • It seems like the remote computer I am working with had a different time than the local computer, hence the different timestamps and the makefile not working.