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

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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.7, 21.06.2025, 02.11.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)
    If Not id
      Trace("Error: Compiler Not found: " + pb_compiler)
    Else
      While ProgramRunning(id)
        If AvailableProgramOutput(id)
          result = ReadProgramString(id)
          Trace("- " + result)
        EndIf
        DoEvents()
      Wend
      CloseProgram(id)
      Trace("Done.")
    EndIf
  CompilerEndIf  
    
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
  
EndIf
Last edited by mk-soft on Sun Nov 02, 2025 12:36 pm, edited 9 times in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 290
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

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

Post 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
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

Your ProcedureDLL in line 5 is incorrect.
You must create two procedures.

ProcedureDLL HSLtoRGB(..., ...)
ProcedureDLL HSLtoRGB2(..., ..., Alpha)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 290
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

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

Post 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?
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

Update v1.02.2
- Trace Output :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Axolotl
Addict
Addict
Posts: 890
Joined: Wed Dec 31, 2008 3:36 pm

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

Post 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
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

Update v1.02.5
- Added optional parameter flags. Example for compiler flag --thread
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

Update v1.02.6
- On Windows: Start compiler on console. ReadProgramString not working correctly.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Piero
Addict
Addict
Posts: 1102
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

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

Post by Piero »

mk-soft wrote: Fri Dec 27, 2024 9:53 pm

Code: Select all

      While ProgramRunning(id)
        If AvailableProgramOutput(id)
          result = ReadProgramString(id)
          If result = ""
            result = ReadProgramError(id)
          EndIf
Hmmm… stdout management (AvailableProgramOutput) ≠ stderr management…

Code: Select all

; Mac

id = RunProgram("ls", "qwerty", "",  #PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
If id
   While ProgramRunning(id)
      If AvailableProgramOutput(id)
         result.s = ReadProgramString(id)
         If result = ""
            result = ReadProgramError(id)
            Debug ("mk's error: " + result)
         EndIf
      EndIf
      s.s=ReadProgramError(id)
      if s : Debug ("Piero's error: " + s) : EndIf
   Wend
   CloseProgram(id)
EndIf
User avatar
mk-soft
Always Here
Always Here
Posts: 6388
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

You're right, not required.
Was an attempt to get the output on Windows, which unfortunately for some reason is not possible.
Removed ReadErrorString ...

Thanks.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Piero
Addict
Addict
Posts: 1102
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

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

Post by Piero »

My Idol just thanked me!
🎉🥳🍻
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 426
Joined: Thu Jul 09, 2015 9:07 am

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

Post by pf shadoko »

I read part of the thread.
My little tool:
viewtopic.php?p=631988#p631988
was initially created specifically for managing optional parameters.

With the optimization of the C code, I think my management of optional parameters remains optimal.
(if anyone wants to do a comparison...).

There is no need to manage the “thread” option; the libraries automatically create the two versions (with and without thread).

My tool has been reviewed and corrected by Fred, so you can rely on it.
(However, there is still some possibility of crashes, so I am waiting for bug reports to make corrections).
infratec
Always Here
Always Here
Posts: 7691
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post by infratec »

Maybe this works better:

Code: Select all

*Buffer = AllocateMemory(2048)

While ProgramRunning(id)
  Len = AvailableProgramOutput(id)
  If Len
    If *Buffer
      Len = ReadProgramData(id, *Buffer, Len)
      If Len
        result = PeekS(*Buffer, Len, #PB_UTF8|#PB_ByteLength)
        Trace("- " + result)
      EndIf
    EndIf
  EndIf
  DoEvents()
Wend

If *Buffer
  FreeMemory(*Buffer)
EndIf
Since AvailableProgramOutput(id) returns available bytes and this means not that CR has arrived.
And ReadProgramString() waits for CR.
Post Reply