Editing make file

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
sedrik
Posts: 8
Joined: Thu Sep 04, 2008 5:06 pm

Editing make file

Post by sedrik »

Hi all

I have quite recently started with psp development and have managed to complete some tutorials. Now I want to start on my own project. One thing I like to do is to have a good structure in my project and it usualy goes something like this.

src/ (all my source files, .c, .cpp)
include/ (all .h files)
lib/ (any external library I might use)
objs/ (all built objects)
gfx/ (any graphics used in the project)
doc/ (documentation, irrelevant for the build but nice if you use doxygen or other documentation system)
(project name)/ (special folder for psp project, folder containing everything I need to play the game on my psp)

Could someone help me setting this up, I have good experience writing code but it's very lacking writing makefiles. :(

Edit:
Here is my current makefile

Code: Select all

PROJECT = project_name

TARGET = ${PROJECT}
OBJS = main.o Engine.o
INCDIR = ./include/
LIBIDR = ./lib/

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = ${PROJECT}

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
angelo
Posts: 168
Joined: Wed Aug 29, 2007 9:34 pm

Post by angelo »

I'd recommend you look at existing project done by other coders. Good examples are:

Application: piKey - Good for PRX's.
Developer: ZX81 - Good for incorporating graphics and the PSPIRKeyB lib.

Makefiles vary with what application you ant to make. It's best to edit an existing application (or smething in the "Samplea" folder) to prevent noobish errors. It also gives you a good head start.

Hope that helps!

Angelo
sedrik
Posts: 8
Joined: Thu Sep 04, 2008 5:06 pm

Post by sedrik »

I know how to edit makefiles to containt new information about my files and stuff.

I just want to know how to edit it so that my directory structure will work. The structure I use for my projects won't change depending on app (not that much, thoose folders will always be there) and I just need help incorporating them into the $(PSPSDK)/lib/build.mak file.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

sedrik wrote:I know how to edit makefiles to containt new information about my files and stuff.

I just want to know how to edit it so that my directory structure will work. The structure I use for my projects won't change depending on app (not that much, thoose folders will always be there) and I just need help incorporating them into the $(PSPSDK)/lib/build.mak file.
Don't change build.mak - you'll break everything else that uses it (like setting up the toolchain/sdk/libs). Instead, make a template makefile with the directories and then use the template for new projects.
sedrik
Posts: 8
Joined: Thu Sep 04, 2008 5:06 pm

Post by sedrik »

How do I tell the makefile that I'm working with C++ and not C? The files compiles with psp-g++ but it tries to link them with psp-gcc which for obvious reasons do not work.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

It handles C vs C++ automatically. If it's doing something else, it's a problem with the makefile, not build.mak. Look at my makefile for Basilisk II - it is a "standard" makefile that also specially handles a few files that need special compiling.

Code: Select all

TARGET = BasiliskII

CPUOBJS = ../uae_cpu/basilisk_glue.o ../uae_cpu/memory.o ../uae_cpu/newcpu.o \
	../uae_cpu/readcpu.o cpustbl.o cpudefs.o \
	cpuemu1.o cpuemu2.o cpuemu3.o cpuemu4.o cpuemu5.o cpuemu6.o cpuemu7.o cpuemu8.o \
	 ../uae_cpu/fpu/fpu_soft.o ../uae_cpu/fpu/softfloat/softfloat.o

OBJS = ../main.o main_psp.o ../prefs.o ../prefs_items.o prefs_psp.o \
	prefs_editor_psp.o sys_psp.o ../rom_patches.o ../slot_rom.o \
	../rsrc_patches.o ../emul_op.o ../macos_util.o ../xpram.o \
	xpram_psp.o ../timer.o timer_psp.o clip_psp.o ../adb.o \
	../serial.o serial_psp.o ../ether.o ether_psp.o ../sony.o \
	../disk.o ../cdrom.o ../scsi.o scsi_psp.o ../video.o \
	video_psp.o ../audio.o audio_psp.o ../extfs.o extfs_psp.o \
	ftruncate.o ../user_strings.o user_strings_psp.o \
	intraFont.o gui_psp.o reqfile.o dvemgr/pspDveManager.o \
	danzeff/danzeff.o \
	$(CPUOBJS)

INCDIR = $(PSPDEV)/SDK/include ../include ./include . ../uae_cpu ../uae_cpu/fpu/softfloat
CFLAGS = -O3 -G8 -Wall -DPSP -DDANZEFF_SCEGU
#CFLAGS += -DFPU_UAE -ffast-math
#CFLAGS += -DFPU_IEEE
CFLAGS += -DFPU_SOFT
CFLAGS += -falign-functions=64
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

BUILD_PRX = 1
PSP_FW_VERSION = 371
PSP_LARGE_MEMORY = 1

LIBDIR = $(PSPDEV)/SDK/lib
LIBS = -lstdc++ -lpng -lz -lpspirkeyb -lpsprtc -lpspwlan -lpspgum -lpspgu -lpspaudio -lm -lpsppower -lpspkubridge -lpspsystemctrl_user
LDFLAGS = -DMODULE_NAME="BasiliskII"

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Basilisk II
PSP_EBOOT_SND0="SND0.AT3"
PSP_EBOOT_ICON="ICON0blk.PNG"
PSP_EBOOT_PIC1="PIC1.PNG"

all: danzeff/danzeff.o cpuemu1.o cpuemu2.o cpuemu3.o cpuemu4.o cpuemu5.o cpuemu6.o cpuemu7.o cpuemu8.o $(EXTRA_TARGETS) $(FINAL_TARGET)

danzeff/danzeff.o: danzeff/danzeff.c
	$&#40;CC&#41; $&#40;CFLAGS&#41; -c $< -o $@

cpuemu1.o&#58; cpuemu.cpp
	$&#40;CXX&#41; -D_REENTRANT -DPART_1 $&#40;CXXFLAGS&#41; -c $< -o $@
cpuemu2.o&#58; cpuemu.cpp
	$&#40;CXX&#41; -D_REENTRANT -DPART_2 $&#40;CXXFLAGS&#41; -c $< -o $@
cpuemu3.o&#58; cpuemu.cpp
	$&#40;CXX&#41; -D_REENTRANT -DPART_3 $&#40;CXXFLAGS&#41; -c $< -o $@
cpuemu4.o&#58; cpuemu.cpp
	$&#40;CXX&#41; -D_REENTRANT -DPART_4 $&#40;CXXFLAGS&#41; -c $< -o $@
cpuemu5.o&#58; cpuemu.cpp
	$&#40;CXX&#41; -D_REENTRANT -DPART_5 $&#40;CXXFLAGS&#41; -c $< -o $@
cpuemu6.o&#58; cpuemu.cpp
	$&#40;CXX&#41; -D_REENTRANT -DPART_6 $&#40;CXXFLAGS&#41; -c $< -o $@
cpuemu7.o&#58; cpuemu.cpp
	$&#40;CXX&#41; -D_REENTRANT -DPART_7 $&#40;CXXFLAGS&#41; -c $< -o $@
cpuemu8.o&#58; cpuemu.cpp
	$&#40;CXX&#41; -D_REENTRANT -DPART_8 $&#40;CXXFLAGS&#41; -c $< -o $@

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
Nothing else is needed... no changes to build.mak or anything.
sedrik
Posts: 8
Joined: Thu Sep 04, 2008 5:06 pm

Post by sedrik »

My makefile

Code: Select all

PROJECT = thaGame

TARGET = $&#123;PROJECT&#125;
OBJS = main.o engine.o card.o deck.o
INCDIR = ./include/
LIBIDR = ./lib/

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = $&#123;PROJECT&#125;

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

Code: Select all

psp-g++ -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150   -c -o main.o main.cpp
psp-g++ -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150   -c -o engine.o engine.cpp
psp-g++ -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150   -c -o card.o card.cpp
psp-g++ -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150   -c -o deck.o deck.cpp
psp-gcc -I./include/ -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150  -L. -L/usr/local/pspdev/psp/sdk/lib   main.o engine.o card.o deck.o  -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o thaGame.elf
deck.o&#58; In function `Deck&#58;&#58;Deck&#40;&#41;'&#58;
deck.cpp&#58;&#40;.text+0xe4&#41;&#58; undefined reference to `operator new&#40;unsigned int&#41;'
deck.o&#58; In function `Deck&#58;&#58;Deck&#40;&#41;'&#58;
deck.cpp&#58;&#40;.text+0x1dc&#41;&#58; undefined reference to `operator new&#40;unsigned int&#41;'
collect2&#58; ld returned 1 exit status
make&#58; *** &#91;thaGame.elf&#93; Error 1
As you can see I haven't done anything strange in the Makefile to make it link with C and still it does.
sedrik
Posts: 8
Joined: Thu Sep 04, 2008 5:06 pm

Post by sedrik »

Ok, found the name of c++ library in your make file now. So to conclude the Makefile does not handle C vs C++ automatically as you suggested.

You have to include

Code: Select all

LIBS= -lstdc++
to make psp-gcc able to link c++ code. Why it think it should link using psp-gcc instead of psp-g++ still makes me confused..
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You weren't linking in the c++ library, so why should it try to link with g++? :)
sedrik
Posts: 8
Joined: Thu Sep 04, 2008 5:06 pm

Post by sedrik »

yeah but linking the library manually is not an automatic process :P

I don't see why it should compile using psp-g++ but link using psp-gcc, wouldn't psp-g++ be able to do the linking that C needs and be the default linker?
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

There's a rule that says "compile .c using gcc" and one that says "compile .cpp using g++" and one that says "link .o with gcc". The problem is that for the last one, it's called .o regardless of where it came from so the Makefile can't know whether to use gcc or g++ (and so we just use gcc).
sedrik
Posts: 8
Joined: Thu Sep 04, 2008 5:06 pm

Post by sedrik »

yeah but I believe g++ can link gcc .o files without problems?
Post Reply