Page 1 of 1

LIB-PB v6.20+: IDE-Tool Build Library for all OS

Posted: Fri Dec 27, 2024 9:53 pm
by mk-soft
The environment for the path is set to the correct compiler in the tool and is only valid there.
Thus, it is not necessary to set by hand beforehand when starting the compiler via Console

Update v1.02.5
- Added optional parameter flags. Example for compiler flag --thread

Update v1.02.6
- On Windows: Start compiler on console. ReadProgramString not working correctly.

Code: Select all

;-TOP by mk-soft, v1.02.6, 21.06.2025

; Tool: Build Library
;
; Link: https://www.purebasic.fr/english/viewtopic.php?t=86000 
; 
; Configure Tools -> New
; - Commandline : youre compilation
; - Arguments   : "%HOME" "%FILE" Flags
; - Name        : Build Library

EnableExplicit

Global path.s, path_pb_home.s, path_pb_compiler.s
Global pb_compiler.s, parameters.s, in_file.s, out_file.s, flags.s, temp.s, index
Global r1, id, result.s

Macro DoEvents()
  While WindowEvent() : Wend
EndMacro

Macro Trace(text)
  AddGadgetItem(0, -1, text)
EndMacro

Procedure UpdateWindow()
  Protected dx, dy
  
  dx = WindowWidth(0)
  dy = WindowHeight(0)
  ResizeGadget(0, 0, 0, dx, dy)
EndProcedure

#WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 500, "Build Libray", #WinStyle)
  ListIconGadget(0, 0, 0, 600, 500, "Trace", 2000)
  AddGadgetColumn(0, 1, "", 24)
  
  BindEvent(#PB_Event_SizeWindow, @UpdateWindow())
  
  DoEvents()
  
  path_pb_home = RTrim(ProgramParameter(0), #PS$)
  path_pb_compiler = path_pb_home + #PS$ + "compilers"
  
  CompilerIf #PB_Compiler_Processor = #PB_Processor_Arm64 Or #PB_Compiler_Processor = #PB_Processor_Arm32
    pb_compiler = path_pb_compiler + #PS$ + "pbcompiler"
  CompilerElse
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      pb_compiler = path_pb_compiler + #PS$ + "pbcompiler"
    CompilerElse
      pb_compiler = path_pb_compiler + #PS$ + "pbcompilerc"
    CompilerEndIf
  CompilerEndIf
  
  in_file = ProgramParameter(1)
  r1 = MessageRequester("Build Libray", "File: " + in_file, #PB_MessageRequester_YesNo)
  If r1 <> #PB_MessageRequester_Yes
    End
  EndIf
  out_file = GetFilePart(in_file, #PB_FileSystem_NoExtension)
  
  index = 2
  Repeat
    temp = ProgramParameter(index)
    If temp = ""
      Break
    EndIf
    flags + temp + " "
    index + 1
  ForEver
  
  If flags
    parameters = in_file + " --optimizer " + flags + "--purelibrary --output " + out_file
  Else
    parameters = in_file + " --optimizer --purelibrary --output " + out_file
  EndIf
  
  path = GetEnvironmentVariable("PATH")
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
       path = path_pb_compiler + ":" + path_pb_home + ":" + path
    CompilerCase #PB_OS_Windows
       path = path_pb_compiler + ";" + path_pb_home + ";" + path
    CompilerCase #PB_OS_Linux
       path = path_pb_compiler + ":" + path_pb_home + ":" + path
  CompilerEndSelect
  SetEnvironmentVariable("PATH", path)
  path = GetEnvironmentVariable("PATH")
  
  Trace("INFO")
  Trace("- Path PureBasic Home: " + path_pb_home)
  Trace("- Path PureBasic Compiler: " + path_pb_compiler)
  Trace("- Path Environment: " + path)
  Trace("- Program: " + GetFilePart(pb_compiler) + " " + parameters)
  Trace("")
  DoEvents()
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Trace("Start Compiler. Close console to continue")
    DoEvents()
    id = RunProgram("cmd", "/K " + pb_compiler + " " + parameters, "",  #PB_Program_Wait)
    Trace("Done.")
  CompilerElse
    Trace("Start Compiler ...")
    id = RunProgram(pb_compiler, parameters, "",  #PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
    If Not id
      Trace("Error: Compiler Not found: " + pb_compiler)
    Else
      While ProgramRunning(id)
        If AvailableProgramOutput(id)
          result = ReadProgramString(id)
          If result = ""
            result = ReadProgramError(id)
          EndIf
          Trace("- " + result)
          DoEvents()
        EndIf
      Wend
      CloseProgram(id)
      Trace("Done.")
    EndIf
  CompilerEndIf  
    
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
  
EndIf

Re: LIB-PB v6.20: IDE-Tool Build Library for all OS

Posted: Sat Dec 28, 2024 12:00 am
by le_magn
Hi MkSoft, I tried your tool, but it fails to compile the code, it returns an error that with the pf shadoko tool I don't have, your tool interests me more because of the fact that it creates the library in the selected compiler folder and not in the IDE folder, where am I wrong?
Image
p.s. don't mind the name of the directory pb610, it is the 620

Re: LIB-PB v6.20: IDE-Tool Build Library for all OS

Posted: Sat Dec 28, 2024 12:43 am
by mk-soft
Your ProcedureDLL in line 5 is incorrect.
You must create two procedures.

ProcedureDLL HSLtoRGB(..., ...)
ProcedureDLL HSLtoRGB2(..., ..., Alpha)

Re: LIB-PB v6.20: IDE-Tool Build Library for all OS

Posted: Sat Dec 28, 2024 1:37 am
by le_magn
mk-soft wrote: Sat Dec 28, 2024 12:43 am Your ProcedureDLL in line 5 is incorrect.
You must create two procedures.

ProcedureDLL HSLtoRGB(..., ...)
ProcedureDLL HSLtoRGB2(..., ..., Alpha)
ok thank's, however, my question is if the tool, here: viewtopic.php?t=85882&hilit=createlib manages to create the libraries without errors, which of the 2 tools is wrong?

Re: LIB-PB v6.20: IDE-Tool Build Library for all OS

Posted: Sat Dec 28, 2024 11:19 am
by mk-soft
I took a closer look at the tool.

The tool from pf shadoko rebuilds the code first.
To do this, it goes through the parameters and creates a new procedureDLL xyz2 for optional parameters. The procedure is then called in this with optional parameters.

This is not optimal as all parameters are processed twice.

Code: Select all

;returns a color from its hue, saturation and luminosity
; QuickHelp HSLToRGB2(hue.a, saturation.a, lightness.a, alpha=255) - 
ProcedureDLL.l HSLToRGB2(hue.a, saturation.a, lightness.a, alpha)
  Protected.f h=hue *6/256
  Protected.f s=saturation/255
  Protected.f l=lightness/255
  Protected.f c,x,r_,v_,b_,m
  c=(1-Abs(2*l-1))*s
  x=c*(1-Abs(Mod(h, 2) -1))
  Select Int(h)
    Case 0:r_=c:v_=x
    Case 1:r_=x:v_=c
    Case 2:v_=c:b_=x
    Case 3:v_=x:b_=c
    Case 4:r_=x:b_=c
    Case 5:r_=c:b_=x
  EndSelect
  m=l-c/2
  Protected r,v,b
  r=Int((r_+m)*255)
  v=Int((v_+m)*255)
  b=Int((b_+m)*255)
  ProcedureReturn RGBA(r,v,b,alpha)
EndProcedure
ProcedureDLL.l HSLToRGB(hue.a,saturation.a,lightness.a)
ProcedureReturn HSLToRGB2(hue.a,saturation.a,lightness.a,255)
EndProcedure

Re: LIB-PB v6.20: IDE-Tool Build Library for all OS

Posted: Sat Dec 28, 2024 11:54 am
by mk-soft
Update v1.02.2
- Trace Output :wink:

Re: LIB-PB v6.20: IDE-Tool Build Library for all OS

Posted: Sat Dec 28, 2024 12:06 pm
by Axolotl
@mk-soft,
thanks for sharing, nice code -- as always.

Some spontaneous thoughts after reading the code, if you don't mind:
1. You can use the compiler switches "--" like "--help" on windows, so no reason to differentiate between the os -- only the Windows only switches using / like /XP
2. Why do you make changes to the PATH environment variable?
Reason for the question : I don't like programs that change my system settings. Unless they are installer/setup programs, which I only use in exceptional cases.
3. Maybe you need the #PB_Program_Error in RunProgram() because you want to read the error output of the program. (stderr) // acc. to Help-File

Re: LIB-PB v6.20: IDE-Tool Build Library for all OS

Posted: Sat Dec 28, 2024 12:43 pm
by mk-soft
For the commandline pbcompiler to work, the path to the purebasic home and compiler must be set. This change to the path is only valid for this instance in my tool. So it is not changed globally ;)

I will adjust the #PB_Program_Error.

Update v1.02.3 :wink:

Re: LIB-PB v6.20: IDE-Tool Build Library for all OS

Posted: Sun May 04, 2025 12:23 pm
by mk-soft
Update v1.02.5
- Added optional parameter flags. Example for compiler flag --thread

Re: LIB-PB v6.20+: IDE-Tool Build Library for all OS

Posted: Sat Jun 21, 2025 2:59 pm
by mk-soft
Update v1.02.6
- On Windows: Start compiler on console. ReadProgramString not working correctly.