LP-89 - Port OP_15.05.01 fixes. Release notes:
[librepilot.git] / flight / libraries / PyMite / platform / openpilot_sitl / SConscript
blob2d00f7aecbb122294ebed9f58d7445d324e7046a
1 import os
2 import glob
4 TCHAIN = "arm-eabi"
5 #TCHAIN = "arm-elf"
6 #TCHAIN = "arm-none-eabi"
8 Import("vars")
10 vars.Add("PM_UART_BAUD", "Baud rate of the ipm serial connection.", "19200")
11 vars.Add("IPM", "Add the interactive library to the standard lib", True)
12 vars.Add("MCU", "Type of ARM device; the arg to -mcpu.", "cortex-m3")
13 vars.Add("NM", "", "arm-eabi-nm")
14 vars.Add("OBJCOPY", "", "%s-objcopy" % TCHAIN)
15 vars.Add("OBJDUMP", "", "%s-objdump" % TCHAIN)
16 vars.Add("SIZE", "", "%s-size" % TCHAIN)
17 #vars.Add("DEBUG","", True)
19 CFLAGS = " -DUART_BAUD=$PM_UART_BAUD -Dgcc" \
20          " -DUSE_STDPERIPH_DRIVER -DSTM32F10X_HD" \
21          " -Wall -Wimplicit" \
22          " -mcpu=$MCU -mthumb -Os -fomit-frame-pointer -mlittle-endian" \
23          " -ffunction-sections -fdata-sections -fno-strict-aliasing"
24          
25 LDFLAGS = "-mcpu=$MCU -mthumb -Wl,-T -Xlinker src/platform/stm32/stm32f10x.ld" \
26           " -u _start-Wl,-e,Reset_Handler -Wl,-static -Wl,--gc-sections" \
27           " -nostartfiles -Wl,--allow-multiple-definition"
28           
29 AFLAGS = "-x assembler-with-cpp $_CPPINCFLAGS -mcpu=$MCU -mthumb -Wall -c"
31 if "DEBUG" in vars.args.keys():
32     CFLAGS = "-g -gstabs -D__DEBUG__=1 " + CFLAGS
34 SOURCES = ["main.c", "plat.c", "stm32f10x_it.c", "syscalls.c"]
35 SOURCES += glob.glob("FWlib/src/*.c")
36 SOURCES += glob.glob("FWlib/src/*.s")
38 PY_SOURCES = ["main.py"]
39 PM_LIB_ROOT = ["pmvm_%s" % vars.args["PLATFORM"]]
41 env = Environment(variables = vars,
42                   CPPPATH = ["#src/vm", "#src/platform/stm32", "#src/platform/stm32/FWlib/inc"],
43                   CC = "%s-gcc" % TCHAIN,
44                   AS =  "%s-gcc" % TCHAIN,
45                   ASFLAGS = AFLAGS,
46                   CCFLAGS = CFLAGS,
47                   CXX = "%s-g++" % TCHAIN,
48                   AR = "%s-ar" % TCHAIN,
49                   ARFLAGS = "rcs",
50                   RANLIB = "%s-ranlib" % TCHAIN,
51                   LINKFLAGS = LDFLAGS,
52                   ENV = os.environ)
53                 
54 vmlib = SConscript(["../../vm/SConscript"], ["env", "vars"])
56 pmfeatures = env.Command(["pmfeatures.h"], ["pmfeatures.py"], 
57     "src/tools/pmGenPmFeatures.py $SOURCE > $TARGET")
59 img_sources = env.Command(["main_img.c", "main_nat.c"], [PY_SOURCES],
60     "src/tools/pmImgCreator.py -f src/platform/stm32/pmfeatures.py -c -u " \
61     "-o src/platform/stm32/main_img.c " \
62     "--native-file=src/platform/stm32/main_nat.c $SOURCES")
64 elf = env.Program("main.elf", SOURCES + img_sources + vmlib,
65                   LIBS = [PM_LIB_ROOT,"c","gcc","m"], LIBPATH = ["../../vm"])
67 bin = env.Command("main.bin", "main.elf", "$OBJCOPY -O binary $SOURCE $TARGET")