~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
////////////////////////////////////////////////////////////////////////////////
//
// Code::Blocks new project wizard script
//
// Project: Atmel AVR project
// Author:  Brian Sidebotham
//
////////////////////////////////////////////////////////////////////////////////

// Global Vars
Processor <- _T("");     // The chosen processor
AvrHex <- false;         // produce Hex file from ELF output ?
AvrSrec <- false;              // produce Motorola S-Record files?
AvrBin <- false;               // produce Binary image files?
AvrLss <- false;         // produce extended list file from ELF output?
AvrMap <- false;         // produce Symbol Map file from ELF output?
AvrExtMem <- false;      // Locate .data in on-board SRAM, or external SRAM
AvrExtMemAddr <- ""      // The external memory address
AvrSize <- false;        // Run avr-size after the build 
AvrF_CPU <- false;       // Define F_CPU?
AvrF_CPUValue <- _T(""); // F_CPU textual value
 
function BeginWizard()
{
    local wiz_type = Wizard.GetWizardType();

    if (wiz_type == wizProject)
    {
        local intro_msg = _T("Welcome to the new Atmel AVR project wizard!\n" +
                             "This wizard will guide you to create a new Atmel AVR project.\n\n" +
                             "When you 're ready to proceed, please click \"Next\"...");

        Wizard.AddInfoPage(_T("AtmelAVRIntro"), intro_msg);
        Wizard.AddProjectPathPage();
        Wizard.AddCompilerPage(_T("GNU AVR GCC Compiler"), _T("avr*"), false, true);
        Wizard.AddPage(_T("processorChoice"));        
    }
    else
        print(wiz_type);
}

function GetFilesDir()
{
    local result = _T("avr/files");
    return result;
}

////////////////////////////////////////////////////////////////////////////////
// Processor choice page
////////////////////////////////////////////////////////////////////////////////


function OnLeave_processorChoice(fwd)
{
    if (fwd)
    {
        Processor = Wizard.GetComboboxStringSelection(_T("comboboxProc"));
        AvrHex = Wizard.IsCheckboxChecked(_T("checkboxHex"));
        AvrSrec = Wizard.IsCheckboxChecked(_T("checkboxSrec"));
        AvrBin = Wizard.IsCheckboxChecked(_T("checkboxBin"));
        AvrMap = Wizard.IsCheckboxChecked(_T("checkboxMap"));
        AvrLss = Wizard.IsCheckboxChecked(_T("checkboxLss"));
        AvrExtMem = Wizard.IsCheckboxChecked(_T("checkboxExtMem"));
        AvrExtMemAddr = Wizard.GetTextControlValue(_T("textctrlExtMem"));        
        AvrSize = Wizard.IsCheckboxChecked(_T("checkboxAvrSize"));
        AvrF_CPU = Wizard.IsCheckboxChecked(_T("checkboxF_CPU"));
        AvrF_CPUValue = Wizard.GetTextControlValue(_T("textctrlF_CPU"));
    }
    return true;
}

function SetupProject(project)
{   
    // Linker options 
        local lo_map = ::wxString();
        local lo_extmem = ::wxString();
    
    // Post Build steps
    local pb_avrsize = ::wxString();
    local pb_eephex = ::wxString();
    local pb_hex = ::wxString();
    local pb_eepbin = ::wxString();
    local pb_bin = ::wxString();
    local pb_eepsrec = ::wxString();
    local pb_srec = ::wxString();    
    local pb_lss = ::wxString();

        // Post build commands
        pb_eephex = _T("avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.hex");
        pb_hex = _T("avr-objcopy -O ihex -R .eeprom -R .eesafe $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).hex");
        pb_eepbin = _T("avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O binary $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.bin");
        pb_bin = _T("avr-objcopy -O binary -R .eeprom -R .eesafe $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).bin");
        pb_eepsrec = _T("avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O srec $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.srec");
        pb_srec = _T("avr-objcopy -O srec -R .eeprom -R .eesafe $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).srec");

        if ( PLATFORM == PLATFORM_MSW )
            pb_lss = _T("cmd /c \"avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_FILE).lss\"");
        else
            pb_lss = _T("avr-objdump -h -S $(TARGET_OUTPUT_FILE) > $(TARGET_OUTPUT_FILE).lss");

        // avr-size is compiled with patches under winavr to produce a fancy output
        // which displays the percentage of memory used by the application for the 
        // target mcu. However, this option is not available under standard binutils
        // avr-size.
        if (PLATFORM_MSW == PLATFORM)
            pb_avrsize = _T("avr-size --mcu=") + Processor + _T(" --format=avr $(TARGET_OUTPUT_FILE)");
        else
            pb_avrsize = _T("avr-size $(TARGET_OUTPUT_FILE)");

        // Setup the linker options
        lo_map = _T("-Wl,-Map=$(TARGET_OUTPUT_FILE).map,--cref");
        
        // Get external memory start address
        lo_extmem = _T("-Wl,--section-start=.data=") + AvrExtMemAddr;
                
    // Project compiler options
    WarningsOn(project, Wizard.GetCompilerID());
        project.AddCompilerOption(_T("-mmcu=") + Processor);
        
        if (AvrF_CPU)
            project.AddCompilerOption(_T("-DF_CPU=") + AvrF_CPUValue);
            
        // Project linker options
        project.AddLinkerOption(_T("-mmcu=") + Processor);
        
        if (AvrMap)
            project.AddLinkerOption(lo_map);
        
        if (AvrExtMem)
            project.AddLinkerOption(lo_extmem);
        
        // Project post-build steps 
        if (AvrSize)
            project.AddCommandsAfterBuild(pb_avrsize);
                    
        if (AvrHex)
        {
            project.AddCommandsAfterBuild(pb_hex);
            project.AddCommandsAfterBuild(pb_eephex);
        }

        if (AvrSrec)
        {
            project.AddCommandsAfterBuild(pb_srec);
            project.AddCommandsAfterBuild(pb_eepsrec);
        }

        if (AvrBin)
        {
            project.AddCommandsAfterBuild(pb_bin);
            project.AddCommandsAfterBuild(pb_eepbin);
        }

        if ( AvrLss )
            project.AddCommandsAfterBuild(pb_lss);


    // Debug build target
    local target = project.GetBuildTarget(Wizard.GetDebugName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttConsoleOnly);
        target.SetTargetFilenameGenerationPolicy(tgfpPlatformDefault, tgfpNone);
        target.SetOutputFilename(Wizard.GetDebugOutputDir() + Wizard.GetProjectName() + _T(".elf"));
        DebugSymbolsOn(target, Wizard.GetCompilerID());
    }

    // Release build target
    target = project.GetBuildTarget(Wizard.GetReleaseName());
    if (!IsNull(target))
        {
            target.SetTargetType(ttConsoleOnly);
            target.SetTargetFilenameGenerationPolicy(tgfpPlatformDefault, tgfpNone);
            target.SetOutputFilename(Wizard.GetReleaseOutputDir() + Wizard.GetProjectName() + _T(".elf"));
            OptimizationsOn(target, Wizard.GetCompilerID());
        }
        
    return true;
}