2014-04-26 73 views
-2

任何知道makefiles的人都可以帮我解决这个问题吗?我没有写,而且还有很多我以前从未见过的东西。需要Makefile专家

#--------------------------------------------------------------------------------- 
# Clear the implicit built in rules 
#--------------------------------------------------------------------------------- 
.SUFFIXES: 
#--------------------------------------------------------------------------------- 
ifeq ($(strip $(DEVKITARM)),) 
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM) 
endif 

include $(DEVKITARM)/gba_rules 

#--------------------------------------------------------------------------------- 
# TARGET is the name of the output, if this ends with _mb a multiboot image is generated 
# BUILD is the directory where object files & intermediate files will be placed 
# SOURCES is a list of directories containing source code 
# DATA is a list of directories containing data files 
# INCLUDES is a list of directories containing header files 
#--------------------------------------------------------------------------------- 
TARGET  := $(shell basename $(CURDIR)) 
BUILD  := build 
SOURCES  := source 
DATA  := 
GRAPHICS := gfx 
INCLUDES := 

#--------------------------------------------------------------------------------- 
# options for code generation 
#--------------------------------------------------------------------------------- 
ARCH := -mthumb -mthumb-interwork 

CFLAGS := -g -Wall -O3\ 
     -mcpu=arm7tdmi -mtune=arm7tdmi\ 
     -fomit-frame-pointer\ 
     -ffast-math \ 
     $(ARCH) 

CFLAGS += $(INCLUDE) 

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 

ASFLAGS := $(ARCH) 
LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir [email protected]).map 

#--------------------------------------------------------------------------------- 
# any extra libraries we wish to link with the project 
#--------------------------------------------------------------------------------- 
LIBS := -lgba 

#--------------------------------------------------------------------------------- 
# list of directories containing libraries, this must be the top level containing 
# include and lib 
#--------------------------------------------------------------------------------- 
LIBDIRS := $(LIBGBA) 

#--------------------------------------------------------------------------------- 
# no real need to edit anything past this point unless you need to add additional 
# rules for different file extensions 
#--------------------------------------------------------------------------------- 
ifneq ($(BUILD),$(notdir $(CURDIR))) 
#--------------------------------------------------------------------------------- 

export OUTPUT := $(CURDIR)/$(TARGET) 
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 
      $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 

export DEPSDIR := $(CURDIR)/$(BUILD) 

#--------------------------------------------------------------------------------- 
# automatically build a list of object files for our project 
#--------------------------------------------------------------------------------- 
CFILES  := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 
SFILES  := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 
BMPFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.bmp))) 

#--------------------------------------------------------------------------------- 
# use CXX for linking C++ projects, CC for standard C 
#--------------------------------------------------------------------------------- 
ifeq ($(strip $(CPPFILES)),) 
#--------------------------------------------------------------------------------- 
    export LD := $(CC) 
#--------------------------------------------------------------------------------- 
else 
#--------------------------------------------------------------------------------- 
    export LD := $(CXX) 
#--------------------------------------------------------------------------------- 
endif 
#--------------------------------------------------------------------------------- 

export OFILES := $(addsuffix .o,$(BINFILES)) \ 
        $(BMPFILES:.bmp=.o) \ 
        $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 

#--------------------------------------------------------------------------------- 
# build a list of include paths 
#--------------------------------------------------------------------------------- 
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 
      $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 
      -I$(CURDIR)/$(BUILD) 

#--------------------------------------------------------------------------------- 
# build a list of library paths 
#--------------------------------------------------------------------------------- 
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 

.PHONY: $(BUILD) clean 

#--------------------------------------------------------------------------------- 
$(BUILD): 
    @[ -d [email protected] ] || mkdir -p [email protected] 
    @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 

all : $(BUILD) 
#--------------------------------------------------------------------------------- 
clean: 
    @echo clean ... 
    @rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba 

#--------------------------------------------------------------------------------- 
else 

DEPENDS := $(OFILES:.o=.d) 

#--------------------------------------------------------------------------------- 
# main targets 
#--------------------------------------------------------------------------------- 
$(OUTPUT).gba : $(OUTPUT).elf 

$(OUTPUT).elf : $(OFILES) 


#--------------------------------------------------------------------------------- 
# The bin2o rule should be copied and modified 
# for each extension used in the data directories 
#--------------------------------------------------------------------------------- 

#--------------------------------------------------------------------------------- 
# This rule links in binary data with the .bin extension 
#--------------------------------------------------------------------------------- 
%.bin.o : %.bin 
#--------------------------------------------------------------------------------- 
    @echo $(notdir $<) 
    @$(bin2o) 

#--------------------------------------------------------------------------------- 
# This rule links in binary data with the .raw extension 
#--------------------------------------------------------------------------------- 
%.raw.o : %.raw 
#--------------------------------------------------------------------------------- 
    @echo $(notdir $<) 
    @$(bin2o) 

#--------------------------------------------------------------------------------- 
# This rule creates assembly source files using grit 
# grit takes an image file and a .grit describing how the file is to be processed 
# add additional rules like this for each image extension 
# you use in the graphics folders 
#--------------------------------------------------------------------------------- 
%.s %.h : %.bmp %.grit 
#--------------------------------------------------------------------------------- 
    grit $< -fts -o$* 

-include $(DEPENDS) 

#--------------------------------------------------------------------------------- 
endif 
#--------------------------------------------------------------------------------- 

我的问题是与make规则.bmp文件。在底部,你可以看到应该为/ gfx目录中的所有.bmp文件调用的规则(现在只有bg.bmp和bg.grit)。以前,我会得到错误“没有规则来制作bg.o所需的目标bg.s”,尽管对我而言,最后一条规则显然应该适用于所有.s文件。在删除整个/ build目录并再次尝试之后,我现在得到“没有规则使目标bg.o在2048年需要”

我可以验证手动运行砂砾(grit bg.bmp -fts -obg .s)在build文件夹中生成bg.s和bg.h文件。

+0

我希望你能想出一个更好的标题。这不是分类发布。 – devnull

回答

0

您可能需要将GRAPHICS目录添加到VPATH,这与您为SOURCESDATA所做的相同。否则,make会很难计算出你的bmp文件的位置,并且无法弄清楚如何制作相应的目标文件。

+0

工作就像一个魅力。很好,赶上,谢谢。 – user3391135