Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,355 Views

Correction to Makefile

Hello, 

 

I have found projects that contain library dependencies always relink to create the final ELF file even if nothing has changed. Although this isn't wrong or bad, it does cause creation dates to be later than the actual project modifications made. This ELF update also causes unnecessary backups and shows a modified status in version control. 

 

I have found this to be caused from new Makefile changes that support tracking changed build configurations by copying the configuration output file to the base folder. This is done using: $(LIB) : $(ACTIVE_CONFIG_LIB) $(CP) $< $@ where $(CP) is CP := cp -f 

 

The problem is the copy (CP) is forced (-f). Adding a -p suppresses the unneeded copy on repeated builds of a target so it doesn't needlessly rewrite the ELF file. 

 

What I could not find out is where to edit this to add the -p other than modifying the Makefile manually. 

 

Hope this helps, 

Bill
0 Kudos
9 Replies
Altera_Forum
Honored Contributor I
60 Views

Adding -p just preserves the modification times, the copy will still happen. 

make should only be running the command if ${LIB} is older than ${ACTIVE_CONFIG_LIB} - so that should suppress the code when not needed. 

So something else funny must be going on, possibly another dependency line somewhere. 

 

What you might need is something that only updates the config file if it has actually changed - that needs to be done before the makefile above is run. 

 

Assigning to CP on the make command line and/or the environment should suppress the assignment in the makefle itself.
Altera_Forum
Honored Contributor I
60 Views

 

--- Quote Start ---  

Adding -p just preserves the modification times, the copy will still happen. 

--- Quote End ---  

 

Yes, true. I should have been clearer that the time-stamp remains the same and therefore dependencies on the lib(s) don't build unnecessarily. That was the point - to stop unnecessary builds and backups. 

 

 

--- Quote Start ---  

make should only be running the command if ${LIB} is older than ${ACTIVE_CONFIG_LIB} - so that should suppress the code when not needed. 

--- Quote End ---  

Which I don't understand because it's the same 2 targets of the CP. How could they be different if the LIB wasn't built? And it isn't because AR isn't run. I didn't understand the problem but still I wanted a solution. I'm obviously not a make expert. 

 

 

--- Quote Start ---  

So something else funny must be going on, possibly another dependency line somewhere. 

--- Quote End ---  

I agree 

 

 

--- Quote Start ---  

What you might need is something that only updates the config file if it has actually changed - that needs to be done before the makefile above is run. 

--- Quote End ---  

Rebuilds occur (because of the CP) even if the config isn't changed. With the -p it still works if the config *is* changed. Although I don't understand the failure the solution (work around) is sound. 

 

Thanks for replying, 

Bill
Altera_Forum
Honored Contributor I
60 Views

Try adding an 'echo xxx $*' line before the $(CP) $< $@ one. 

That will show all the dependencies.
Altera_Forum
Honored Contributor I
60 Views

 

--- Quote Start ---  

Try adding an 'echo xxx $*' line before the $(CP) $< $@ one. 

That will show all the dependencies. 

--- Quote End ---  

I have $(LIB) : $(ACTIVE_CONFIG_LIB) echo xxx $* echo $(LIB) echo $(ACTIVE_CONFIG_LIB) $(CP) $< $@ 

 

and get: 

 

echo xxx liblwip_altera_tse_FALCON 

xxx liblwip_altera_tse_FALCON 

echo liblwip_altera_tse_FALCON.a 

liblwip_altera_tse_FALCON.a 

echo obj/Release/liblwip_altera_tse_FALCON.a 

obj/Release/liblwip_altera_tse_FALCON.a 

cp -f -p obj/Release/liblwip_altera_tse_FALCON.a liblwip_altera_tse_FALCON.a 

 

And the time-stamps of $(LIB ) and $(ACTIVE_CONFIG) are identical. 

 

Thanks for your suggestion. I wouldn't mind knowing if I can do this without hand-modifying a makefile. 

 

Bill
Altera_Forum
Honored Contributor I
60 Views

Hmmmm .... I should have checked the manual! I've clearly not written enough makefiles recently. 

 

It seems I meant $^ not $*. 

Since the makefile is echoeing the commands, you could use : instead of echo
Altera_Forum
Honored Contributor I
60 Views

Now I get: 

 

xxx obj/Release/liblwip_altera_tse_FALCON.a 

liblwip_altera_tse_FALCON.a 

obj/Release/liblwip_altera_tse_FALCON.a 

cp -f -p obj/Release/liblwip_altera_tse_FALCON.a liblwip_altera_tse_FALCON.a 

 

(I changed to @echo). There seems to be something wrong with the time-stamp check between the source and target. The project is simply a "Create NIOS II Lib" with 3 source files with everything else auto-generated. 

 

Bill
Altera_Forum
Honored Contributor I
60 Views

I wonder what 'ls -l $@ $^' generates (just before the copy)? 

make (and I doubt gmake is very different) ends up checking the timestamps on everything twice, once at the start and again just before running each command. 

There might also be something odd about the way that definition file doesn't get updated when nothing changes - since I suspect it is rewritten. Getting that wrong could cause make to rebuild the following items. 

 

As I said earlier, you should be able to override the in-makefile assignment to $(CP) by putting it on the command line "make CP='cp -fp' xxxx", or maybe in the environment "CP='cp -fp' make xxx". 

 

Or look at $PATH and add the script file "cp" containing: 

#!/bin/sh /bin/cp -p "$@" 

in one of the first directories searched.
Altera_Forum
Honored Contributor I
60 Views

 

--- Quote Start ---  

I wonder what 'ls -l $@ $^' generates (just before the copy)? 

--- Quote End ---  

ls -l liblwip_altera_tse_FALCON.a obj/Release/liblwip_altera_tse_FALCON.a -rwxr-xr-x+ 1 xxxxxxxxx mkpasswd 138792 Oct 3 14:23 liblwip_altera_tse_FALCON.a -rwxr-xr-x+ 1 xxxxxxxxx mkpasswd 138792 Oct 3 14:23 obj/Release/liblwip_altera_tse_FALCON.a cp -f -p obj/Release/liblwip_altera_tse_FALCON.a liblwip_altera_tse_FALCON.a 

 

Looke like it *should* be working, no? 

 

I will try your other suggestions so as to not have to edit the Makefile, although I'm not sure when they regenerate. So far it never has. 

 

Thanks for your continued input. Although it's not a show-stopper it's one of those things that are good to know (and fix if we can). Eventually it helps everyone. 

 

Bill
Altera_Forum
Honored Contributor I
60 Views

Might be worth using 'ls --full_time $@ $<' one of the files might have a sub-second timestamp.

Reply