[solved] Compiler Directive adjust directory at compile tim

Just starting out? Need help? Post your questions and find answers here.
jamirokwai
Enthusiast
Enthusiast
Posts: 799
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

[solved] Compiler Directive adjust directory at compile tim

Post 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.
Last edited by jamirokwai on Wed Jun 25, 2008 10:40 pm, edited 2 times in total.
Regards,
JamiroKwai
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Compiler Directives

Post 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. ;)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Of course that is possible! How do you think I did it with CodeCaddy?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post 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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> CompilerIf #PB_Compiler_Debugger

Holy crap, how the heck did I miss that? :shock: :lol: Thanks guys.
jamirokwai
Enthusiast
Enthusiast
Posts: 799
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Yeah! Works

Post 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
Regards,
JamiroKwai
Post Reply