Friday, November 6, 2009

Shell scripting 101

I had to automate the build system today. The task was simple however my shell scripting knowledge is somewhat limited. I've done itsy-bitsy work on shell scripting but nothing extensive. Today in the process of automating the build I got to learn a few things, might be trivial but they were learning for me.

  • To check if the file already exists on the filesystem
    [ -f filename ] && echo"file exists"


  • To check if the directory exists on the filesystem
    [ -f dirname ] && echo"dir exists"


  • To copy the output of the command executed in the script to a variable.
    result=`pwd`


  • export command is used to set a environment variable.


  • Use = for comparisons not ==.
    if [ $name = "shiv" ];
    then
    echo "its me"
    fi


  • Use option "o" with unzip command to overwrite existing files without prompting.
    unzip -o myArchive.zip

  • Use option "r" to travel recurcively with zip command
    zip -r zipfilename sourcedir *


Following link points to a quick shell scripting reference.
http://www.opengroup.org/onlinepubs/007908799/xcu/shellix.html

Working with dylibs : Deployment Issues - Part 3

Read Part 1
Read Part 2

if you are using install_name_tool extensively. I'd recommend you use the linker flag -headerpad_max_install_names. Man page of ld describes this flag as follows.


-headerpad_max_install_names
Automatically adds space for future expansion of load commands such that all paths could expand to MAXPATHLEN. Only useful if intend to run install_name_tool to alter the load commands later. Size is a hexadecimal number.


Read Part 1
Read Part 2

Tuesday, November 3, 2009

Obtaining Current Date and Time

I had a simple task of adding a time stamp for a resource request. By time stamp I mean the year-date-time when the resource was requested. It was C++ code I did not want to add objective-c code in there. So the option I had was to use Core-Foundation CFDate or to use simple unix calls. I hate Carbon anyways, whenever I get a chance I try avoid it. Same was the case here. I used unix apis. They turned out be simple and did the job with charm.

Code snippet:

time_t currtime;
time(&currtime);

struct tm *dateAndTime = locattime(&currtime);

int year = 1900 + timedate->tm_year;
int month = dateAndTime->tm_mon+1;
int date = dateAndTime->tm_mday;
int hour = dateAndTime->tm_hour;
int min = dateAndTime->tm_min;
int sec = dateAndTime->tm_sec;

Now I can format the time-stamp string in any damn way I want. If objective-c was an option NSDate would have done the job for me.

Monday, November 2, 2009

Working with dylibs : Deployment Issues - Part 2

Read Part 1 of the post
Read Part 3 of the post

In addition to what I had already written on dylib deployment. My friend, Vishvesh, pointed out some additional notes.


  • dylib execution path can be specified in Xcode project "Installation Directory" field. Using this will not require to use complex command line tools to specify the dylib installation path [I have yet verified this].

  • otool when run against a static libraries (.a) lists all the object files.

  • Command file can be used to detect the architecture type a dylib or a static lib is built for.

    example :
    %file myCustom.dylib
    myCustom.dylib: Mach-O universal binary with 2 architectures
    myCustom.dylib(for architecture i386): Mach-O dynamically linked shared library i386
    myCustom.dylib(for architecture ppc): Mach-O dynamically linked shared library ppc


    %file libdoCustomProcessing.a
    libdoCustomProcessing.a: Mach-O universal binary with 2 architectures
    libdoCustomProcessing.a (for architecture i386): current ar archive
    libdoCustomProcessing.a (for architecture ppc): current ar archive



Read Part 1 of the post
Read Part 3 of the post

LinkWithin

Related Posts with Thumbnails