我写了以下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:\utils\encraesf $(TARGET)raw.bin $(TARGET).bin
$(TARGET)raw.bin : $(TARGET).mot
del $(TARGET)raw.bin
c:\utils\srec2bin $(TARGET)raw.bin -K 256 -dFF -v 0 -s $(TARGET).mot
c:\utils\stamp $(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中做事的方式有很多问题(主要是因为我主要使用'文件列表'在所有命令中,而不是内置的自动vartiables($^
等)。它按原样构建目标,但我遇到的主要问题是它重新编译所有先决条件而不是只是那些自上次构建以来发生了变化的人。我希望将此转换为使用自动变量作为先决条件,而不是变量'方法中的文件列表。 #39;我目前正在使用(即$(SOURCES)
)。我很高兴听到您在上面的makefile中看到的任何其他问题!
我使用MINGW make,但我希望makefile可以在GNU,NMAKE等之间移植。
编辑:输出如下所示(单个文件已更改 - adc.c,您可以看到所有内容都已重建...)
C:\projects\svn\ecap\Firmware\Application>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:\utils\srec2bin fooraw.bin -K 256 -dFF -v 0 -s foo.mot
c:\utils\stamp fooraw.bin 3dee0
Writing date stamp at 0003dee0
Date Stamp: 2014.07.05 17:17:56
cmd /c del foo.bin
c:\utils\encraesf fooraw.bin foo.bin
答案 0 :(得分:2)
基本问题是这样的规则:
$(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”则用于其他文件(我确定)你有理由)。你也在玩汇编程序。所以我无法测试这个解决方案,我只能指出问题所在。