LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2005, 01:32 PM   #1
somnium
LQ Newbie
 
Registered: Jul 2003
Location: Suburbia
Distribution: Slackware
Posts: 26

Rep: Reputation: 15
Bash file naming in makefile


Hey guys,
I'm in need of a little help pertaining to bash scripts in my make file. Basically, what I would liek to do is have a script that increments and appended number everytime I compile the program, kind of an easy way to keep progressive builds in order.

kind of like binary-0.0.1, binary-0.0.2 and so forth.

Right now I just have the name of the binary into a variable that make uses in a cc line. I'm guessing I need a script that would read the variable string, find the last build number and increment it and use that to create the binary.


The other option is that I'm going about this the wrong way and there's an easier and/or better way of doing this that I'm just not seeing.

Either way, that's for the help

Last edited by somnium; 10-18-2005 at 01:40 PM.
 
Old 10-18-2005, 02:03 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
This is probably overkill, but I was bored... Just incorporate it into the Makefile using system command/calls. Use the "-d" to display it (in the compile command for instance) and the "-i" to increment. You may need to futz with the addition section to match how you want your revisioning system to work. At worst, it would require using cut...

Code:
#!/bin/bash

DATA_FILE="./.counter_data"

DisplayUsage ()
{
cat << EOF
Usage: $( basename $0 ) ( -d | -i )
   -d   Display the stored counter value
   -i   Increment the stored counter value
EOF
}

if [ $# -ne 1 ] ; then
  DisplayUsage
  exit 1
fi

case ${1} in
  -i)
    if [ ! -f ${DATA_FILE} ] ; then
      echo 0 > ${DATA_FILE}
    fi

    counter_value=$( cat ${DATA_FILE} )
    let counter_value=counter_value+1
    echo ${counter_value} > ${DATA_FILE}
  ;;

  -d)
    if [ ! -r ${DATA_FILE} ] ; then
      echo "Unable to read data file (${DATA_FILE})"
    else
      cat ${DATA_FILE}
    fi
  ;;

  *)
    echo "ERROR: unrecognized option: ${1}"
    DisplayUsage
    exit 1
  ;;
esac

exit 0

Last edited by Dark_Helmet; 10-18-2005 at 02:06 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to modify the file naming pattern (%s~) of backups LinToWinWin Linux - Software 1 10-11-2005 08:27 PM
mail server the naming naming convention problem kashan Linux - Newbie 0 07-16-2004 02:08 PM
naming a Tcl file liguorir Linux - Software 1 05-20-2004 08:47 PM
Samba file naming conventions ElectroLinux Linux - Newbie 3 03-10-2004 02:42 AM
File Naming Conventions mooreted Linux - Software 4 08-23-2003 10:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration