How to ship or export an sdl project made in codeblocks - c++11

The project uses external image files and codeblocks is configured to find the library and header files for SDL. How can I turn the project into a format so that it can be easily shipped ? I intend to create a single executable file or an installer which is portable .
How can I do this ?

I've done that many times.
You just have to put the necessary DLLs (I use SDL 1.2, so SDL.dll, SDL_image.dll,zlib.dll, ...) where the executable is, which may be not so good with codeblocks/VC++ tree and the Debug/bin & Release/bin directories but would work with a .bat file which could run the executable.
OR
Consider that your development project is NOT the one the users will see.
Do you think that Microsoft guys code all system32 commands in one single source directory?
So develop however you like and then create a deliver script to put everything in the root directory. Like that you don't have the constraints of delivered product while you are developping and reverse.
I recommend this approach.
Checkout My bagman SDL remake to see what I mean
When I create the archive for distribution, I use a custom script that I include here. This one has all the works, libmpeg for mp3 decompression, and all. If you unzip the Bagman archive, it works right away on a windows PC.
Here's my directory tree
Bagman\bin
Bagman\exploit
Bagman\icons
Bagman\music
Bagman\obj
Bagman\resource
Bagman\sound
Bagman\src
Bagman\work
Bagman\bin\Debug
Bagman\bin\Debug256
Bagman\bin\Release
Bagman\exploit\mkf
Bagman\obj\Amiga
Bagman\obj\Debug
Bagman\obj\Debug256
Bagman\obj\NDS
Bagman\obj\NDSEMU
Bagman\obj\Release
Bagman\obj\Debug\src
Bagman\obj\Debug\src\characters
Bagman\obj\Debug\src\engine
Bagman\obj\Debug\src\gfx
Bagman\obj\Debug\src\screens
Bagman\obj\Debug\src\sys
Bagman\obj\Debug256\src
Bagman\obj\Debug256\src\characters
Bagman\obj\Debug256\src\engine
Bagman\obj\Debug256\src\gfx
Bagman\obj\Debug256\src\sys
Bagman\obj\NDS\src
Bagman\obj\NDS\src\characters
Bagman\obj\NDS\src\engine
Bagman\obj\NDS\src\gfx
Bagman\obj\NDS\src\sys
Bagman\obj\NDSEMU\src
Bagman\obj\NDSEMU\src\characters
Bagman\obj\NDSEMU\src\engine
Bagman\obj\NDSEMU\src\gfx
Bagman\obj\NDSEMU\src\sys
Bagman\obj\Release\src
Bagman\obj\Release\src\characters
Bagman\obj\Release\src\engine
Bagman\obj\Release\src\gfx
Bagman\obj\Release\src\sys
Bagman\resource\1x
Bagman\resource\maps
Bagman\resource\1x\images
Bagman\resource\1x\sprites
Bagman\src\characters
Bagman\src\engine
Bagman\src\gfx
Bagman\src\screens
Bagman\src\sys
Here's the python script that copies all necessary files in the user archive:
import sys,os,zipfile,re,shutil,glob
import find,which # custom modules I created myself
MODULE_FILE = sys.modules[__name__].__file__
PROGRAM_DIR = os.path.abspath(os.path.dirname(MODULE_FILE))
ROOTDIR=os.path.realpath(os.path.join(PROGRAM_DIR,os.pardir))
PRODUCT_NAME="Bagman"
music=False
dev=False
version = "1.2"
print("making archive for version "+version)
os.chdir(ROOTDIR)
archname=PRODUCT_NAME+"-win32-"+version+".zip"
zfn = os.path.join(ROOTDIR,os.pardir,archname)
if os.path.exists(zfn):
os.remove(zfn)
zf = zipfile.ZipFile(zfn,mode="w",compression=zipfile.ZIP_DEFLATED)
dll_list = ["SDL.dll","SDL_Mixer.dll"]+["smpeg.dll","libgcc_s_sjlj-1.dll","libstdc++-6.dll","libgcc_s_dw2-1.dll"] # MP3 playing needs the second part
items_list = ["bagman*.bat","*.cbp","*.dev","*.txt","COPYING","resource","exploit","sound","src"]
real_items_list = []
for i in items_list:
real_items_list.extend(glob.glob(i))
for d in dll_list:
print("processing '"+d+"'")
dp = which.which(d)
if len(dp)==0:
raise Exception("%s not found in PATH" % d)
zf.write(dp[0],arcname=PRODUCT_NAME+"/"+d)
for i in real_items_list:
print("processing '"+i+"'")
if os.path.isfile(i):
zf.write(i,arcname=PRODUCT_NAME+"/"+i)
else:
fnd = find.Find()
items = fnd.init(i)
for f in items:
if i == "resource" and os.path.basename(f) in ["settings","soundbank.bin"]:
pass
else:
fi = f.replace(os.sep,"/")[2:]
if os.path.isfile(fi):
if fi.endswith("~"):
pass
else:
zf.write(fi,arcname=PRODUCT_NAME+"/"+fi)
else:
zfi = zipfile.ZipInfo(PRODUCT_NAME+"/"+fi+"/")
zf.writestr(zfi, '')
zfi = zipfile.ZipInfo(PRODUCT_NAME+"/bin/")
zf.writestr(zfi, '')
zfi = zipfile.ZipInfo(PRODUCT_NAME+"/bin/Release/")
zf.writestr(zfi, '')
zfi = zipfile.ZipInfo(PRODUCT_NAME+"/bin/Debug/")
zf.writestr(zfi, '')
zf.write("bin/Release/bagman.exe",arcname=PRODUCT_NAME+"/bin/Release/bagman.exe")
zf.close()
I know that there are existing python modules which will help you achieve such things (distutils). I did not use them because I wasn't aware of them.

Related

Build translated Sphinx docs in separate directories

I work on a documentation that will be published in different languages. It is one of the reasons I use Sphinx.
I know how generate the translated version but with the setting described in the documentation, the resulting files replaces the ones that were generated before. Thus, when generating multiple translation, I have to move the files to another directory before doing anything else. It would be more practical (and easier to deploy) to generate the translations in separate directories.
Is there a way to tell Sphinx or the makefile that when I run
make -e SPHINXOPTS="-D language='(lang)'" (format)
the files have to be generated in /build/(format)/(lang) ?
For now, only the HTML build is used (and I doubt that something else will be used) so a specific solution would be accepted if it is not possible to do it globally.
Sphinx version is 1.4.6.
I found a working solution by replacing the Makefile by a custom Python script (build.py).
Using sys.argv, I emulate the make target behaviour. I added several options for the language. Using the subprocess module, precisely its call() function, I am able to run commands with a set of options. The script is based on a function that generates the command to be executed by subprocess.call():
def build_command(target, build_dir, lang=None):
lang_opt = []
if lang:
lang_opt = ["-D", "language='" + lang + "'"]
build_dir += "/" + lang
else:
build_dir += "/default"
return ["sphinx-build", "-b", target, "-aE"] + lang_opt + ["source", "build/" + build_dir]
It is the lang parameter that allows me to separate each language, independently of the target. Later in the code, I just run
subprocess.call(build_command(target, target, lang))
To build the documentation in the desired language with the specified target (usually, target = "html"). It can also emulate make gettext:
subprocess.call(build_command("gettext", "locale"))
And so on...
A better solution may exist, but at least this one will do the job.

How to get QMake to copy large data files only if they are updated

I have some large data files that need to be copied from source folders to build folders during our Qmake/QtCreator build. Since they are large, I only want the copy to happen for new/changed files. And I'd really like to avoid listing them all specifically in the project file. Here's what I've tried:
This attempt at copying data files fails because the DemoData folder is the target. Therefore the copy is not performed if files within the folder are added or changed. Only if the folder does not exist.
DemoData.commands = $$COPY_CMD $${SRC_DATA_DIR}DemoData $${BLD_DATA_DIR}DemoData
DemoData.target += $${BLD_DATA_DIR}DemoData
PRE_TARGETDEPS += $${BLD_DATA_DIR}DemoData
QMAKE_EXTRA_TARGETS += DemoData
This approach fails because the DemoData.target item is not expected to have a list of multiple items. QMake puts the list in quotes in the generated makefile so it becomes one target.
DemoData.commands = $$COPY_CMD $${SRC_DATA_DIR}DemoData $${BLD_DATA_DIR}DemoData
DEMO_DATA_FILES = $$files($${SRC_DATA_DIR}DemoData/*)
for(FILE, DEMO_DATA_FILES){
DemoData.target += $${BLD_DATA_DIR}DemoData\\$$basename(FILE)
PRE_TARGETDEPS += $${BLD_DATA_DIR}DemoData\\$$basename(FILE)
}
QMAKE_EXTRA_TARGETS += DemoData
This attempt fails because (AFAICT) QMake does not support variable names contained in other variables. It seems to be more of a one level substitution. A makefile is generated, but the DemoDataX targets all have no command lines. All attempts to display the contents of the 'commands' field generate syntax errors.
DEMO_DATA_FILES = $$files($${SRC_DATA_DIR}DemoData/*)
DEMO_DATA_NAME = DemoData
for(FILE, DEMO_DATA_FILES){
$${DEMO_DATA_NAME}.target = $${FILE}
$${DEMO_DATA_NAME}.commands = $$COPY_CMD $${FILE} $${BLD_DATA_DIR}DemoData
PRE_TARGETDEPS += $${FILE}
QMAKE_EXTRA_TARGETS += $${DEMO_DATA_NAME}
DEMO_DATA_NAME = $${DEMO_DATA_NAME}X
}
This approach works, but with two shortcomings. The minor one is that a separate 'make install' step must be performed. The major one is that the files are always copied unconditionally. Since our data files are large, this is unacceptable timewise.
DemoData.path = $${BLD_DATA_DIR}DemoData
DemoData.files = $${SRC_DATA_DIR}DemoData/*
INSTALLS += DemoData
Is there a way to do this, or am I left with some sort of external script or manually generated/maintained makefile?
Use QMAKE_EXTRA_COMPILES feature.
# list your files in this variable.
# Masks are available with $$files functions but
# if your set of files changes (files added or removed)
# your have to re-run qmake after that explicitly, not just make
MYFILES = $$files($${PWD}/files/*.*)
copy_files.name = copy large files
copy_files.input = MYFILES
# change datafiles to a directory you want to put the files to
copy_files.output = $${OUT_PWD}/datafiles/${QMAKE_FILE_BASE}${QMAKE_FILE_EXT}
copy_files.commands = ${COPY_FILE} ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
copy_files.CONFIG += no_link target_predeps
QMAKE_EXTRA_COMPILERS += copy_files
Add your big files to MYFILES variable. For each file a rule will be generated in Makefile that copies file to specified directory (datafiles in the example). Original file will be listed as a dependecy in the rule (this is default qmake behaviour) so copy will occur only when original file is fresher than existing copy. Generated rules are listed as dependencies in the target file rule (copy_files.CONFIG += target_predeps) so copying will occur on every build automatically.
The only caveat is this: if your set of files is dynamic (files are added or removed) you can use masks as in my example but you have to be careful to execute qmake after changing the set. Be aware that Qt Creator builds projects by launching make, not qmake. The most simple way to ensure that qmake will be launched is to modify .pro file.
For those who can read Russian there is more info about QMAKE_EXTRA_COMPILERS here
Do you need the script to be cross platform? I personally wouldn't use the copy command, but robocopy on Windows and rsync on Mac/Linux.
win32: $${DEMO_DATA_NAME}.commands = robocopy $${SRC_DIR} $${DST_DIR} $${FILE} /MIR /XO
!win32: $${DEMO_DATA_NAME}.commands = rsync -aru $${FILE} $${BLD_DATA_DIR}
I'm not really sure what you want to copy here, but you get the idea, you can adapt the files and/or directories.
Robocopy parameters are described here.
/MIR Mirrors a directory tree
/XO Excludes older files.
Rsync parameters are described here.
-a Archive
-r Recursive
-u Update only when the source is newer
As a side note if you don't want to run this make install command, you can set this extra target as a dependency to the project that needs these files: theProjectNeedingThoseFiles.depends += DemoData.

Find files in project/solution that no longer exist

Visual Studio 2010 has a bug (or annoying behavior) that it always starts a new build for a project if it includes a reference to a (source) file that no longer exists (and subsequently all depending projects). Now I have a rather large project and the only way I know of to find such files is to manually open every file.
Is there an easier way to identify such invalid references in project files?
I wrote a python script that identifies missing files and prints them to the console.
import os
import re
import sys
def show_help():
print()
print("Syntax:", sys.argv[0], "[filename]")
print()
def check_missing_project_includes(filename):
f = open(filename, 'r')
p = re.compile('(ClCompile|ClInclude) Include="(.*?)" />', re.IGNORECASE)
missing_files = []
for line in f:
m = re.search(p, line)
if m:
filename = m.group(2)
if not os.path.exists(filename):
missing_files.append(filename)
return missing_files
if len(sys.argv) != 2:
show_help()
exit()
filename = sys.argv[1]
missing_files = check_missing_project_includes(filename)
if len(missing_files) > 0:
print("Missing files:")
for mf in missing_files:
print("\t", mf)
A technique that I've used to diagnose missing files is to install a SCC provider Addin (eg AnkhSVN if you're using Subversion), then in the Solution Explorer missing files will have a different icon. This isn't as useful for larger projects, but for smaller ones it's quite quick to see at a glance.
Have you tried opening the proj file in an editor like Notepad++ and locate and remove the references from there? (If I'm understanding the question correctly that is)

How can I set up an Xcode build rule with a variable output file list?

Build Rules are documented in the Xcode Build System Guide
They are well adapted to the common case where one input file is transformed into a fixed number (usually one) of output files.
The output files must be described in the "Output Files" area of the build rule definition; one line per output file. Typically the output files have the same name as the input file but have different extensions.
In my case, one single input file is transformed into a variable number of files with the same extensions. The number and the names of the output files depend on the content of the input file and are not known in advance.
The output files will have to be further processed later on (they are in this case C files to be compiled).
How can I set up a build rule for such a case?
Any suggestions welcome.
(I asked the same question on the Apple developer forum, but I figured it'd be a good idea to ask here too).
I dealt with this by, instead of generating multiple C files, just concatenating them all together into one file (e.g. "AUTOGENERATED.c"), and specifying that as the output file.
So long as your output files don't contain anything that will conflict (static functions with the same name, conflicting #defines etc.) this works well.
See this article on Cocoa With Love:
http://cocoawithlove.com/2010/02/custom-build-rules-generated-tables-and.html
This has an example of generating custom C code and using that as input to the normal build process. He's using ${} variable syntax in the output
The best way I found to add any number of files to my xcode project (and make some processing) is to write a little php script. The script can simply copy files into the bundle. The tricky part is the integration with xcode. It took me some time to find a clean way. (You can use the script language you like with this method).
First, use "Add Run Script" instead of "Add Copy File"
Shell parameter:
/bin/sh
Command parameter:
${SRCROOT}/your_script.php -s ${SRCROOT} -o ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
exit $?
(screenshot in xcode)
${SRCROOT} is your project directory.
${CONFIGURATION(...) is the bundle directory. Exactly what you need :)
This way, your script return code can stop xcode build (use die(0) for success and die(1) for failures) and the output of script will be visible in xcode's build log.
Your script will look like that: (don't forget chmod +x on it)
#!/usr/bin/php
<?php
error_reporting(E_ALL);
$options = getopt("s:o:");
$src_dir = $options["s"]."/";
$output_dir = $options["o"]."/";
// process_files (...)
die(0);
?>
BONUS: here my 'add_file' function.
Note the special treatment for PNG (use apple's png compression)
Note the filemtime/touch usage to prevent copy files each times.
l
define("COPY_PNG", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/copypng -compress");
function add_file_to_bundle($output_dir, $filepath) {
// split path
$path_info = pathinfo($filepath);
$output_filepath = $output_dir.$path_info['basename'];
// get file's dates of input and output
$input_date = filemtime($filepath);
$output_date = #filemtime($output_filepath);
if ($input_date === FALSE) { echo "can't get input file's modification date"; die(1); }
// skip unchanged files
if ($output_date === $input_date) {
//message("skip ".$path_info['basename']);
return 0;
}
// special copy for png with apple's png compression tool
if (strcasecmp($path_info['extension'], "png") == 0) {
//message($path_info['basename']." is a png");
passthru(COPY_PNG." ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var);
if ($return_var != 0) die($return_var);
}
// classic copy
else {
//message("copy ".$path_info['basename']);
passthru("cp ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var);
if ($return_var != 0) die($return_var);
}
// important: set output file date with input file date
touch($output_filepath, $input_date, $input_date);
return 1;
}

How do I find iTunes library folder on Mac and Windows?

I made an application that parse the iTunes library to retrieve its content. It works fine in most cases but if a user moved his library somewhere else than the default iTunes folder (see: http://lifehacker.com/238296/ultranewb--how-to-move-your-itunes-library-to-an-external-drive), then I need a way to find this path.
On Mac, I was looking into ~/Library/Preferences/com.apple.iTunes.plist. There is a setting called "alis:1:iTunes Library Location" but it contains several parameters all concatenated and converted to hexadecimal.
On Windows, I found this file "C:\Documents and Settings\\Application Data\Apple Computer\iTunes\iTunesPrefs.xml" that contains a setting "iTunes Library XML Location:1" but this one is encoded.
Any help would be greatly appreciated.
Thanks!
On Windows, the iTunes Library XML Location:1 entry in iTunesPrefs.xml is a Base 64 encoded Unicode string, so you'll need to decode it before you can use it. On my PC, it decodes to C:\Documents and Settings\Emerick\My Documents\My Music\iTunes\iTunes Music Library.xml.
It should be relatively easy to decode this value using your language of choice; your platform may even provide utility libraries that make this trivial. In C#, for example, the decoding function would look something like this:
static public string DecodeBase64(string encodedData)
{
byte[] encodedBytes = System.Convert.FromBase64String(encodedData);
return System.Text.UnicodeEncoding.Unicode.GetString(encodedBytes);
}
I can't help you with the Windows stuff, but on the Mac what you're seeing in that prefs file is old-school alias handle data. Take a look at or just use Chris Hanson's BDAlias class to convert it to a path.
http://github.com/rentzsch/bdalias
As the others point out "alis:1:iTunes Library Location" is alias data. Here's how I find the path from the data in OS X using Python.
#!/usr/bin/env python
import commands, plistlib
from Carbon import File
from os.path import expanduser
PLIST_PATH = '~/Library/Preferences/com.apple.iTunes.plist'
PLIST_KEY = 'alis:1:iTunes Library Location'
def resolve_path_from_alias_data( alis ):
fs_ref = File.Alias( rawdata=alis ).FSResolveAlias( None )[0]
file_path = fs_ref.as_pathname()
return file_path
plist_str = commands.getoutput( '/usr/bin/plutil -convert xml1 -o - "' + expanduser( PLIST_PATH ) + '"' )
plist_data = plistlib.readPlistFromString( plist_str )
alis_data = plist_data[ PLIST_KEY ].data
file_path = resolve_path_from_alias_data( alis_data )
print repr( file_path )
Unfortunately, iTunes no longer uses "alis:1:iTunes Library Location" so this no longer works. Now iTunes 11 uses an entry called "RDoc:132:Documents" which seems to be completely different. I have posted a similar question with the appropriate iTunes 11 details.
Actually, my answer works just fine as of OS X 10.9.1. I'm not sure whether it stopped due to some error I made, or if Apple quietly reverted something. Either way, it's working again on my Mac.

Resources