Problem with a define

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
MysticWhiteDragon
Posts: 30
Joined: Thu Feb 16, 2006 8:46 am

Problem with a define

Post by MysticWhiteDragon »

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: Select all

#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
	$&#40;CC&#41; $&#40;CFLAGS&#41; -c -o $@ $<

obj/%.o&#58; src/%.S
	$&#40;CC&#41; $&#40;CFLAGS&#41; -c -o $@ $<

endif

#=========================  ========================= #

ifdef BUILD_PS2

# _____     ___ ____     ___ ____
#  ____|   |    ____|   |        | |____|
# |     ___|   |____ ___|    ____| |    \    PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# Copyright 2001-2004, ps2dev - http&#58;//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$&#40;PS2DEV&#41;/ee/ee/include
EE_LDFLAGS = -DPS2
EE_LIBS = -ldebug

all&#58; $&#40;EE_BIN&#41;
	mv -f $&#40;EE_BIN&#41; bin/ps2/

obj/%.o &#58; src/%.c
	$&#40;EE_CC&#41; $&#40;EE_CFLAGS&#41; $&#40;EE_INCS&#41; -c $< -o $@

obj/%.o &#58; src/%.cc
	$&#40;EE_CXX&#41; $&#40;EE_CXXFLAGS&#41; $&#40;EE_INCS&#41; -c $< -o $@

obj/%.o &#58; src/%.cpp
	$&#40;EE_CXX&#41; $&#40;EE_CXXFLAGS&#41; $&#40;EE_INCS&#41; -c $< -o $@

obj/%.o &#58; src/%.S
	$&#40;EE_CC&#41; $&#40;EE_CFLAGS&#41; $&#40;EE_INCS&#41; -c $< -o $@

obj/%.o &#58; src/%.s
	$&#40;EE_AS&#41; $&#40;EE_ASFLAGS&#41; $< -o $@

clean&#58;
	rm -f *.elf src/*.o *.a

include $&#40;PS2SDK&#41;/samples/Makefile.pref
include $&#40;PS2SDK&#41;/samples/Makefile.eeglobal

endif

main.c

Code: Select all

#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&#40;"Hello World", 0, 1, 1&#41;;

#define printf pspDebugScreenPrintf 

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;

	sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

#endif

int main&#40;int argc, char **argv&#41;
&#123;
#ifdef PSP
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;

	printf&#40;"Hello World"&#41;; 
#endif

#ifdef PS2 // works if changed to #ifndef PSP
	init_scr&#40;&#41;;
	scr_printf&#40;"Hello World!"&#41;;
#endif

#ifdef PSP
	sceKernelSleepThread&#40;&#41;;
#endif
	return&#40;0&#41;;
&#125;

J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

It would help if you posted the error.
User avatar
jbit
Site Admin
Posts: 293
Joined: Sat May 28, 2005 3:11 am
Location: København, Danmark
Contact:

Re: Problem with a define

Post by jbit »

MysticWhiteDragon wrote:

Code: Select all

EE_LDFLAGS = -DPS2
-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.
MysticWhiteDragon
Posts: 30
Joined: Thu Feb 16, 2006 8:46 am

Post by MysticWhiteDragon »

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: Select all

LDFLAGS  = psp-setup.c -DMODULE_NAME="Name" -DMODULE_ATTR=0 -DVERSION_MAJOR=1 -DVERSION_MINOR=0
User avatar
jbit
Site Admin
Posts: 293
Joined: Sat May 28, 2005 3:11 am
Location: København, Danmark
Contact:

Post by jbit »

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.
MysticWhiteDragon
Posts: 30
Joined: Thu Feb 16, 2006 8:46 am

Post by MysticWhiteDragon »

From the psp-setup.c

Code: Select all

/**
 *  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&#58; 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&#58;
 *         -DMODULE_NAME="name" -- set the name &#40;default NONAME&#41;
 *         -DMODULE_ATTR=0      -- module attributes &#40;default 0&#41;
 *         -DVERSION_MAJOR=1    -- version 1.x &#40;default 1&#41;
 *         -DVERSION_MINOR=0    -- version x.0 &#40;default 0&#41;
 *
 *  Note&#58;  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.
User avatar
jbit
Site Admin
Posts: 293
Joined: Sat May 28, 2005 3:11 am
Location: København, Danmark
Contact:

Post by jbit »

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. :)
Post Reply