Author Topic: Portable Code::Blocks  (Read 165561 times)

mrTeoc

  • Guest
Re: Portable Code::Blocks
« Reply #15 on: April 14, 2009, 03:40:26 am »
This is great! I really needed this, because I get to work on random pcs very often.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Portable Code::Blocks
« Reply #16 on: April 14, 2009, 06:01:55 am »
I think the CbLauncher.exe 0.11 version should be uploaded so the people don't need to download the whole package from:

http://files.filefront.com/Portable+CB+5526+bin7z/;13582845;/fileinfo.html

I've uploaded it to my blog. You can download it from the following link-

Quote
http://biplab.in/2009/04/creating-portable-codeblocks-part-2/

I've also written steps to launch C::B nightlies (> rev 5534) in a portable manner using CbLauncher in the above post.
Be a part of the solution, not a part of the problem.

Offline rokan1

  • Single posting newcomer
  • *
  • Posts: 3
Re: Portable Code::Blocks
« Reply #17 on: April 16, 2009, 05:16:28 pm »
I made a small batch file which temporarily modifies essential environment variables to make "portable" version not only for codeblocks but also msys and mingw.
Assuming that you have copied the tools to /MingW and /msys and /codeblocks on your usb you can copy the following script to eg portable.bat on your usb.
After running this bat file, just type codeblocks and everything should work fine - if it touches configuration files, it uses the locations within USB.
Be sure you set $(CODEBLOCKS)/../Mingw as the location for the gcc toolchain.
You can also change cmd.exe to codeblocks.exe in the last line of this batch file to start codeblocks immediately.

Code
@echo off

echo Setting environment variables and checking for directories availability:
:: Get the current batch fille drive and set it as homedrive
for %%x in (%0) do set HOMEDRIVE=%%~dsx
set HOMEDRIVE

:: Set user as USERNAME
set USERNAME=user
set USERNAME


:: Set \home\%USERNAME% as HOMEPATH and assure the directory exists
mkdir %HOMEDRIVE%\home
set HOMEPATH=\home\%USERNAME%
set HOMEPATH
mkdir %HOMEDRIVE%%HOMEPATH%
mkdir "%HOMEDRIVE%%HOMEPATH%\Desktop

:: Set %HOMEDRIVE%%HOMEPATH% as USERPROFILE
set USERPROFILE=%HOMEDRIVE%%HOMEPATH%
set USERPROFILE

::set %HOMEDRIVE%%HOMEPATH%\ApplicationData as APPDATA
set APPDATA=%HOMEDRIVE%%HOMEPATH%\ApplicationData
set APPDATA
mkdir %APPDATA%


:: Set %HOMEDRIVE%\home\AllUsers as ALLUSERSPROFILE and assure it exists
set ALLUSERSPROFILE=%HOMEDRIVE%\home\AllUsers
set ALLUSERSPROFILE
mkdir %ALLUSERSPROFILE%


echo Adding %HOMEDRIVE%\MinGW\bin;%HOMEDRIVE%\msys\1.0\bin;%HOMEDRIVE%\codeblocks to the PATH
set PATH=%HOMEDRIVE%\MinGW\bin;%HOMEDRIVE%\msys\1.0\bin;%HOMEDRIVE%\codeblocks;%PATH%
set PATH

CALL cmd.exe



Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Portable Code::Blocks
« Reply #18 on: April 16, 2009, 05:29:50 pm »
I made a small batch file which temporarily modifies essential environment variables to make "portable" version not only for codeblocks but also msys and mingw.
Assuming that you have copied the tools to /MingW and /msys and /codeblocks on your usb you can copy the following script to eg portable.bat on your usb.
After running this bat file, just type codeblocks and everything should work fine - if it touches configuration files, it uses the locations within USB.
Be sure you set $(CODEBLOCKS)/../Mingw as the location for the gcc toolchain.
You can also change cmd.exe to codeblocks.exe in the last line of this batch file to start codeblocks immediately.

Code
@echo off

echo Setting environment variables and checking for directories availability:
:: Get the current batch fille drive and set it as homedrive
for %%x in (%0) do set HOMEDRIVE=%%~dsx
set HOMEDRIVE

:: Set user as USERNAME
set USERNAME=user
set USERNAME


:: Set \home\%USERNAME% as HOMEPATH and assure the directory exists
mkdir %HOMEDRIVE%\home
set HOMEPATH=\home\%USERNAME%
set HOMEPATH
mkdir %HOMEDRIVE%%HOMEPATH%
mkdir "%HOMEDRIVE%%HOMEPATH%\Desktop

:: Set %HOMEDRIVE%%HOMEPATH% as USERPROFILE
set USERPROFILE=%HOMEDRIVE%%HOMEPATH%
set USERPROFILE

::set %HOMEDRIVE%%HOMEPATH%\ApplicationData as APPDATA
set APPDATA=%HOMEDRIVE%%HOMEPATH%\ApplicationData
set APPDATA
mkdir %APPDATA%


:: Set %HOMEDRIVE%\home\AllUsers as ALLUSERSPROFILE and assure it exists
set ALLUSERSPROFILE=%HOMEDRIVE%\home\AllUsers
set ALLUSERSPROFILE
mkdir %ALLUSERSPROFILE%


echo Adding %HOMEDRIVE%\MinGW\bin;%HOMEDRIVE%\msys\1.0\bin;%HOMEDRIVE%\codeblocks to the PATH
set PATH=%HOMEDRIVE%\MinGW\bin;%HOMEDRIVE%\msys\1.0\bin;%HOMEDRIVE%\codeblocks;%PATH%
set PATH

CALL cmd.exe


Thanks.
My question is:
Do I need the "CBLuncher.exe" supplied by BipLab to run CB?
Or I just type codeblocks.exe  as you said?

Thanks. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Portable Code::Blocks
« Reply #19 on: April 16, 2009, 05:37:59 pm »
@Rokan,

I haven't tried this. But having a complete development environment should be nice to many users. Thanks for sharing this.


@OllyDbg,

So far CbLauncher does the similar thing before launching Code::Blocks. Assuming the batch file is error free, you do not need CbLauncher.exe v0.1.1 to make C::B portable. You can use this batch file.
Be a part of the solution, not a part of the problem.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Portable Code::Blocks
« Reply #20 on: April 16, 2009, 05:44:24 pm »
@Rokan,

I haven't tried this. But having a complete development environment should be nice to many users. Thanks for sharing this.


@OllyDbg,

So far CbLauncher does the similar thing before launching Code::Blocks. Assuming the batch file is error free, you do not need CbLauncher.exe v0.1.1 to make C::B portable. You can use this batch file.

Thanks for the quick response. :D I will try it.

By the way, comparing a batch file with a exe file, I do prefer the former one, because it can be easily add to trunk. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Portable Code::Blocks
« Reply #21 on: April 16, 2009, 05:50:57 pm »
By the way, comparing a batch file with a exe file, I do prefer the former one, because it can be easily add to trunk. :D

You are forgetting that exe file has a corresponding source file which should not be difficult to add to trunk. Nobody will add a exe file to trunk unless absolutely necessary.
Be a part of the solution, not a part of the problem.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Portable Code::Blocks
« Reply #22 on: April 16, 2009, 05:58:25 pm »
By the way, comparing a batch file with a exe file, I do prefer the former one, because it can be easily add to trunk. :D

You are forgetting that exe file has a corresponding source file which should not be difficult to add to trunk. Nobody will add a exe file to trunk unless absolutely necessary.

Oh, yes. I really forget that. :D
I notices that there is an DLL file named "exchndl.dll" in the trunk\src\, I'm not sure why we need this file :shock:.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Portable Code::Blocks
« Reply #23 on: April 16, 2009, 06:00:48 pm »
exchndl.dll is used generate crash report for Code::Blocks on Windows.
Be a part of the solution, not a part of the problem.

Offline rokan1

  • Single posting newcomer
  • *
  • Posts: 3
Re: Portable Code::Blocks
« Reply #24 on: April 16, 2009, 11:06:38 pm »

Thanks.
My question is:
Do I need the "CBLuncher.exe" supplied by BipLab to run CB?
Or I just type codeblocks.exe  as you said?

Thanks. :D

No, you do not need CBLuncher.exe and all that jazz, just unpack standard codeblocks  (eg from nightly builds) to /codeblocks directory on USB

I have found a bug in codeblocks: It does not use APPDATA to store various .ini files, instead it uses hard-codded "Application Data" subdirectory within users directory, which causes messing the root (on USB) with various files. As a work-arround I have modified the directories on USB to look like "standard windows" ones (although I prefer short unix-like ones where you do not need to type quotes to get around that stupid spaces). The script launches codeblocks.exe and also command prompt with all variables set - where you can eg launch real bash shell from msys by typing "sh". Here is modified script expecting MinGW, msys, and codeblocks directories as before:

Code

@echo off


echo Setting environment variables and checking for directories availability:
:: Get the current batch fille drive and set it as homedrive
for %%x in (%0) do set HOMEDRIVE=%%~dsx
set HOMEDRIVE

:: Set user as USERNAME
set USERNAME=user
set USERNAME


:: Set \Documents and Settings\%USERNAME% as HOMEPATH and assure the directory exists
set HOMEPATH=\Documents and Settings\%USERNAME%
set HOMEPATH
mkdir "%HOMEDRIVE%%HOMEPATH%"
mkdir "%HOMEDRIVE%%HOMEPATH%\Desktop"

:: Set %HOMEDRIVE%%HOMEPATH% as USERPROFILE
set USERPROFILE=%HOMEDRIVE%%HOMEPATH%
set USERPROFILE



::set "%HOMEDRIVE%%HOMEPATH%\Application Data" as APPDATA
set APPDATA=%HOMEDRIVE%%HOMEPATH%\Application Data
mkdir "%APPDATA%"
set APPDATA



:: Set %HOMEDRIVE%\home\All Users as ALLUSERSPROFILE and assure it exists
set ALLUSERSPROFILE=%HOMEDRIVE%\Documents and settings\All Users
mkdir "%ALLUSERSPROFILE%"
mkdir "%ALLUSERSPROFILE%\Application Data"


echo Preppending %HOMEDRIVE%\MinGW\bin;%HOMEDRIVE%\msys\1.0\bin;%HOMEDRIVE%\codeblocks to the PATH
set PATH=%HOMEDRIVE%\MinGW\bin;%HOMEDRIVE%\msys\1.0\bin;%HOMEDRIVE%\codeblocks;%PATH%

start codeblocks.exe

cmd.exe



Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: Portable Code::Blocks
« Reply #25 on: April 17, 2009, 01:14:50 am »
Here is modified script expecting MinGW, msys, and codeblocks directories as before:
Notice that this script won't work on non-English Windows platforms.

@Biplab: Did you commit the sources for CbLauncher, too? I could not find them... Or do I need to use the one from the archive?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Portable Code::Blocks
« Reply #26 on: April 17, 2009, 02:00:13 am »
I have found a bug in codeblocks: It does not use APPDATA to store various .ini files, instead it uses hard-codded "Application Data" subdirectory within users directory, which causes messing the root (on USB) with various files.

Code::Blocks now uses APPDATA to save configuration files. Download a nightly (Rev > 5534) which will have this modification.


@Biplab: Did you commit the sources for CbLauncher, too? I could not find them... Or do I need to use the one from the archive?

No I didn't commit source of CbLauncher. It can be downloaded from my blog. If others have no objection, I can commit it to trunk.
Be a part of the solution, not a part of the problem.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: Portable Code::Blocks
« Reply #27 on: April 17, 2009, 07:10:14 am »
No I didn't commit source of CbLauncher. It can be downloaded from my blog. If others have no objection, I can commit it to trunk.
You can submit the tool in the "tools" sub-folder in src.

BTW: How does that work under Linux? If I got the changes right they are Windows only and under Linux it still uses the standard path's which would be not on (e.g.) a USB stick...?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Portable Code::Blocks
« Reply #28 on: April 17, 2009, 10:50:14 am »
BTW: How does that work under Linux? If I got the changes right they are Windows only and under Linux it still uses the standard path's which would be not on (e.g.) a USB stick...?!

On linux a simple script should be enough.

I just hacked one to use C::B compiled with C::B.

Put the following script inside the folder where the run.sh-script is and start it.
You might have to deal with LD_LIBRARY_PATH for a wxWidgets-installation, if you need to have it on the stick (or whatever), too.
But that's another thing and makes it not so easy to make C::B portable on linux.

If you have a C::B installed on the machine and all you want is to have portable configuration, you can use a call to codeblocks instead of running run.sh.

Code
#!/bin/sh

xhost +
export HOME=`pwd`
./run.sh
xhost -

By the way:
Instead of dealing with APPDATA and HOME (that seems to be a little hacky), it would be better (in my opinion) to pass an alternative conf-dir to C::B as start-parameter and provide a sdk-function that returns the actual used conf-dir (for the plugins or whatever needs it).

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Portable Code::Blocks
« Reply #29 on: April 19, 2009, 06:11:25 am »
No I didn't commit source of CbLauncher. It can be downloaded from my blog. If others have no objection, I can commit it to trunk.
You can submit the tool in the "tools" sub-folder in src.

BTW: How does that work under Linux? If I got the changes right they are Windows only and under Linux it still uses the standard path's which would be not on (e.g.) a USB stick...?!

I'll put that code in trunk.

Creating portable version on Linux is not easy. I mean you build binary on Fedora and then you can't expect that it will run fine on other system, e.g. Ubuntu. Yes, it's possible to ask Code::Blocks to save configuration file to any specified folder. I have made this change only for Windows where many people prefer portable application.


By the way:
Instead of dealing with APPDATA and HOME (that seems to be a little hacky), it would be better (in my opinion) to pass an alternative conf-dir to C::B as start-parameter and provide a sdk-function that returns the actual used conf-dir (for the plugins or whatever needs it).

Both way it's a hack. If you use APPDATA or HOME, you are asking Code::Blocks to use another directory by pointing to by modifying corresponding environmental variables locally. On the other hand if we provide it as an option, we are still asking it to use another folder as the configuration folder. Using well defined environment variable to save configuration is a standard procedure.
Be a part of the solution, not a part of the problem.