<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Automatically including a timestamp when building in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Automatically-including-a-timestamp-when-building/m-p/216553#M18841</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How would I include the date/time my code was built at so it could be printed by the software when requested?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried adding a -DTIME=%time% to the compliler options (%time% on Windows is a special env. var) but it's passed literally in (as though "#define TIME %time%").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using a define would seem to be the cleanest method; but I would also be content with including a file that was generated by some batch/Python script as part of the build process.&amp;nbsp; However, I don't know how to automatically run other things at build time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Aug 2010 02:48:11 GMT</pubDate>
    <dc:creator>NickT</dc:creator>
    <dc:date>2010-08-04T02:48:11Z</dc:date>
    <item>
      <title>Automatically including a timestamp when building</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Automatically-including-a-timestamp-when-building/m-p/216553#M18841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How would I include the date/time my code was built at so it could be printed by the software when requested?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried adding a -DTIME=%time% to the compliler options (%time% on Windows is a special env. var) but it's passed literally in (as though "#define TIME %time%").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using a define would seem to be the cleanest method; but I would also be content with including a file that was generated by some batch/Python script as part of the build process.&amp;nbsp; However, I don't know how to automatically run other things at build time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 02:48:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Automatically-including-a-timestamp-when-building/m-p/216553#M18841</guid>
      <dc:creator>NickT</dc:creator>
      <dc:date>2010-08-04T02:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically including a timestamp when building</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Automatically-including-a-timestamp-when-building/m-p/216554#M18842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you check following post?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.freescale.com/message/32584#32584" title="https://community.freescale.com/message/32584#32584"&gt;https://community.freescale.com/message/32584#32584&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This could be a solution to your request.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CrasyCat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 18:30:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Automatically-including-a-timestamp-when-building/m-p/216554#M18842</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2010-08-04T18:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically including a timestamp when building</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Automatically-including-a-timestamp-when-building/m-p/216555#M18843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Had some spare time to hack up a solution; here's what I cooked up with information borrowed from several other posts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Configure (Edit...)Standard Settings:&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Target/Target Settings&lt;/P&gt;&lt;P&gt;&amp;nbsp; --- Pre-linker: BatchRunner PreLinker&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Linker/BatchRunner PreLinker&lt;/P&gt;&lt;P&gt;&amp;nbsp; --- {Project}verstamp.bat&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. verstamp.bat in my Project root&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;python verstamp.py&lt;/PRE&gt;&lt;P&gt;3. verstamp.py in my Project root&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import sys
import os
import subprocess
import time

fname = 'verstamp'

cwpath = 'C:/Program Files/Freescale/CodeWarrior for Microcontrollers V6.3'
srcpath = './CODE'
objpath = './c6v2_Data/Standard/ObjectCode'

rev_code_only = True

cfile = '%s/%s.c' % (srcpath, fname)
ofile = '%s/%s.o' % (objpath, fname)

def main(argv=None):
    if argv is None:
        argv = sys.argv
   
    #datetimestamp = iso8601datetime(sdec=3)
    datetimestamp = time.strftime('%Y-%m-%d %H:%M:%S')
   
    # Running 'svnversion' on the entire project directory can take
    # a long time.  Probably TargetDataWindows.tdt, which causes a
    # significant pause when 'svn status' scans it.
    if rev_code_only:
        revstamp = subprocess.Popen(
            'svnversion %s' % srcpath,
            shell=True, 
            stdout=subprocess.PIPE).stdout.read().strip()
    else:
        revstamp = subprocess.Popen(
            'svnversion',
            shell=True, 
            stdout=subprocess.PIPE).stdout.read().strip()
   
    with open(cfile,'w') as fstamp:
        fstamp.write('// autogenerated file\n')
        fstamp.write('const char bldDateTime[] = "Built on: %s";\n'
                        % datetimestamp)
        fstamp.write('const char bldSVNRev[]   = "SVN rev : %s";\n'
                        % revstamp)

    # echo generated file
    with open(cfile) as f:
        for line in f.readlines(): print line,
       
    # compile file
    subprocess.call(' '.join([
        r'"%s/prog/chc08.exe"' % cwpath,        # compiler
        r'"%s"' % cfile,                        # - file to compile
        r'-I"%s/lib/hc08c/include"' % cwpath,   # - include path
        r'-Cs08',                               # - HCS08 core
        r'-Ms',                                 # - small memory model
        r'-D__NO_FLOAT__',                      # - #defines
        r'-WmsgFbv',                            # - verbose message file
        r'-WmsgFob"%f%e(%l): %k %d: %m\n"'      # - message format
        ]))

    # (just leave the .o file with the code...it's found by the linker fine)
    #os.remove(ofile)
    #os.rename(cfile, ofile)
   
if __name__ == "__main__":
    sys.exit(main())
&lt;/PRE&gt;&lt;P&gt;4. Was using PE so had to(?) disable the PRM file generation under the CPU/Build Options/Generate PRM File = No. (This was after it was initially generated)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. Added this snippet to the end of the PRM so it would link my compiled object file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ENTRIES verstamp.o:* END&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't &lt;EM&gt;fully&lt;/EM&gt; understand the build process, so this is a dirty hack, but it gets the SVN revision (and date/time) that the project was compiled with into the binary, so...success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Aug 2010 22:18:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Automatically-including-a-timestamp-when-building/m-p/216555#M18843</guid>
      <dc:creator>NickT</dc:creator>
      <dc:date>2010-08-18T22:18:10Z</dc:date>
    </item>
  </channel>
</rss>

