| View previous topic :: View next topic |
| Author |
Message |
MysticWhiteDragon
Joined: 16 Feb 2006 Posts: 30
|
Posted: Sun Jun 21, 2009 6:45 am Post subject: Problem with a define |
|
|
I am attempting to build a multi-platform game (Starting with PSP, PS2 & Windows).
I can get the PSP version to compile correctly, but the PS2 compiler will not accept -DPS2 while -DPSP works for the PSP. Any help would be appreciated.
Makefile
| Code: |
#BUILD_DC = 1
#BUILD_PSP = 1
#
BUILD_PS2 = 1
#BUILD_WIN = 1
#BUILD_GP2X = 1
#BUILD_LINUX = 1
#========================= ========================= #
ifdef BUILD_PSP
TARGET = Template
OBJS = obj/main.o
#BUILD_PRX = 1
#PRX_EXPORTS = src/exports.exp
#PSP_FW_VERSION = 371
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS) -c
LDFLAGS = -DPSP
LIBDIR = lib
LIBS = -lc -lm
#USE_PSPSDK_LIBC = 1
#USE_PSPSDK_LIBS = 1
#USE_KERNEL_LIBC = 1
#USE_KERNEL_LIBS = 1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Template
#PSP_EBOOT_ICON = res/ICON0.PNG
#PSP_EBOOT_ICON1 = res/ICON1.PMF
#PSP_EBOOT_PIC1 = res/PIC1.PNG
#PSP_EBOOT_UNKPNG = res/PIC0.PNG
#PSP_EBOOT_SND0 = res/SND0.AT3
PSPSDK = ../../Compiler/System/psp/psp/sdk
include $(PSPSDK)/lib/build.mak
all: EBOOT.PBP
-rm -f $(TARGET).elf PARAM.SFO
-mv -f EBOOT.PBP bin/psp/
obj/%.o: src/%.c
$(CC) $(CFLAGS) -c -o $@ $<
obj/%.o: src/%.S
$(CC) $(CFLAGS) -c -o $@ $<
endif
#========================= ========================= #
ifdef BUILD_PS2
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
PS2DEV = ../../Compiler/System/ps2
PS2SDK = ../../Compiler/System/ps2/ps2sdk
EE_BIN = main.elf
EE_OBJS = obj/main.o
EE_INCS = -I$(PS2DEV)/ee/ee/include
EE_LDFLAGS = -DPS2
EE_LIBS = -ldebug
all: $(EE_BIN)
mv -f $(EE_BIN) bin/ps2/
obj/%.o : src/%.c
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
obj/%.o : src/%.cc
$(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) -c $< -o $@
obj/%.o : src/%.cpp
$(EE_CXX) $(EE_CXXFLAGS) $(EE_INCS) -c $< -o $@
obj/%.o : src/%.S
$(EE_CC) $(EE_CFLAGS) $(EE_INCS) -c $< -o $@
obj/%.o : src/%.s
$(EE_AS) $(EE_ASFLAGS) $< -o $@
clean:
rm -f *.elf src/*.o *.a
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
endif
|
main.c
| Code: |
#ifdef PSP
#include <pspkernel.h>
#include <pspdebug.h>
#endif
#ifdef PS2 // works if changed to #ifndef PSP
#include <tamtypes.h>
#include <debug.h>
#endif
#ifdef PSP
PSP_MODULE_INFO("Hello World", 0, 1, 1);
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
#endif
int main(int argc, char **argv)
{
#ifdef PSP
pspDebugScreenInit();
SetupCallbacks();
printf("Hello World");
#endif
#ifdef PS2 // works if changed to #ifndef PSP
init_scr();
scr_printf("Hello World!");
#endif
#ifdef PSP
sceKernelSleepThread();
#endif
return(0);
}
|
|
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Jun 21, 2009 6:48 am Post subject: |
|
|
| It would help if you posted the error. |
|
| Back to top |
|
 |
jbit Site Admin

Joined: 28 May 2005 Posts: 293 Location: København, Danmark
|
Posted: Sun Jun 21, 2009 7:13 am Post subject: Re: Problem with a define |
|
|
-D is a compile time flag, not a link time flag... it needs to be in EE_CFLAGS (and EE_CXXFLAGS if you use C++), not EE_LDFLAGS.
I have no idea why the PSP version works since it looks like you made the same mistake there too. (maybe the PSP define is set in a header somewhere?)
Also using ambiguous defines like PS2/PSP is asking for trouble since the preprocessor might pick up on it in places you don't expect. Something like TARGET_PS2, TARGET_PSP, etc is usually used. |
|
| Back to top |
|
 |
MysticWhiteDragon
Joined: 16 Feb 2006 Posts: 30
|
Posted: Sun Jun 21, 2009 7:21 am Post subject: |
|
|
Thanks jbit!!!
I haven't ever used -D in a makefile. I copied that -D from another makefile. Thanks for straightening that out. It now works fine. Now I know for future reference.
Line from the other makefile.
| Code: |
LDFLAGS = psp-setup.c -DMODULE_NAME="Name" -DMODULE_ATTR=0 -DVERSION_MAJOR=1 -DVERSION_MINOR=0
|
|
|
| Back to top |
|
 |
jbit Site Admin

Joined: 28 May 2005 Posts: 293 Location: København, Danmark
|
Posted: Sun Jun 21, 2009 7:27 am Post subject: |
|
|
It works in that LDFLAGS because it seems to be doing compile and link in the same phase (thus why there's a .c file there too), this is quite ugly :)
I don't think I'd trust the validity of any makefile that has source/target files in the *FLAGS variables. |
|
| Back to top |
|
 |
MysticWhiteDragon
Joined: 16 Feb 2006 Posts: 30
|
Posted: Sun Jun 21, 2009 7:30 am Post subject: |
|
|
From the psp-setup.c
| Code: |
/**
* This file handles all the PSP-specific kernel setup and exit stuff.
*
* Is there some general interest for this file, so that we can place it
* somewhere in the compiler toolchain include path?
*
* Usage: Simply add
* -DMODULE_NAME="your-module-name" psp-setup.c
* to the LFLAGS or LDFLAGS of your project, so that this file is
* compiled in when gcc collects and links the final ELF binary.
*
* Options:
* -DMODULE_NAME="name" -- set the name (default NONAME)
* -DMODULE_ATTR=0 -- module attributes (default 0)
* -DVERSION_MAJOR=1 -- version 1.x (default 1)
* -DVERSION_MINOR=0 -- version x.0 (default 0)
*
* Note: The linker flags and library lists need to be placed after this
* entry on the LFLAG or LDFLAGS command line, otherwise gcc won't
* be able to to resolve all symbols.
*/
|
That is why I thought the -D had to be where it was located.
Last edited by MysticWhiteDragon on Sun Jun 21, 2009 8:03 am; edited 3 times in total |
|
| Back to top |
|
 |
jbit Site Admin

Joined: 28 May 2005 Posts: 293 Location: København, Danmark
|
Posted: Sun Jun 21, 2009 7:41 am Post subject: |
|
|
| Ah, there they're using it for some magic reason, but again those "-D" defines will only affect code that's compiled (and preprocessed) during the link phase... which is any .c file in the LDFLAGS/OBJECTS/etc variables. :) |
|
| Back to top |
|
 |
|