You are not logged in.

#1 2005-04-23 17:29:06

shaurz
Member
From: Leeds, UK
Registered: 2004-02-02
Posts: 334
Website

Make and Directories

Is there a way to tell Make to ignore the timestamps of specific files (so that simply by existing they are 'up to date')? Alternatively, is there a command to alter the timestamp of a file?

The reason I ask is that I am using Make to re-create my build directories (which I prefer to keep seperate from source) when they are needed. Unfortunately, when some unrelated object is rebuilt, the build directory's timestamp is updated too, and because other targets depend on the directory, they are rebuilt unnecessarily. This sometimes leads to weird results.

Offline

#2 2005-04-23 18:32:50

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: Make and Directories

1) Fix your Makefile. Either you depend on a directory, or not. Being lazy and using it instead of the files within it is wrong.

2) See touch(1).

Offline

#3 2005-04-23 19:44:03

shaurz
Member
From: Leeds, UK
Registered: 2004-02-02
Posts: 334
Website

Re: Make and Directories

I'm not sure I explained this correctly. I'll try again.

I have something like this:

$(TARGETDIR) :
    @mkdir -p $@

$(TARGET) : $(TARGETDIR) $(OBJECTS)
    @echo " DSO    $(TARGET)"
    @gcc -shared $(LINKAGE) -o$(TARGET) $(OBJECTS)

$(TARGETDIR) is actually ./bin, where all the final binaries/libraries go. If I remake program X, it updates the ./bin directory's timestamp. When I run make again it procedes to relink all the other programs, even though I have not modified anything.

Of course everything works fine removing the directory as a dependency. I could just make sure the directories are always there and won't be deleted, but I'd really like this to work since it is a much nicer way.

I just looked at touch's man page. To be honest I didn't know it could set any time. I'll try that.

Offline

#4 2005-04-23 20:31:57

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,615
Website

Re: Make and Directories

instead of using mkdir, try using 'install -D" to place the final binaries. See if that changes anything.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#5 2005-04-23 20:36:59

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: Make and Directories

Why not just use install with the -D option? Or just always call mkdir -p, even easier and clearer than the extra rule.

I guess the problem is that the mtime of the dir changeswhen you put files in it. The next time you run make it will think it's newer than TARGET and will rebuild everything.

Offline

#6 2005-04-23 21:06:02

shaurz
Member
From: Leeds, UK
Registered: 2004-02-02
Posts: 334
Website

Re: Make and Directories

i3839 wrote:

...Or just always call mkdir -p, even easier and clearer than the extra rule.

Great idea. It works well, cheers!

It seems so obvious now. No more will I have directories as dependencies (phew).

Offline

#7 2005-04-23 21:20:58

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: Make and Directories

If stuck, always go for the easiest and cleanest solution, often that is the best one. If that solution makes things more ugly, then go fix things higher up the trouble chain.

Offline

Board footer

Powered by FluxBB