forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Objective-C on the MinPSPW SDK

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Heimdall



Joined: 10 Nov 2005
Posts: 259
Location: Netherlands

PostPosted: Thu Sep 25, 2008 10:26 pm    Post subject: Objective-C on the MinPSPW SDK Reply with quote

As of build 0.8.8 there is a new compiler included and a sample obj-c project.

https://sourceforge.net/project/showfiles.php?group_id=223830&package_id=270611&release_id=628720

The example code:


Code:
#include <objc/Object.h>

@interface Greeter:Object
{
 /* This is left empty on purpose:
  ** Normally instance variables would be declared here,
  ** but these are not used in our example.
  */
}

- (void)greet;

@end


#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>

/* Define printf, just to make typing easier */
#define printf  pspDebugScreenPrintf

@implementation Greeter

- (void)greet
{
   printf("Hello, World from Obj-C!\n");
}

@end

/* Define the module info section */
PSP_MODULE_INFO("template", 0, 1, 1);

/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

int main(void)
{
   id myGreeter;
   myGreeter=[Greeter new];

   [myGreeter greet];

   [myGreeter free];

   /* Non Objective-C code to allow the app to end */
   SceCtrlData pad;
   
   printf("\nPress X to quit.\n");
   for (;;)
   {
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons & PSP_CTRL_CROSS)
         break;
      sceDisplayWaitVblankStart();
   }
   sceKernelExitGame();
   
   return 0;
}


So for the iPhone fans there is no excuse to drop it and make cool apps for the PSP :)
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Fri Sep 26, 2008 4:13 am    Post subject: Reply with quote

Cool! Maybe the toolchain script can be altered to compile obj-c as well.
Back to top
View user's profile Send private message AIM Address
Heimdall



Joined: 10 Nov 2005
Posts: 259
Location: Netherlands

PostPosted: Fri Sep 26, 2008 5:14 pm    Post subject: Reply with quote

I never built the official script but i think the patch is easy, on the download part, it is necessary to download the gcc objc component and on the build script enable it by:

Code:
--enable-languages="c,c++,objc"


This builds but it won't link, I had to change my script with something like:

CFLAGS="-G0" \
../../gcc-4.3.2/configure \
--enable-languages="c,c++,objc" \
... and all the other flags...

Then I added the sample code to the SDK:


Code:
Index: pspsdk/src/base/build.mak
===================================================================
--- pspsdk/src/base/build.mak   (revision 2432)
+++ pspsdk/src/base/build.mak   (working copy)
@@ -45,6 +45,11 @@
 CFLAGS += -D_PSP_FW_VERSION=$(PSP_FW_VERSION)
 CXXFLAGS += -D_PSP_FW_VERSION=$(PSP_FW_VERSION)
 
+# Objective-C selection. All Objective C code must be linked against libobjc.a
+ifeq ($(USE_OBJC),1)
+LIBS     := $(LIBS) -lobjc
+endif
+
 ifeq ($(BUILD_PRX),1)
 LDFLAGS  := $(addprefix -L,$(LIBDIR)) -specs=$(PSPSDK)/lib/prxspecs -Wl,-q,-T$(PSPSDK)/lib/linkfile.prx $(LDFLAGS)
 EXTRA_CLEAN += $(TARGET).elf
@@ -198,6 +203,9 @@
 %.c: %.exp
    psp-build-exports -b $< > $@
 
+%.o: %.m
+   $(CC) $(CFLAGS) -c -o $@ $<
+
 clean:
    -rm -f $(FINAL_TARGET) $(EXTRA_CLEAN) $(OBJS) $(PSP_EBOOT_SFO) $(PSP_EBOOT) $(EXTRA_TARGETS)
 
Index: pspsdk/src/base/build_prx.mak
===================================================================
--- pspsdk/src/base/build_prx.mak   (revision 2432)
+++ pspsdk/src/base/build_prx.mak   (working copy)
@@ -37,6 +37,11 @@
 
 CFLAGS += -D_PSP_FW_VERSION=$(PSP_FW_VERSION)
 
+# Objective-C selection. All Objective C code must be linked against libobjc.a
+ifeq ($(USE_OBJC),1)
+LIBS     := $(LIBS) -lobjc
+endif
+
 # Library selection.  By default we link with Newlib's libc.  Allow the
 # user to link with PSPSDK's libc if USE_PSPSDK_LIBC is set to 1.
 
@@ -80,6 +85,9 @@
 %.c: %.exp
    psp-build-exports -b $< > $@
 
+%.o: %.m
+   $(CC) $(CFLAGS) -c -o $@ $<
+
 clean: $(EXTRA_CLEAN)
    -rm -f $(FINAL_TARGET) $(TARGET).elf $(OBJS)
 
Index: pspsdk/src/samples/Makefile.am
===================================================================
--- pspsdk/src/samples/Makefile.am   (revision 2432)
+++ pspsdk/src/samples/Makefile.am   (working copy)
@@ -81,7 +81,8 @@
    utility/systemparam \
    utility/osk \
    me/basic \
-   wlan
+   wlan \
+   obj-c
 
 all:
 
Index: pspsdk/src/samples/obj-c/main.m
===================================================================
--- pspsdk/src/samples/obj-c/main.m   (revision 0)
+++ pspsdk/src/samples/obj-c/main.m   (revision 0)
@@ -0,0 +1,61 @@
+#include <objc/Object.h>
+
+@interface Greeter:Object
+{
+ /* This is left empty on purpose:
+  ** Normally instance variables would be declared here,
+  ** but these are not used in our example.
+  */
+}
+
+- (void)greet;
+
+@end
+
+
+#include <pspkernel.h>
+#include <pspdebug.h>
+#include <pspctrl.h>
+
+/* Define printf, just to make typing easier */
+#define printf  pspDebugScreenPrintf
+
+@implementation Greeter
+
+- (void)greet
+{
+   printf("Hello, World from Obj-C!\n");
+}
+
+@end
+
+/* Define the module info section */
+PSP_MODULE_INFO("template", 0, 1, 1);
+
+/* Define the main thread's attribute value (optional) */
+PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
+
+int main(void)
+{
+   id myGreeter;
+   myGreeter=[Greeter new];
+
+   [myGreeter greet];
+
+   [myGreeter free];
+
+   /* Non Objective-C code to allow the app to end */
+   SceCtrlData pad;
+   
+   printf("\nPress X to quit.\n");
+   for (;;)
+   {
+      sceCtrlReadBufferPositive(&pad, 1);
+      if (pad.Buttons & PSP_CTRL_CROSS)
+         break;
+      sceDisplayWaitVblankStart();
+   }
+   sceKernelExitGame();
+   
+   return 0;
+}
Index: pspsdk/src/samples/obj-c/Makefile.sample
===================================================================
--- pspsdk/src/samples/obj-c/Makefile.sample   (revision 0)
+++ pspsdk/src/samples/obj-c/Makefile.sample   (revision 0)
@@ -0,0 +1,19 @@
+TARGET = ObjC
+OBJS = main.o
+
+USE_OBJC=1
+
+INCDIR =
+CFLAGS = -G0 -Wall -O2
+CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
+ASFLAGS = $(CFLAGS)
+
+LIBDIR =
+LDFLAGS =
+
+EXTRA_TARGETS = EBOOT.PBP
+PSP_EBOOT_TITLE = ObjC Sample
+
+PSPSDK=$(shell psp-config --pspsdk-path)
+include $(PSPSDK)/lib/build.mak
+

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Heimdall



Joined: 10 Nov 2005
Posts: 259
Location: Netherlands

PostPosted: Wed Oct 01, 2008 12:35 am    Post subject: Reply with quote

I'm working on a patch to enable also Objective-C++. The compiler seems to work, i'm running tests and will generate a binary build in the coming days.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group