Makefiles 链是一团糟:没有规则来制作目标
Posted
技术标签:
【中文标题】Makefiles 链是一团糟:没有规则来制作目标【英文标题】:Chain of Makefiles are a mess: no rule to make target 【发布时间】:2017-06-14 11:42:55 【问题描述】:在一个转换项目中,我修改并重新修改了现有的 makefile 链,但设法破坏了它。 当我为一个没有 Contiki 的 AVR 项目和一个有(以及顶部的一些扩展)的 AVR 项目进行编译时,makefile 需要遵循不同的链。 一个没有工作,一个不再工作,因为它还需要考虑 Contiki 的 makefile。 我会尽量做到完整,但会省略不必要的细节。
使用 /CerberOS/uJ/Build/ 的终端,我执行以下命令:
make cerberos CLASSES=Test_NodeToNode Location= OS=PERIPHERAL
并在最后给出以下信息:
make[2]: *** No rule to make target 'blank.u'. Stop.
make[2]: Leaving directory '/home/sven/git/uJVM_PhD_Project/CerberOS/uJ/build'
../../UPNP/micropnp-contiki/build/Makefile_cerberos.include:159: recipe for target 'flash' failed
make[1]: *** [flash] Error 2
make[1]: Leaving directory '/home/sven/git/uJVM_PhD_Project/CerberOS/uJ/build'
Makefile:41: recipe for target 'cerberos' failed
我的目录结构是这样的:
/CerberOS/
-> /uJ/
---> /build/
-------> Makefile
-------> Makefile.target
-> /UPNP/
--->/contiki/
--------> Makefile.include
---> /micropnp/
--------> Makefile_cerberos.local
-------->/build/
-------------->Makefile_cerberos.include
-------->/cpu/
-------------->/avr/
--------------------> Makefile.avr
Makefile.target 只包含“TARGET = avr-micropnp Makefile如下:
BUILDENV_JAVA = $(ROOT)/../uJ/buildenv_java/RT/
SRV = $(ROOT)/../uJ/Services/
CCVT ?= $(ROOT)/../classCvt/classCvt
TOBIN ?= $(ROOT)/../classCvt/tobinOTA
CMD = $(TOBIN) -c $(CCVT)
# By default, uJ is assumed to be in the same parent folder as uPnP
ROOT = ../..
ifndef UJ
UJ = $(ROOT)/uJ
endif
# OS possibilities: UPNP (ID=0), PERIPHERAL (ID=1)
ifndef OS
OS = UPNP
endif
ifeq ($(OS), UPNP)
CFLAGS += -DOS_ID=0
else ifeq ($(OS), PERIPHERAL)
CFLAGS += -DOS_ID=1
else
endif
ifeq ($(TARGET),)
-include Makefile.target
ifeq ($(TARGET),)
$info TARGET not defined, using target 'native'
TARGET=native
else
$info using saved target '$(TARGET)'
endif
endif
cerberos: clean clean_uj __code.c
make flash
$(info BUILDENV_JAVA is $(BUILDENV_JAVA))
$(info OS is $(OS))
include ../Makefile_uj.include
ifeq ($(OS), UPNP)
$(info Building as uPNP Platform)
include ../../UPNP/micropnp-contiki/build/Makefile_cerberos.include
else ifeq ($(OS), PERIPHERAL)
$(info Building as periperal)
include ../Makefile_peripheral.include
else
$(info Including nothing)
endif
Makefile_cerberos.include 是:
$(info XXXXXXXXXXXXXXXXXXXXXXXX Starting Makefile_cerberos.include XXXXXXXXXXXXXXXXXXXXXXXX)
UPNP = $(ROOT)/UPNP/micropnp-contiki
CONTIKI_PROJECT = blank
# Duplicated from Contiki's Makefile. Necessary because we need the
# $TARGET var set earlier, and Contiki's Makefile is only included
# last minute.
ifeq ($(TARGET),)
-include Makefile.target
ifeq ($(TARGET),)
$info TARGET not defined, using target 'native'
TARGET=native
else
$info using saved target '$(TARGET)'
endif
endif
# Allow uPnP wide local settings to be defined in a seperate Makefile
include $(UPNP)/Makefile_cerberos.local
# This enables -ffunction-sections and -fdata-sections, and splits each
# .text and .data section in the object-files in subsections for each function.
# Next, the linker is instructed to garbage collect unused variables and
# functions. The result of this is smaller files, but functions not called in
# the core image will not be available for OTA deployed services.
SMALL=1
# Disable netstacks, except for IPv6 which is used for address parsing
CONTIKI_WITH_IPV6=1
CONTIKI_WITH_IPV4=0
CONTIKI_WITH_RPL=0
# Specify project-conf file (for Contiki settings specific to uPnP)
CFLAGS += -DPROJECT_CONF_H=\"upnp-conf.h\" -fshort-enums
######################################################################
# Setting a few defaults, customizable in Makefile.local
######################################################################
# By default, Contiki is assumed to be in the same parent folder as uPnP
ifndef CONTIKI
CONTIKI = $(ROOT)/UPNP/contiki
endif
### UPNP UJ SVEN
APPDIRS += $(UPNP)/apps
APPS += er-coap rest-engine
######################################################################
# Including source files/directories
######################################################################
# uPnP Core sourcefiles/dirs
#PROJECT_SOURCEFILES += upnp.c vector.c twi_master.c rd-client.c controller.c \
hal.c buzzer.c pir-sensor.c temp-sensor.c relay-switch.c\
lamp.c accelerometer.c loudness-sensor.c rfid.c light-sensor.c\
battery_varta.c thermocouple.c
# Reduced set
PROJECT_SOURCEFILES += upnp.c vector.c twi_master.c rd-client.c controller.c \
hal.c buzzer.c pir-sensor.c temp-sensor.c relay-switch.c\
loudness-sensor.c
PROJECTDIRS += $(UPNP) \
$(UPNP)/lib \
$(UPNP)/drivers/
MCU=atmega1284p
### Compiler definitions
CC = avr-gcc
LD = avr-gcc
AS = avr-as
AR = avr-ar
ELF_SIZE = avr-size -C --mcu=$(MCU)
OBJCOPY = avr-objcopy
STRIP = avr-strip
AVRDUDE = avrdude
OPTI = s
CFLAGS += -Wall -mmcu=$(MCU) -gdwarf-2 -fno-strict-aliasing -O$(OPTI)
ASFLAGS += -mmcu=$(MCU)
LDFLAGS += -mmcu=$(MCU) -Wl,-Map=contiki-$(TARGET).map \
-Wl,--section-start=.bootloader=$(BOOTLOADER_START)
MCU=atmega1284p
# Bootsection start address (byte address!) for linker. Fuses are
# set to the second smallest bootsection (1024 bytes) starting on 0xFC00
# (word address) //TODO see if we can bring this down again!
BOOTLOADER_START=0x1F800
# Avrdude settings
AVRDUDE_PROGRAMMER=atmelice_isp
AVRDUDE_MCU=m1284p
AVRDUDE_OPTIONS=-B 1
### These flags help significantly reduce the code size
ifeq ($(SMALL),1)
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
LDFLAGS += -Wl,--gc-sections
endif # SMALL
### Upload image to MCU
#Let avrdude use defaults if options not defined
ifdef AVRDUDE_PORT
AVRDUDE_PORT:=-P $(AVRDUDE_PORT)
endif
ifdef AVRDUDE_PROGRAMMER
AVRDUDE_PROGRAMMER:=-c $(AVRDUDE_PROGRAMMER)
endif
ifdef AVRDUDE_MCU
AVRDUDE_MCU:=-p $(AVRDUDE_MCU)
endif
SOURCES=$(wildcard *.c $(PROJECT_SOURCEFILES)/*.c)
SOURCES=$(wildcard *_avr.S $(PROJECT_SOURCEFILES)/*_avr.S)
OBJECTS=$(PROJECT_SOURCEFILES:.c=.o)
OBJECTS=$(PROJECT_SOURCEFILES:_avr.S=.o)
HEADERS=$(PROJECT_SOURCEFILES:.c=.h)
HEADERS=$(PROJECT_SOURCEFILES:_avr.S=.h)
### Compilation rules
#Use all standard contiki compile rules, except add .elf rule that prints size
%.elf: %.$(TARGET)
cp $< $@
$(ELF_SIZE) $@
#Prepare images from ELF
%.fuses.bin: %.$(TARGET)
$(OBJCOPY) $< -j .fuse -O binary --change-section-lma .fuse=0 $@
%.eep: %.$(TARGET)
$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex $^ $@
%.hex: %.$(TARGET)
$(OBJCOPY) $^ -j .text -j .data -j .bootloader -O ihex $@
#Flash targets
%.fu: %.fuses.bin
$(eval LFUSE = $(shell od -A none --format=x1 --read-bytes=1 $<))
$(eval HFUSE = $(shell od -A none --format=x1 --read-bytes=1 -j1 $<))
$(eval EFUSE = $(shell od -A none --format=x1 --read-bytes=1 -j2 $<))
$(AVRDUDE) $(AVRDUDE_MCU) -B 4 $(AVRDUDE_PORT) $(AVRDUDE_PROGRAMMER) \
-U lfuse:w:0x$(LFUSE):m -U hfuse:w:0x$(HFUSE):m -U efuse:w:0x$(EFUSE):m
%.u: %.hex
$(AVRDUDE) $(AVRDUDE_MCU) $(AVRDUDE_OPTIONS) $(AVRDUDE_PORT) $(AVRDUDE_PROGRAMMER) -U flash:w:$<
%.eu: %.eep
$(AVRDUDE) $(AVRDUDE_MCU) $AVRDUDE_OPTIONS $AVRDUDE_PORT $AVRDUDE_PROGRAMMER -U eeprom:w:$<
flash:
make blank.u
# Include uPnP specific platform files
include $(UPNP)/platform/$(TARGET)/Makefile.early.$(TARGET)
# Include Contiki
include $(CONTIKI)/Makefile.include
# Party overrides compilation rules of Contiki with uPnP specific rules for target platform
include $(UPNP)/platform/$(TARGET)/Makefile.$(TARGET)
按照我的理解,没有找到将target设为blank.u的规则是没有意义的。 其他 makefile 也可以,但我已将它们添加到 pastebin。 Makefile_cerberos.local 见https://pastebin.com/nT4TmwPY
对于 Makefile.avr(包含在 $(UPNP)/platform/makefiles 中):https://pastebin.com/SKz2FmjP
还有 Makefile.include:https://pastebin.com/NACUiv4Q
我很茫然。 有人可以帮忙吗?
【问题讨论】:
【参考方案1】:通过查看您的 makefile:
%.hex: %.$(TARGET)
$(OBJCOPY) $^ -j .text -j .data -j .bootloader -O ihex $@
%.u: %.hex
$(AVRDUDE) $(AVRDUDE_MCU) $(AVRDUDE_OPTIONS) $(AVRDUDE_PORT) $(AVRDUDE_PROGRAMMER) -U flash:w:$<
flash:
make blank.u
所以flash
依赖于blank.u
,而blank.u
可以 依赖于静态模式规则%.u: %.hex
,这可能依赖于静态模式规则%.hex: %.$(TARGET)
- 但如果@ 987654329@ 不存在,然后 Make(正确地)决定它没有规则来制作 blank.u
,并且它失败并出现您提到的错误。
我注意到您的*** Makefile 设置 TARGET
如果未定义:
ifeq ($(TARGET),)
$info TARGET not defined, using target 'native'
TARGET=native
但是,我没有看到您将TARGET
导出到子制作流程的任何地方。最简单的方法是在设置 TARGET 之后将 export TARGET
添加到您的*** makefile。 GNU Make Manual 有更多详细信息。
顺便说一句,每当您从 makefile 中调用 make 时,您都应该这样做
$(MAKE) blank.u
而不是
make blank.u
即使您使用非标准二进制名称,这也可以确保正确调用 Make,并为不同的命令行参数添加一些额外的处理。同样,GNU Make Manual 有详细信息。
【讨论】:
谢谢,这有点帮助。不过,我发现了一些奇怪的东西:只需删除 Makefile_cerberos.include 中的 flash: 规则,就可以运行完整的 make 进程并编译工作的二进制映像。 AVRDUDE没有使用这个图像,大概是因为没有命令。不过这很奇怪。有什么线索吗? @Sven - 如果你只是运行make
,那么 Make 应该运行它找到的第一个目标,我假设它是 flash
。删除它应该使它找到下一个目标是什么(从你发布的文件中不清楚它是什么)。以上是关于Makefiles 链是一团糟:没有规则来制作目标的主要内容,如果未能解决你的问题,请参考以下文章
*** 没有规则来制作目标 `src/main/jni/Build.config'。停止