| View previous topic :: View next topic |
| Author |
Message |
sedrik
Joined: 04 Sep 2008 Posts: 8
|
Posted: Mon Sep 15, 2008 8:29 am Post subject: Editing make file |
|
|
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: | 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
|
|
|
| Back to top |
|
 |
angelo
Joined: 29 Aug 2007 Posts: 168
|
Posted: Tue Sep 16, 2008 4:34 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
sedrik
Joined: 04 Sep 2008 Posts: 8
|
Posted: Tue Sep 16, 2008 5:00 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Sep 17, 2008 5:37 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
sedrik
Joined: 04 Sep 2008 Posts: 8
|
Posted: Fri Sep 19, 2008 3:38 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Fri Sep 19, 2008 4:04 pm Post subject: |
|
|
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: | 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
$(CC) $(CFLAGS) -c $< -o $@
cpuemu1.o: cpuemu.cpp
$(CXX) -D_REENTRANT -DPART_1 $(CXXFLAGS) -c $< -o $@
cpuemu2.o: cpuemu.cpp
$(CXX) -D_REENTRANT -DPART_2 $(CXXFLAGS) -c $< -o $@
cpuemu3.o: cpuemu.cpp
$(CXX) -D_REENTRANT -DPART_3 $(CXXFLAGS) -c $< -o $@
cpuemu4.o: cpuemu.cpp
$(CXX) -D_REENTRANT -DPART_4 $(CXXFLAGS) -c $< -o $@
cpuemu5.o: cpuemu.cpp
$(CXX) -D_REENTRANT -DPART_5 $(CXXFLAGS) -c $< -o $@
cpuemu6.o: cpuemu.cpp
$(CXX) -D_REENTRANT -DPART_6 $(CXXFLAGS) -c $< -o $@
cpuemu7.o: cpuemu.cpp
$(CXX) -D_REENTRANT -DPART_7 $(CXXFLAGS) -c $< -o $@
cpuemu8.o: cpuemu.cpp
$(CXX) -D_REENTRANT -DPART_8 $(CXXFLAGS) -c $< -o $@
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
Nothing else is needed... no changes to build.mak or anything. |
|
| Back to top |
|
 |
sedrik
Joined: 04 Sep 2008 Posts: 8
|
Posted: Fri Sep 19, 2008 5:08 pm Post subject: |
|
|
My makefile
| Code: | PROJECT = thaGame
TARGET = ${PROJECT}
OBJS = main.o engine.o card.o deck.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 |
| Code: | 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: In function `Deck::Deck()':
deck.cpp:(.text+0xe4): undefined reference to `operator new(unsigned int)'
deck.o: In function `Deck::Deck()':
deck.cpp:(.text+0x1dc): undefined reference to `operator new(unsigned int)'
collect2: ld returned 1 exit status
make: *** [thaGame.elf] 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. |
|
| Back to top |
|
 |
sedrik
Joined: 04 Sep 2008 Posts: 8
|
Posted: Fri Sep 19, 2008 5:20 pm Post subject: |
|
|
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
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.. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Fri Sep 19, 2008 6:21 pm Post subject: |
|
|
| You weren't linking in the c++ library, so why should it try to link with g++? :) |
|
| Back to top |
|
 |
sedrik
Joined: 04 Sep 2008 Posts: 8
|
Posted: Fri Sep 19, 2008 7:30 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Sat Sep 20, 2008 3:10 am Post subject: |
|
|
| 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). |
|
| Back to top |
|
 |
sedrik
Joined: 04 Sep 2008 Posts: 8
|
Posted: Sat Sep 20, 2008 3:15 am Post subject: |
|
|
| yeah but I believe g++ can link gcc .o files without problems? |
|
| Back to top |
|
 |
|