Page 1 of 1

[solved] Compiler Directive adjust directory at compile tim

Posted: Wed Jun 25, 2008 3:11 pm
by jamirokwai
Dear Board,

is it possible a compile-time to let the compiler decide, what code to
compile... :)

On Mac-OS, the current directory is foreseeable different when testing
and running an Application. I'd like to add something like

Code: Select all

compilerif #compiling_an_executable
 path$ = "/here/and/there"
compilerelseif #compiling_for_testing
 path$ = "over/there"
compilerendif
So, if I use the function "Create Executable", the compiler would fill
path$ with "/here/and/there", when compiling/executing the compiler
would fill path$ with "over/there"

See http://www.purebasic.fr/english/viewtopic.php?t=32741 for a
working idea how to accomplish this at runtime.

Is that possible??

Thanks in advance for any ideas :D

-----

Edit:
fast answer! :P Thank you very much, see my reply at the end of this thread.

Re: Compiler Directives

Posted: Wed Jun 25, 2008 3:16 pm
by PB
Just set a constant (such as #testing=1) and then use the compiler directives.
That's all I do. It's not possible to test when an executable is being created
because it always is, even when hitting F5 to Compile/Run. ;)

Posted: Wed Jun 25, 2008 5:38 pm
by blueznl
Of course that is possible! How do you think I did it with CodeCaddy?

Posted: Wed Jun 25, 2008 6:28 pm
by Foz
This is what I use - one for running from the IDE, and one for running as an independent app:

Code: Select all

CompilerIf #PB_Compiler_Debugger
; debug mode
CompilerElse
; running directly
CompilerEndIf

Posted: Wed Jun 25, 2008 9:54 pm
by PB
> CompilerIf #PB_Compiler_Debugger

Holy crap, how the heck did I miss that? :shock: :lol: Thanks guys.

Yeah! Works

Posted: Wed Jun 25, 2008 10:35 pm
by jamirokwai
PB wrote:> CompilerIf #PB_Compiler_Debugger

Holy crap, how the heck did I miss that? :shock: :lol: Thanks guys.
Let's say, this is indeed what I was thinking of... You need, of course,
to compile with debugger enabled...

Thank you very much!!!

My approach for Mac OS X to use datafiles depending on the location of
the Application bundle is as follows... My Application uses this location
to load some data residing in the same directory as the Bundle on runtime.

Code: Select all

 CompilerIf #PB_Compiler_Debugger 
  location$ = "" 
 CompilerElse
  location$ = Left(GetPathPart(ProgramFilename()), FindString(GetPathPart(ProgramFilename()),GetFilePart(ProgramFilename())+".app",1)-1)
 CompilerEndIf
The approach of determing the Bundle's directory is coded by michael51,
see http://www.purebasic.fr/english/viewtopic.php?t=32741