gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > needing to "make clean" too often

#65033 - keldon - Thu Dec 29, 2005 6:26 pm

I keep having weird things happen in my code which are solved only by running 'make clean'. Problem is that I am not changing anything out of the ordinary when this is happening. No changes in header files or extra header files included. It is mostly just small changes in some lines of code.

I have to do this for windows development every now and then after changes to header files but this is happening far too often. Is there any known reason for this.

#65037 - Peter - Thu Dec 29, 2005 7:53 pm

I guess you can fix it by using header dependencies. I did experience something similar and fixed it with when I enabled header dependencies.

#65042 - keldon - Thu Dec 29, 2005 9:14 pm

Would that involve having the headers compiled by themselves too? Could you give me a sample from your makefile?

#65102 - wintermute - Fri Dec 30, 2005 2:45 am

Have a look at the devkitPro makefiles included in the examples, they autogenerate dependencies during the build process.

#65118 - keldon - Fri Dec 30, 2005 10:32 am

Code:
define adjustdepends
cp $(DEPSDIR)/$*.d $(DEPSDIR)/$*.P;

sed -e 's/#.*//' -e 's/^[^:]*: \+//' -e 's/^ *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $(DEPSDIR)/$*.P >> $(DEPSDIR)/$*.d;
rm $(DEPSDIR)/$*.P
endef

Is this a regular expression which searches header files for header includes? And does this mean I need a .d file listing headers dependencies?

Also I am guessing that DEPSDIR is the directory to my dependency files.

#65125 - Touchstone - Fri Dec 30, 2005 1:48 pm

There's a parameter you can pass to the C compiler in GCC that'll make it preprocess your .c file and generate a list of all the header files that your source file is dependant on.
_________________
You can't beat our meat

#65135 - Peter - Fri Dec 30, 2005 4:05 pm

keldon wrote:
Could you give me a sample from your makefile?

I'm using DevKitPro, but not its makefile system. I use the makefile-system from HAM instead. Here is the line to enable header dependencies (hope I found the right one, heh):
Code:

ASFLAGS += -MD $(*D)/$(*F).d

#65143 - wintermute - Fri Dec 30, 2005 4:58 pm

keldon wrote:
Code:
define adjustdepends
cp $(DEPSDIR)/$*.d $(DEPSDIR)/$*.P;

sed -e 's/#.*//' -e 's/^[^:]*: \+//' -e 's/^ *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $(DEPSDIR)/$*.P >> $(DEPSDIR)/$*.d;
rm $(DEPSDIR)/$*.P
endef

Is this a regular expression which searches header files for header includes?


No, that expression parses the compiler generated dependency files and adds all the prerequisites as targets with no rules or prerequisites. This prevents errors when headers that are no longer used are deleted. See http://make.paulandlesley.org/autodep.html#norule

Quote:

And does this mean I need a .d file listing headers dependencies?


No, the dependency files are generated as part of the compile process.

Code:

#---------------------------------------------------------------------------------
%.o: %.cpp
   @echo $(notdir $<)
   @$(CXX) -MMD -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -c $< -o $@
   @$(adjustdepends)
   
#---------------------------------------------------------------------------------
%.o: %.c
   @echo $(notdir $<)
   @$(CC) -MMD -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@
   @$(adjustdepends)

#---------------------------------------------------------------------------------
%.o: %.s
   @echo $(notdir $<)
   $(CC) -MMD -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
   @$(adjustdepends)

#---------------------------------------------------------------------------------
%.o: %.S
   @echo $(notdir $<)
   @$(CC) -MMD -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
   @$(adjustdepends)



As it happens, the adjustdepends sed-fu is no longer required, gcc now provides the -MP option which does the same thing.

http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Preprocessor-Options.html#Preprocessor-Options


Quote:

Also I am guessing that DEPSDIR is the directory to my dependency files.


Yes, this is defined in the main Makefile, it defaults to $BUILD in the templates.

#65317 - keldon - Mon Jan 02, 2006 12:46 am

Thanks; I will look into this later in the week.