How do I add .o files to my makefile?

support for the ARM toolchain
Gamer2020
Posts: 8
Joined: Fri Sep 09, 2011 7:22 pm

How do I add .o files to my makefile?

Post by Gamer2020 » Sun Sep 18, 2011 12:38 am

I'm sorry to be a bother but I tried doing this and it didn't work right.

These are the contents of my makefile.

I would have put it in a spoiler but not sure if this site has that code.

Code: Select all

#
# Template for projects using grit.
# 
# Making gfx into a library in a separate makefile and using that here.
#

# ---------------------------------------------------------------------
# SETUP
# ---------------------------------------------------------------------

# --- No implicit rules ---
.SUFFIXES:

# --- Tonc paths ---
# If not defined as environment var, assumed to be C:\devkitPro\tonc-code\code
export TONCCODE	?= C:\devkitPro\tonc-code\code

include $(TONCCODE)/tonc_rules



# --- Main path ---
export PATH	:=	$(DEVKITARM)/bin:$(PATH)



# ---------------------------------------------------------------------
# PROJECT DETAILS
# ---------------------------------------------------------------------

# PROJ		: Base project name
# TITLE		: Title for ROM header (12 characters)
# LIBS		: Libraries to use, formatted as list for linker flags
# BUILD		: Directory for build process temporaries. Should NOT be empty!
# SRCDIRS	: List of source file directories
# DATADIRS	: List of data file directories
# INCDIRS	: List of header file directories
# LIBDIRS	: List of library directories
# General note: use . for the current dir, don't leave them empty.

export PROJ	?= $(notdir $(CURDIR))
TITLE		:= test
GFXLIBS		:= libgfx.a

LIBS		:= -ltonc -lgfx

BUILD		:= build
SRCDIRS		:= startup fonts key_demo
DATADIRS	:= data
INCDIRS		:= include fonts
LIBDIRS		:= $(TONCCODE)/tonclib
SOUND_DIR = sound/
SOUND_FILES = $(SOUND_DIR)m4aLib.o $(SOUND_DIR)SoundDat.o $(SOUND_DIR)gun.o $(SOUND_DIR)se3.o $(SOUND_DIR)se5.o \
	$(SOUND_DIR)se8.o $(SOUND_DIR)se9b.o $(SOUND_DIR)flutec4.o $(SOUND_DIR)suboscc3.o $(SOUND_DIR)orgc3.o \
	$(SOUND_DIR)synbsc2.o $(SOUND_DIR)brassc3.o $(SOUND_DIR)mutetpc4.o $(SOUND_DIR)cutgtg3.o $(SOUND_DIR)sawg3.o \
	$(SOUND_DIR)sinec3.o $(SOUND_DIR)revcym.o $(SOUND_DIR)engin01a.o $(SOUND_DIR)housebd.o $(SOUND_DIR)housesd.o \
	$(SOUND_DIR)housechh.o $(SOUND_DIR)houseohh.o $(SOUND_DIR)tamba.o $(SOUND_DIR)vibra.o $(SOUND_DIR)timbale.o \
	$(SOUND_DIR)harpc3.o $(SOUND_DIR)harpc5.o $(SOUND_DIR)se_d01.o $(SOUND_DIR)se_dbend.o $(SOUND_DIR)se_dvib.o \
	$(SOUND_DIR)se_gbend2.o $(SOUND_DIR)se_swep2.o $(SOUND_DIR)se_noise.o $(SOUND_DIR)sound3.o $(SOUND_DIR)se_dben2.o \
	$(SOUND_DIR)se_gbend.o $(SOUND_DIR)se_sweep.o $(SOUND_DIR)se_dgmix.o $(SOUND_DIR)agb2000.o $(SOUND_DIR)wario.o \
	$(SOUND_DIR)engin.o


# --- switches ---

bMB		:= 0	# Multiboot build
bTEMPS	:= 0	# Save gcc temporaries (.i and .s files)
bDEBUG2	:= 0	# Generate debug info (bDEBUG2? Not a full DEBUG flag. Yet)


# ---------------------------------------------------------------------
# BUILD FLAGS
# ---------------------------------------------------------------------

# This is probably where you can stop editing

# --- Architecture ---

ARCH    := -mthumb-interwork -mthumb
RARCH   := -mthumb-interwork -mthumb
IARCH   := -mthumb-interwork -marm -mlong-calls

# --- Main flags ---

CFLAGS	:= -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH) -O2
CFLAGS	+= -Wall
CFLAGS	+= $(INCLUDE)
CFLAGS	+= -ffast-math -fno-strict-aliasing

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

ASFLAGS	:= $(ARCH)
LDFLAGS := $(ARCH) -Wl,-Map,$(PROJ).map

# --- switched additions ----------------------------------------------

# --- Multiboot ? ---
ifeq ($(strip $(bMB)), 1)
	TARGET	:= $(PROJ).mb
else
	TARGET	:= $(PROJ)
endif
	
# --- Save temporary files ? ---
ifeq ($(strip $(bTEMPS)), 1)
	CFLAGS	+= -save-temps
endif

# --- Debug info ? ---

ifeq ($(strip $(bDEBUG2)), 1)
	CFLAGS	+= -g
	LDFLAGS	+= -g
endif


# ---------------------------------------------------------------------
# BUILD PROCEDURE
# ---------------------------------------------------------------------

ifneq ($(BUILD),$(notdir $(CURDIR)))

# Still in main dir: 
# * Define/export some extra variables
# * Invoke this file again from the build dir
# PONDER: what happens if BUILD == "" ?

export OUTPUT	:=	$(CURDIR)/$(TARGET)
export VPATH	:=									\
	$(foreach dir, $(SRCDIRS) , $(CURDIR)/$(dir))	\
	$(foreach dir, $(DATADIRS), $(CURDIR)/$(dir))   
	

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

# --- List source and data files ---

CFILES		:=	$(foreach dir, $(SRCDIRS) , $(notdir $(wildcard $(dir)/*.c)))
CPPFILES	:=	$(foreach dir, $(SRCDIRS) , $(notdir $(wildcard $(dir)/*.cpp)))
SFILES		:=	$(foreach dir, $(SRCDIRS) , $(notdir $(wildcard $(dir)/*.s)))
BINFILES	:=	$(foreach dir, $(DATADIRS), $(notdir $(wildcard $(dir)/*.*)))

# --- Set linker depending on C++ file existence ---
ifeq ($(strip $(CPPFILES)),)
	export LD	:= $(CC)
else
	export LD	:= $(CXX)
endif

# --- Define object file list ---
export OFILES	:=									\
	$(addsuffix .o, $(BINFILES))					\
	$(CFILES:.c=.o) $(CPPFILES:.cpp=.o)				\
	$(SFILES:.s=.o)
	
# --- Create include and library search paths ---
export INCLUDE	:=									\
	$(foreach dir,$(INCDIRS),-I$(CURDIR)/$(dir))	\
	$(foreach dir,$(LIBDIRS),-I$(dir)/include)		\
	-I$(CURDIR)/$(BUILD)

export LIBPATHS	:=	-L$(CURDIR) $(foreach dir,$(LIBDIRS),-L$(dir)/lib)


# --- More targets ----------------------------------------------------

.PHONY: $(BUILD) clean

# --- Create $(BUILD) if necessary, and run this makefile from there ---

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

all	: $(BUILD)

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


else		# If we're here, we should be in the BUILD dir

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

# --- Main targets ----

$(OUTPUT).gba	:	$(OUTPUT).elf

$(OUTPUT).elf	:	$(OFILES) libgfx.a


-include $(DEPENDS)


endif		# End BUILD switch

# EOF
I am using a makefile from one of the examples from tonc in my project.

Basically SOUND_FILES holds all of the .o files I need to include with my source. Where exactly should I add $(SOUND_FILES)? These files need to be .o files before I run the makefile as they are output by another program.

I will upload my source if it is needed but I don't think it is.

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: How do I add .o files to my makefile?

Post by WinterMute » Sun Sep 18, 2011 1:15 pm

The best way to go with this is to integrate the tool which outputs these files as part of the Makefile or the build process. In most cases you should avoid any manual steps in the build process.

It's hard to provide a definitive answer without knowing what the tool is, which files it converts from and what options are passed.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Gamer2020
Posts: 8
Joined: Fri Sep 09, 2011 7:22 pm

Re: How do I add .o files to my makefile?

Post by Gamer2020 » Sun Sep 18, 2011 8:15 pm

Problem is that I don't want to assemble the files each time and they actually shouldn't be. Some of those files come already assembled so I can't reassemble them.

The tool is mks4agb from the Nintendo SDK. I'm basically just trying to use their music player. I got the program to work with devkitARM and now I just have to add the output files to my source. That seems to be the way it is supposed to be done since the instructions say that the output files must be give to the programer.

The make files Nintendo uses are different so I am unsure of where to put the variable. I tried putting them in a couple places but I always got the error "No rule to make target."

Gamer2020
Posts: 8
Joined: Fri Sep 09, 2011 7:22 pm

Re: How do I add .o files to my makefile?

Post by Gamer2020 » Sun Sep 18, 2011 11:39 pm

Sorry for the double post but I don't think I'm allowed to edit my post anymore 0.o

If is helps this is what instructions say to change in the makefile.

Code: Select all

 *Add $(SOUND_FILES) to the written portion of the link.*
                                    
  $(TARGET_ELF): $(.OFILES) $(SOUND_FILES) Makefile $(DEPENDFILE)
    @echo > $(MAPFILE)
    $(CC) -g -o $@ $(.OFILES) $(SOUND_FILES) -Wl, $(LDFLAGS)
 
I just need to do the same in my makefile.

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: How do I add .o files to my makefile?

Post by zeromus » Wed Sep 21, 2011 7:05 am

try

Code: Select all

$(OUTPUT).elf   :   $(OFILES) $(SOUND_FILES) libgfx.a
If this works, then it should be pretty obvious how it is the same thing as the suggestion you received.

But if you want to do it right, then you need to be a makefile master and have the .o files built automatically as wintermute suggested

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: How do I add .o files to my makefile?

Post by WinterMute » Wed Sep 21, 2011 12:11 pm

This is a little awkward - Nintendo SDKs are proprietary and confidential which basically means we don't have legal access to them, even if the GBA is no longer a commercially exploited platform. Generally we try to avoid supporting use of tools and libraries that we shouldn't have. The question is quite valid though, even if the tool pipeline is a bit wrong.

The Makefiles are basically designed to work from source assets and feed them through other tools to get the final output so attempting to link object files generated by a tool not on the programmer's machine can get a bit problematic. The build system expects all the final object files to be in that build folder but obviously it's not really a good idea to just dump the files in there as they'll get deleted when you make clean.

Personally I think I'd tend towards putting the sound files into a library archive and linking that directly, similar to the way the graphics files are linked. You can probably rework the graphics makefile a bit
Help keep devkitPro toolchains free, Donate today

Personal Blog

Gamer2020
Posts: 8
Joined: Fri Sep 09, 2011 7:22 pm

Re: How do I add .o files to my makefile?

Post by Gamer2020 » Thu Sep 22, 2011 4:53 am

WinterMute wrote:This is a little awkward - Nintendo SDKs are proprietary and confidential which basically means we don't have legal access to them, even if the GBA is no longer a commercially exploited platform. Generally we try to avoid supporting use of tools and libraries that we shouldn't have. The question is quite valid though, even if the tool pipeline is a bit wrong.

The Makefiles are basically designed to work from source assets and feed them through other tools to get the final output so attempting to link object files generated by a tool not on the programmer's machine can get a bit problematic. The build system expects all the final object files to be in that build folder but obviously it's not really a good idea to just dump the files in there as they'll get deleted when you make clean.

Personally I think I'd tend towards putting the sound files into a library archive and linking that directly, similar to the way the graphics files are linked. You can probably rework the graphics makefile a bit
Yeah I understand that and I would assemble the files from the makefile but some come already assembled.

I was thinking that I could put them in an archive but I was unsure as to whether that was the best solution. I was also unsure as to whether the files would actually linked. I'll try putting them in an archive and seeing if it works. Thanks =)
zeromus wrote:try

Code: Select all

$(OUTPUT).elf   :   $(OFILES) $(SOUND_FILES) libgfx.a
If this works, then it should be pretty obvious how it is the same thing as the suggestion you received.

But if you want to do it right, then you need to be a makefile master and have the .o files built automatically as wintermute suggested
I tried that already and it didn't work. Thanks.

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: How do I add .o files to my makefile?

Post by zeromus » Thu Sep 22, 2011 7:38 pm

didn't work how

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: How do I add .o files to my makefile?

Post by WinterMute » Thu Sep 22, 2011 11:02 pm

It doesn't work because the linker can't find the object files - the working directory is the build directory and the object files have a path relative to the Makefile. For that to work you'd probably need to specify the absolute path for each object file - this should probably work

move the SOUND_FILES variable down below BINFILES and create it using a wildcard instead of naming each file individually

Code: Select all

SOUND_DIR := sound

...

BINFILES   :=   $(foreach dir, $(DATADIRS), $(notdir $(wildcard $(dir)/*.*)))
SOUND_FILES = $(wildcard $(CURDIR)/$(SOUND_DIR)/*.o)

...

$(OUTPUT).elf   :   $(OFILES) $(SOUND_FILES) libgfx.a
Help keep devkitPro toolchains free, Donate today

Personal Blog

Gamer2020
Posts: 8
Joined: Fri Sep 09, 2011 7:22 pm

Re: How do I add .o files to my makefile?

Post by Gamer2020 » Wed Oct 12, 2011 1:40 am

Sorry for the late reply but I have been busy. The method you said in your last post doesn't seem to work. It should show the file names that are in the $(SOUND_FILES) when it links the files right?

I'm going to try putting them in an archive now.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests