LIB-PB v6.20+: IDE-Tool Build Library for all OS
Posted: Fri Dec 27, 2024 9:53 pm
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.
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