diff --git a/Makefile b/Makefile index 6e1620d8..94c6f595 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ # (at your option) any later version. # # This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of + # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # @@ -137,7 +137,7 @@ clean:: %.d: %.c $(CC) -M -MG $(CFLAGS) $< | \ sed -e 's@^\(.*\)\.o:@$*.d $*.o Makefile '`dirname $*.d`/Module.mk':@' > $@ - + # This is tricky, but it works like a charm. It needs lots of utilities # though: cut, find, gzip, ln, tail and tar. @@ -159,3 +159,15 @@ version: echo '#define LM_DATE "'`date +'%Y%m%d'`\" > version.h echo -n 'Version: '; \ echo '#define LM_VERSION "'`read VER; echo $$VER`\" >> version.h + +# .ro files are used for programs (as opposed to modules) +%.ro: %.c + $(CC) $(EXCFLAGS) -c $< -o $@ + +%: %.ro + $(CC) $(EXLDFLAGS) -o $@ $^ + +%.rd: %.c + $(CC) -M -MG $(CFLAGS) $< | \ + sed -e 's@^\(.*\)\.o:@$*.rd $*.ro Makefile '`dirname $*.rd`/Module.mk':@' > $@ + diff --git a/doc/makefiles b/doc/makefiles index 67508065..87c81fe9 100644 --- a/doc/makefiles +++ b/doc/makefiles @@ -50,5 +50,16 @@ ones for developers: Set to 1 to enable any debugging code. Note that debugging code should only output more information, and never make the code mis-behave. +Several files are generated by Makefiles: + * .d + Dependency files for modules. Automatically generated. + * .rd + Dependency files for executables. Automatically generated. + * .ro + Object files for executables. They will be linked together to create + the executable. This extension is used to distinguish them from + modules (which end on .o). Also, using a different extensions makes + the Makefile fragments much simpler. + There are lots of comments within the main Makefile. Please read them if you want to know more. diff --git a/i2c/eeprom/Module.mk b/i2c/eeprom/Module.mk index bc198ec7..7fa08dea 100644 --- a/i2c/eeprom/Module.mk +++ b/i2c/eeprom/Module.mk @@ -25,8 +25,9 @@ MODULE_DIR := i2c/eeprom I2CEEPROMTARGETS := $(MODULE_DIR)/eeprom I2CEEPROMSOURCES := $(MODULE_DIR)/eeprom.c -# Include all dependency files -INCLUDEFILES += $(I2CEEPROMSOURCES:.c=.d) +# Include all dependency files. We use '.rd' to indicate this will create +# executables. +INCLUDEFILES += $(I2CEEPROMSOURCES:.c=.rd) all-i2c-eeprom: $(I2CEEPROMTARGETS) all :: all-i2c-eeprom @@ -37,19 +38,3 @@ clean-i2c-eeprom: $(RM) $(I2CEEPROMSOURCES:.c=.d) $(I2CEEPROMSOURCES:.c=.o) \ $(I2CEEPROMTARGETS) clean :: clean-i2c-eeprom - -# The targets -$(MODULE_DIR)/eeprom: $(MODULE_DIR)/eeprom.o - - -# Oops, we need to use EXCFLAGS instead of CFLAGS... And we have to deal with -# an executable. Ugly code approaching... :-) - -$(I2CEEPROMSOURCES:.c=.o): - $(CC) $(EXCFLAGS) -c $(@:.o=.c) -o $@ - -$(I2CEEPROMSOURCES:.c=.d): - $(CC) -M -MG $(EXCFLAGS) $(@:.d=.c) | \ - sed -e \ - 's@^\(.*\)\.o:@$@ $(@:.d=.o) Makefile '`dirname $@`/Module.mk':@' > $@ -