How do I add .o files to my makefile?
Posted: 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.
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.
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
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.