Compile x86 programs from x64 IDE (windows only)
Posted: Sun Jan 25, 2009 8:14 am
If you're anything like me, you hate having to open the x86 IDE to test or compile something in x86 (me especially because the x86 IDE runs with /noext).
So I made this little (relatively anyway) program to call the x86 compiler from an x64 IDE tool.
Theoretically it could also be used to call an earlier PB version, or compile x64 from the x86 IDE (on an x64 windows install - but this would require disabling of the wow64 emulation iirc).
Just edit the variable/constants at the top of the file, and you're ready to compile as exe (compile in x64 IDE).
#windowwidth/height is the width and height of the compiler output window opened.
#dontcloseonOKcompile will keep the compiler output window open even if the compile had no errors.
Set #droopyslibisinstalled if you have droopy's lib installed, or the compiler will complain.
It will only set compiler command line options that are available as Environment Variables to a tool, if you require other options, add the option(s) to the end of the tools's command line; they should be passed on.
Create an IDE tool with the arguments set to the following:
If you spot any problems (especially relating to Vista usage), or have any suggestions/requests, let me know!
So I made this little (relatively anyway) program to call the x86 compiler from an x64 IDE tool.
Theoretically it could also be used to call an earlier PB version, or compile x64 from the x86 IDE (on an x64 windows install - but this would require disabling of the wow64 emulation iirc).
Just edit the variable/constants at the top of the file, and you're ready to compile as exe (compile in x64 IDE).
#windowwidth/height is the width and height of the compiler output window opened.
#dontcloseonOKcompile will keep the compiler output window open even if the compile had no errors.
Set #droopyslibisinstalled if you have droopy's lib installed, or the compiler will complain.
It will only set compiler command line options that are available as Environment Variables to a tool, if you require other options, add the option(s) to the end of the tools's command line; they should be passed on.
Code: Select all
purebasicx86path.s = "C:\Program Files (x86)\PureBasic4.30"
#windowwidth = 550
#windowheight = 250
#dontcloseonOKcompile = 0
#droopyslibisinstalled = 0
Procedure Error(error.s)
MessageRequester("Error", error, #MB_ICONERROR)
EndProcedure
CompilerIf #droopyslibisinstalled = 0
Procedure WaitUntilWindowIsClosed()
Repeat
Until WaitWindowEvent()= #PB_Event_CloseWindow
ProcedureReturn 1
EndProcedure
Procedure.s GetTempDirectory() ; Return the temp directory
Protected WinTemp.s
WinTemp = Space(255)
GetTempPath_(255, WinTemp)
If Right(WinTemp, 1) <> "\" : WinTemp = WinTemp + "\" : EndIf
ProcedureReturn WinTemp
EndProcedure
CompilerEndIf
Debugger = Val(GetEnvironmentVariable("PB_TOOL_Debugger"))
inlineasm = Val(GetEnvironmentVariable("PB_TOOL_InlineASM"))
unicode = Val(GetEnvironmentVariable("PB_TOOL_Unicode"))
threadsafe = Val(GetEnvironmentVariable("PB_TOOL_Thread"))
xpskin = Val(GetEnvironmentVariable("PB_TOOL_XPSkin"))
onerror = Val(GetEnvironmentVariable("PB_TOOL_OnError"))
subsys.s = Trim(GetEnvironmentVariable("PB_TOOL_SubSystem"))
theexe.s = GetEnvironmentVariable("PB_TOOL_Executable")
;EnableExplicit
Define compileroptions.s = "",x.i, progparam.s,properfile.s,tempfile.s
If debugger : compileroptions+"/DEBUGGER " : EndIf
If inlineasm : compileroptions+"/INLINEASM " : EndIf
If unicode : compileroptions+"/UNICODE " : EndIf
If threadsafe : compileroptions+"/THREAD " : EndIf
If xpskin : compileroptions+"/XP " : EndIf
If onerror : compileroptions+"/LINENUMBERING " : EndIf
If subsys <> "" : compileroptions+"/SUBSYSTEM "+Chr(34)+subsys+Chr(34)+" " : EndIf
For x = 0 To CountProgramParameters()-1
progparam = ProgramParameter(x)
Debug progparam
If FindString(UCase(progparam), "/FILE:", 0)
properfile = RemoveString(progparam,"/FILE:",#PB_String_NoCase)
Debug properfile
;properfile = progparam
;properfile = Right(progparam, Len(progparam)-6)
ElseIf FindString(UCase(progparam), "/TEMPFILE:", 0)
tempfile = RemoveString(progparam,"/TEMPFILE:",#PB_String_NoCase)
ElseIf FindString(UCase(progparam), "/EXE", 0)
makeexe.s = SaveFileRequester("Create cross compiled exe", theexe, "*.exe,*.dll|*.exe;*.dll", 0)
If makeexe
If (LCase(Right(makeexe, 4)) <> ".exe") And (LCase(Right(makeexe, 4)) <> ".dll")
makeexe+".exe"
EndIf
compileroptions+"/EXE "+Chr(34)+makeexe+Chr(34)+" "
If LCase(Right(makeexe, 4)) = ".dll"
compileroptions+"/DLL "
EndIf
disablethedebugger = 1
Else
End
EndIf
Else
compileroptions+progparam+" "
EndIf
Next x
OpenWindow(0,0,0,#windowwidth,#windowheight,"PB compiler output", #PB_Window_SystemMenu)
ListViewGadget(0,0,0,#windowwidth,#windowheight)
AddGadgetItem(0,-1, "Compiler Options:")
AddGadgetItem(0,-1, compileroptions)
If properfile <> ""
compileroptions+Chr(34)+properfile+Chr(34)
ElseIf tempfile <> ""
compileroptions+Chr(34)+tempfile+Chr(34)
SetCurrentDirectory(GetTempDirectory())
Else
Error("You need to specify a file (with /FILE:) or a temp file (with /TEMPFILE:)")
End
EndIf
If disablethedebugger : compileroptions=RemoveString(compileroptions, "/DEBUGGER ") : EndIf ;for compiling as exe
wasanerror = 0
prog = RunProgram(purebasicx86path+"\compilers\PBCompiler.exe", compileroptions, GetCurrentDirectory(), #PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
If prog
While ProgramRunning(prog)
If AvailableProgramOutput(prog)
progoutput.s = ReadProgramString(prog)
If FindString(LCase(progoutput), "error",0)
wasanerror = 1
Error(progoutput)
SetForegroundWindow_(WindowID(0))
EndIf
AddGadgetItem(0,-1, progoutput)
Else
WaitWindowEvent(0)
EndIf
Wend
CloseProgram(prog)
AddGadgetItem(0,-1, "Compiler Closed")
Else
Error("Could Not execute PB compiler")
EndIf
CompilerIf #dontcloseonOKcompile = 1
WaitUntilWindowIsClosed()
CompilerElse
If wasanerror
WaitUntilWindowIsClosed()
EndIf
CompilerEndIf
You can also create another tool and add /EXE to the command arguments to create an exe/dll (you have to add .dll to the SaveFileRequester file field manually)"/FILE:%FILE" "/TEMPFILE:%TEMPFILE"
If you spot any problems (especially relating to Vista usage), or have any suggestions/requests, let me know!
