00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import os
00035
00036
00037 EnsureSConsVersion(1, 1)
00038
00039
00040
00041
00042
00043
00044
00045 opts = Options('custom.py')
00046 opts.Add(EnumOption('BOOTLDR', 'Determines bootloader type', 'msu',
00047 allowed_values=('msu','none')))
00048
00049
00050
00051 print "Creating a SCons build environment for Microchip C30 family"
00052 env = Environment(
00053
00054
00055
00056
00057 tools = ['gcc', 'gnulink', 'ar', 'zip', 'packaging'],
00058 options = opts,
00059
00060 CCCOM = '$CC -c -o $TARGET $CFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $SOURCES',
00061 CCCCOMSTR = 'Compiling $SOURCES',
00062 CCFLAGS = '-mcpu=${MCU} -Wall',
00063 ARFLAGS = 'rcs',
00064 ARSTR = 'Create static library: $TARGET',
00065 OBJSUFFIX = '.o',
00066 PROGSUFFIX = '.cof')
00067
00068
00069 env['ENV']['PATH'] = os.environ['PATH']
00070
00071
00072 if os.name == 'posix':
00073 print "Modifiying environment for Linux"
00074 incDirs = Split( """include
00075 /usr/pic30-elf/include
00076 /usr/share/pic30-support/generic/h
00077 /usr/share/pic30-support/pic24h/h
00078 """)
00079 libDirs = Split( """.
00080 lib
00081 """)
00082
00083 env.Replace(
00084 CPPPATH = incDirs,
00085 CC = 'pic30-elf-gcc',
00086 LIBPATH = libDirs,
00087 AR = 'pic30-elf-ar',
00088 LINK = 'pic30-elf-gcc',
00089 MCC_BASE = '/usr/share/pic30-support/pic24h/'
00090 )
00091
00092
00093
00094 b2h = Builder(action = 'pic30-elf-bin2hex $SOURCE',
00095 suffix = 'hex',
00096 src_suffix = 'cof')
00097 env.Append(BUILDERS = {'Hex' : b2h})
00098
00099 elif os.name == 'nt':
00100 print "Modifying environment for Windoze"
00101 incDirs = Split( """include
00102 """)
00103 libDirs = Split( """.
00104 lib
00105 """)
00106
00107 env.Replace(
00108 CPPPATH = incDirs,
00109 CC = 'pic30-gcc',
00110 LIBPATH = libDirs,
00111 AR = 'pic30-ar',
00112 LINK = 'pic30-gcc',
00113 MCC_BASE = 'c:\\PROGRA~1\\MICROC~1\\MPLABC~2\\support\\PIC24H'
00114 )
00115
00116
00117
00118 b2h = Builder(action = 'pic30-bin2hex $SOURCE',
00119 suffix = 'hex',
00120 src_suffix = 'cof')
00121 env.Append(BUILDERS = {'Hex' : b2h})
00122
00123
00124 dict = env.Dictionary()
00125 if dict['BOOTLDR'] == 'msu':
00126 env.Replace(
00127 LINKERSCRIPT = '--script=lkr' + os.sep + 'p${MCU}_bootldr.gld',
00128 LINKFLAGS = '-Wl,--heap=100,$LINKERSCRIPT',
00129 )
00130 else:
00131 env.Replace(
00132 LINKFLAGS = '-Wl,--heap=100,$LINKERSCRIPT',
00133 LINKERSCRIPT = '--script=${MCC_BASE}' + os.sep + 'gld' + os.sep + 'p${MCU}.gld',
00134 )
00135
00136
00137 env.SetOption('num_jobs', 2)
00138 print "Running with -j", env.GetOption('num_jobs')
00139
00140
00141 Help(opts.GenerateHelpText(env))
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 archiveFiles = [
00158 'Doxyfile',
00159 'Doxyfile_bob',
00160 'readme.txt',
00161 'runAStyle.bat',
00162 'SConstruct',
00163 'SConstruct.py',
00164 'SCons_build.py',
00165 'standard_header.txt',
00166 'bin',
00167 'bootloader',
00168 'docs',
00169 'esos',
00170 'hex',
00171 'lkr',
00172 'chap3',
00173 'chap4',
00174 'chap6',
00175 'chap7',
00176 'chap8',
00177 'chap9',
00178 'chap10',
00179 'chap11',
00180 'chap12',
00181 'chap13',
00182 'chap14',
00183 'chap15',
00184 'common',
00185 'include',
00186 'robotics',
00187 'explorer16_100p',
00188 'templates']
00189
00190
00191 archiveFileName = 'build/pic24_code_examples.zip'
00192
00193
00194 def buildTargetsSConscript(buildTargets, env, variantDirName):
00195 SConscript('SCons_build.py', exports='buildTargets env',
00196 variant_dir='build/' + env['MCU'] + "_" + variantDirName)
00197
00198
00199
00200 if 'zipit' in COMMAND_LINE_TARGETS:
00201
00202 SConscript('./templates/SConscript.py', 'env')
00203
00204 env.Command(Glob('docs/*'), Glob('common/*.c'), "doxygen")
00205
00206 zipNode = env.Zip(archiveFileName, archiveFiles)
00207 env.Alias('zipit', zipNode)
00208 else:
00209
00210 buildTargetsSConscript(['chap8', 'chap9', 'chap10', 'chap11', 'chap12'],
00211 env.Clone(MCU='24HJ32GP202'), 'default')
00212 buildTargetsSConscript(['chap8', 'chap9', 'chap10', 'chap11', 'chap12'],
00213 env.Clone(MCU='24FJ32GA002'), 'default')
00214
00215
00216 buildTargetsSConscript(['chap13', 'chap15'],
00217 env.Clone(MCU='24HJ64GP502'), 'default')
00218
00219
00220 buildTargetsSConscript(['chap15'],
00221 env.Clone(MCU='24FJ64GA002'), 'default')
00222
00223
00224 buildTargetsSConscript(['explorer'],
00225 env.Clone(MCU='24FJ128GA010', CPPDEFINES='EXPLORER16_100P'), 'default')
00226
00227
00228 for clock in ['SIM_CLOCK', 'FRCPLL_FCY16MHz', 'FRC_FCY4MHz',
00229 'PRI_NO_PLL_7372KHzCrystal', 'PRIPLL_8MHzCrystal_16MHzFCY']:
00230 buildTargetsSConscript(['reset'],
00231 env.Clone(MCU='24FJ64GA002', CPPDEFINES='CLOCK_CONFIG=' + clock), clock)
00232 for clock in ['SIM_CLOCK', 'PRI_NO_PLL_7372KHzCrystal', 'FRC_FCY3685KHz',
00233 'FRCPLL_FCY40MHz', 'PRIPLL_7372KHzCrystal_40MHzFCY', 'PRIPLL_8MHzCrystal_40MHzFCY']:
00234 buildTargetsSConscript(['reset'],
00235 env.Clone(MCU='24HJ32GP202', CPPDEFINES='CLOCK_CONFIG=' + clock), clock)