I want to add header file dependency in make file
I written rule
${OBJECTDIR}/%.o: %.cc %.h
gcc $(WarningLevel) $(CFLAGS) $(INCLUDES) -c -o $@ $^
but there are two error
One for .cc file which don't have any .h files . It will give no rule to make. Second one is the object file build by rule give error at linking
file format not recognized; treating as linker script
how can I achieve that ? (source file should be compile if header file is got modified )
$(wildcard %.h)will not work since functions are expanded before matching (I got bitten by this several times). You could 1) use something based on$(shell find ...),define,$(foreach)and$(eval)but this is tricky, 2) use gcc's-Moption family to generate dependencies for you. I usually go for the second one but I'm at work and I don't have an example right now for you.\tgcc <STUFF>ie a tab character in-front of gcc.