Makefiles链是一团糟:没有规则可以制定目标

时间:2017-06-14 11:42:55

标签: c makefile

在转换项目中,我修改并重新修改了现有的makefile链,但设法打破了它。 当我为没有Contiki的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)

根据我的理解,没有意义找不到使目标成为空白的规则。 其他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 个答案:

答案 0 :(得分: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) - 但如果blank.$(TARGET)不存在,那么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还有详细信息。