当只有一个.c文件发生变化时,Make正在重新构建整个项目



我写了下面的makefile:

CC = cxs12x
CFLAGS = +hcs -l +rev +fast +debug +sprec -pnp -gi -gsf -gdv -s -oc
SOURCES = MAIN.C vector.c can.c allegro3930.c regulatorctrl.c timer.c adc.c
SOURCESS2 = $(SOURCES:.c=.s)
SOURCESS = $(SOURCESS2:.C=.s)
OBJECTS2 = $(SOURCES:.c=.o)
OBJECTS = $(OBJECTS2:.C=.o)
AS = cas12x
AFLAGS = -l
ASOURCES = CRT0.asm
ASOURCESS = $(ASOURCES:.asm=.s)
AOBJECT = $(ASOURCES:.asm=.o)
OBJLIST = objlist.lkf
ORDEREDOBJLIST = bklist
LDFLAGS = 
LD = clnk
LINKERSCRIPT = lds12.lkf
TARGET = foo
$(TARGET).bin : $(TARGET)raw.bin
    cmd /c del $(TARGET).bin
    c:utilsencraesf $(TARGET)raw.bin $(TARGET).bin
$(TARGET)raw.bin : $(TARGET).mot
    del $(TARGET)raw.bin
    c:utilssrec2bin $(TARGET)raw.bin -K 256 -dFF -v 0 -s $(TARGET).mot
    c:utilsstamp $(TARGET)raw.bin 3dee0
$(TARGET).mot : $(TARGET).out
    cmd /c del $(TARGET).mot
    chex -s -f3 -o$(TARGET).s19 $(TARGET).out   #for cyclone
    chex -s -b0x7c0000 -f3 -o$(TARGET).mot $(TARGET).out
$(TARGET).out : $(OBJECTS) $(AOBJECT)
    cmd /c del $@
    $(LD) -o$@ -m$(TARGET).map $(LINKERSCRIPT)
    cvdwarf -v -loc $@
    cv695 -v $@
    clabs $@
$(AOBJECT) : $(ASOURCESS)
    $(AS) $(AFLAGS) $(ASOURCESS)
$(OBJECTS) : $(SOURCESS)
    $(AS) $(AFLAGS) $(SOURCESS)
$(ASOURCESS) : $(ASOURCES)
    copy $*.asm $*.s
$(SOURCESS) : $(SOURCES)
    $(CC) $(CFLAGS) $(SOURCES)
clean:
    cmd /c DEL /F /Q $(OBJECTS) $(AOBJECT) $(SOURCESS) $(ASOURCESS) $(ORDEREDOBJLIST) $(OBJECTS:.o=.ls) $(OBJECTS:.o=.la) $(AOBJECT:.o=.ls) $(AOBJECT:.o=.la) $(TARGET).bin $(TARGET)raw.bin $(TARGET).mot $(TARGET).out $(TARGET).s19 $(TARGET).map

我确信我在这个makefile中做事情的方式有很多问题(主要集中在我主要在所有命令中使用"文件列表"这一事实,而不是内置的自动变量($^等)。它按原样构建目标,但我遇到的主要问题是,它重新编译了所有先决条件,而不仅仅是那些自上次构建以来发生了更改的先决条件。我想把它转换为使用自动变量的先决条件,而不是我目前使用的"变量文件列表"方法(即$(SOURCES))。我也很乐意听到您在上述makefile中看到的任何其他问题!

我正在使用MINGW make,但我希望makefile可以在GNU, NMAKE等之间移植。

edit:输出如下所示(更改了一个文件- adc.c,您可以看到所有内容都被重新构建了…)

C:projectssvnecapFirmwareApplication>c:/mingw/bin/mingw32-make
cxs12x +hcs -l +rev +fast +debug +sprec -pnp -gi -gsf -gdv -s -oc MAIN.C vector.
c can.c allegro3930.c regulatorctrl.c timer.c adc.c
MAIN.C:
vector.c:
can.c:
allegro3930.c:
regulatorctrl.c:
timer.c:
adc.c:
cas12x -l MAIN.s vector.s can.s allegro3930.s regulatorctrl.s timer.s adc.s
cmd /c del foo.out
clnk -ofoo.out -mfoo.map lds12.lkf
cvdwarf -v -loc foo.out
Reading Debug Symbols ..
     For file: 9s12p128.h
     For file: adc.c
     For file: allegro3930.c
     For file: timer.c
     For file: regulatorctrl.c
     For file: can.c
     For file: MAIN.C
     For file: vector.c
Outputing HEADER PART
Outputing PROGRAM HEADER PART
Outputing IMAGE LOAD PART
Outputing SYMBOLS TABLE PART
Outputing IMAGE DEBUG PART
Outputing LINES INFO
     For file: vector.c
     For file: MAIN.C
     For file: can.c
     For file: regulatorctrl.c
     For file: timer.c
     For file: allegro3930.c
     For file: adc.c
Outputing DEBUG INFO
     For file: 9s12p128.h
Getting SPACE CODING
        for globals ...
        for functions ...
     For file: adc.c
Getting SPACE CODING
        for globals ...
        for functions ...
     For file: allegro3930.c
Getting SPACE CODING
        for globals ...
        for functions ...
     For file: timer.c
Getting SPACE CODING
        for globals ...
        for functions ...
     For file: regulatorctrl.c
Getting SPACE CODING
        for globals ...
        for functions ...
     For file: can.c
Getting SPACE CODING
        for globals ...
        for functions ...
     For file: MAIN.C
Getting SPACE CODING
        for globals ...
        for functions ...
     For file: vector.c
Getting SPACE CODING
        for globals ...
        for functions ...
Outputing DEBUG ABBREV
Outputing DEBUG LOCATION
Outputing DEBUG FRAME
Outputing STRING TABLE PART
Outputing SECTION NAME TABLE PART
Outputing SECTIONS TABLE PART
cv695 -v foo.out
Loading Line Information
          For file:        adc.c (file n° 1)
          For file:        allegro3930.c (file n° 2)
          For file:        timer.c (file n° 3)
          For file:        regulatorctrl.c (file n° 4)
          For file:        can.c (file n° 5)
          For file:        MAIN.C (file n° 6)
          For file:        vector.c (file n° 7)
Outputing HEADER PART
Outputing EXTENSION PART
Outputing ENVIRONMENT PART
Outputing SECTION PART
Outputing PUBLIC/EXTERNAL PART
Outputing IMAGE DEBUG PART
SOURCE FILE:9s12p128.h
        Registering types ...  for globals ...  for functions ...
                Outputing Globals
                Outputing line info
SOURCE FILE:adc.c
        Registering types ...  for globals ...  for functions ...
                Outputing Globals
                Outputing info for function tim4svc()
                Outputing info for function adcInit()
                Outputing line info
SOURCE FILE:allegro3930.c
        Registering types ...  for globals ...  for functions ...
                Outputing Globals
                Outputing info for function tim1svc()
                Outputing info for function tim3svc()
                Outputing info for function allegro3930UpdateDuty()
                Outputing info for function allegro3930Init()
                Outputing line info
SOURCE FILE:timer.c
        Registering types ...  for globals ...  for functions ...
                Outputing Globals
                Outputing info for function tosvc()
                Outputing info for function timerInit()
                Outputing line info
SOURCE FILE:regulatorctrl.c
        Registering types ...  for globals ...  for functions ...
                Outputing Globals
                Outputing info for function tim2svc()
                Outputing info for function regulatorCtrlStartZeroSpan()
                Outputing info for function regulatorCtrlDoZeroSpan()
                Outputing info for function regulatorCtrlDoPositionCtrl()
                Outputing info for function regulatorCtrlInit()
                Outputing info for function binSearch()
                Outputing info for function getFrac()
                Outputing info for function interp1d()
                Outputing line info
SOURCE FILE:can.c
        Registering types ...  for globals ...  for functions ...
                Outputing Globals
                Outputing info for function can0rxsvc()
                Outputing info for function tim0svc()
                Outputing info for function canInit()
                Outputing info for function txextmsg()
                Outputing line info
SOURCE FILE:MAIN.C
        Registering types ...  for globals ...  for functions ...
                Outputing Globals
                Outputing info for function main()
                Outputing info for function stopallints()
                Outputing info for function dummyf()
                Outputing line info
SOURCE FILE:vector.c
        Registering types ...  for globals ...  for functions ...
                Outputing Globals
                Outputing info for function unusedv()
                Outputing line info
Outputing IMAGE LOAD PART
clabs foo.out
cmd /c del foo.mot
chex -s -f3 -ofoo.s19 foo.out   #for cyclone
chex -s -b0x7c0000 -f3 -ofoo.mot foo.out
del fooraw.bin
c:utilssrec2bin fooraw.bin -K 256 -dFF -v 0 -s foo.mot
c:utilsstamp fooraw.bin 3dee0
Writing date stamp at 0003dee0
Date Stamp:  2014.07.05 17:17:56
cmd /c del foo.bin
c:utilsencraesf fooraw.bin foo.bin

基本问题是这样的规则:

$(SOURCESS) : $(SOURCES)
    $(CC) $(CFLAGS) $(SOURCES)

因此 SOURCES的所有成员是 SOURCESS的所有成员的先决条件;更改一个文件,例如vector.c, Make认为所有的目标(MAIN.s vector.s can.s allegro3930.s regulatorctrl.s timer.s adc.s)都过期了,需要重新构建。

我建议一个更严格的规则,就像这样:

%.s : %.c
    $(CC) $(CFLAGS) $<

请注意这可能不像写的那样工作,因为您使用的是MINGW Make,并且您在一个源文件中使用"。c",而在其他源文件中使用"。c"(我相信您有您的原因)。你还在玩汇编程序。所以我不能测试这个解决方案,我只能指出问题

最新更新