News:

Welcome to RetroCoders Community

Main Menu

FreeBasic pre-fbc

Started by ron77_db, Apr 01, 2022, 08:30 AM

Previous topic - Next topic

ron77_db

this little piece of code will give you the ability to set in each ".bas" file or program the unique build commands for freebasic compiler (fbc or fbc.exe) so you won't need to set it manually in a text editor or IDE...

simple compile it with build commands fbc -s GUI then copy the executable to the bin folder where the fbc (on linux) or fbc.exe (on windows) is found then change the path in your IDE/text editor to that executable (meaning instead of fbc or fbc.exe pre-fbc or pre-fbc.exe) and now when you wish to compile with build commands no no longer need to set them in the build options but at the top of the .bas file of your program that you are about to compile add the following:

#define fbc [whatever build commands you wish]

for example:

1. "#define fbc -s console -exx"

and then compile and the executable will be compiled with the build commands you defined in the code

this is very useful if you have many files and source codes that need to be compiled with specific build commands and you find id hard to remember each time - that way you define them once and it is fixed for each source file...

the code should be compiled with 32 bit fbc for windows and 64 bit fbc for linux

happy coding

p.s. - the author of the code is mysoft who kindly gave permission to post it here

#define fbc -s gui
 
dim as string EXTRA,PARM
dim as integer COUNT,FND
 
COUNT = 1
do
  PARM = command$(COUNT)  
  if PARM = "" then 
    exit do
  elseif instr(1,lcase$(PARM),".bas") then
    if dir$(PARM)<>"" then
      open PARM for input as #1
      while not eof(1)
        line input #1,PARM      
        FND = instr(1,lcase$(PARM),"#define fbc")
        if FND then
          EXTRA += mid$(PARM,FND+11)
        end if
      wend
      close #1
    end if
  end if
  COUNT += 1
loop
PARM = command$+EXTRA
if instr(lcase$(PARM),"-v ") then print "{"+PARM+"}"
rem if instr(lcase$(PARM),"-prefix ") then chdir exepath
 
#ifdef __FB_WIN32__
end exec(exepath+"\fbc.exe",PARM)
#else
end exec("fbc",PARM)
#endif
 

paul doe

Since Fb 1.09.0 you can use the #cmdline preprocessor directive:

https://www.freebasic.net/wiki/KeyPgPpcmdline

mysoft

heh a bit too late, but good :)