Skip to content

Instantly share code, notes, and snippets.

@4lehandro
Forked from mkuf/compile157.sh
Last active August 26, 2015 12:53
Show Gist options
  • Select an option

  • Save 4lehandro/6e75e87b57d003427c3f to your computer and use it in GitHub Desktop.

Select an option

Save 4lehandro/6e75e87b57d003427c3f to your computer and use it in GitHub Desktop.
compile Repetier-Firmware without GUI
#!/bin/bash
## compile Repetier-Firmware without GUI
##
## Before you start:
## Set ADIR to your ArduinoIDE-Directory
## Set GPP, GCC, AR, OC. These can either be the binaries from the ArduinoIDE or your Distro
##
## How to use:
## Place this file in the Repetier-Directory (besides Repetier.ino)
## cd to your Repetier-Dir
## to compile, execute './compile157.sh compile' (no output except errors)
## after compiling, you can upload the binary with './compile157.sh upload'
PROJECT=$(ls *.ino)
ADIR=/opt/arduino-1.5.7 #location of your arduino-ide
BDIR=./build
DUE=ttymxc3 #device-file under '/dev/'
case $1 in
upload)
/usr/bin/sudo stty -F /dev/${DUE} cs8 115200 hupcl
/usr/bin/sudo ${ADIR}/hardware/tools/bossac --port=${DUE} -U false -e -w -b ${BDIR}/${PROJECT}.cpp.bin -R
;;
*)
GPP=/usr/bin/arm-none-eabi-g++
GCC=/usr/bin/arm-none-eabi-gcc
AR=/usr/bin/arm-none-eabi-ar
OC=/usr/bin/arm-none-eabi-objcopy
GPPOPTS="-c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=157 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON" # -DUSB_MANUFACTURER=\"Unknown\" -DUSB_PRODUCT=\"Arduino Due\""
GCCOPTS="-c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=157 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON" # -DUSB_MANUFACTURER=\"Unknown\" -DUSB_PRODUCT=\"Arduino Due\""
INC_ALL="-I${ADIR}/hardware/arduino/sam/system/libsam -I${ADIR}/hardware/arduino/sam/system/CMSIS/CMSIS/Include/ -I${ADIR}/hardware/arduino/sam/system/CMSIS/Device/ATMEL/ -I${ADIR}/hardware/arduino/sam/cores/arduino -I${ADIR}/hardware/arduino/sam/variants/arduino_due_x"
INC_GPP="-I${ADIR}/hardware/arduino/sam/libraries/SPI"
INC_GCC=""
if [ -d "${BDIR}" ]; then
rm -rf ${BDIR}
fi
mkdir ${BDIR}
#========================
# Compile Repetier
#========================
#create mainfile
cat ${ADIR}/hardware/arduino/sam/cores/arduino/main.cpp > ${PROJECT}.cpp
cat ${PROJECT} >> ${PROJECT}.cpp
echo 'extern "C" void __cxa_pure_virtual() {while (true);}' >> ${PROJECT}.cpp
#compile application
for dot_cpp in $(ls *.cpp); do
${GPP} ${GPPOPTS} ${INC_ALL} ${INC_GPP} ${dot_cpp} -o ${BDIR}/${dot_cpp}.o
done
rm ${PROJECT}.cpp
#========================
# Compile Libraries
#========================
#arduino c libs
for dot_c in $(ls ${ADIR}/hardware/arduino/sam/cores/arduino/*.c ${ADIR}/hardware/arduino/sam/cores/arduino/avr/*.c); do
dot_c_out=$(echo ${dot_c} | sed -rs 's/.*\/(.*.c)/\1\.o/g')
${GCC} ${GCCOPTS} ${INC_ALL} ${dot_c} -o ${BDIR}/${dot_c_out}
${AR} rcs ${BDIR}/core.a ${BDIR}/${dot_c_out}
done
#arduino cpp libs
for dot_cpp in $(ls ${ADIR}/hardware/arduino/sam/cores/arduino/*.cpp ${ADIR}/hardware/arduino/sam/cores/arduino/USB/*.cpp ${ADIR}/hardware/arduino/sam/libraries/SPI/*.cpp); do
dot_cpp_out=$(echo ${dot_cpp} | sed -rs 's/.*\/(.*\.cpp)/\1.o/g')
${GPP} ${GPPOPTS} ${INC_ALL} ${dot_cpp} -o ${BDIR}/${dot_cpp_out}
${AR} rcs ${BDIR}/core.a ${BDIR}/${dot_cpp_out}
done
${GPP} ${GPPOPTS} ${INC_ALL} ${ADIR}/hardware/arduino/sam/variants/arduino_due_x/variant.cpp -o ${BDIR}/variant.cpp.o
#========================
# Create Binary
#========================
${GPP} -Os -Wl,--gc-sections -mcpu=cortex-m3 -T${ADIR}/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld -Wl,-Map,${BDIR}/${PROJECT}.cpp.map -o ${BDIR}/${PROJECT}.cpp.elf -L${BDIR} -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group ${BDIR}/syscalls_sam3.c.o ${BDIR}/Printer.cpp.o ${BDIR}/HAL.cpp.o ${BDIR}/Communication.cpp.o ${BDIR}/ui.cpp.o ${BDIR}/motion.cpp.o ${BDIR}/Commands.cpp.o ${BDIR}/${PROJECT}.cpp.o ${BDIR}/gcode.cpp.o ${BDIR}/Eeprom.cpp.o ${BDIR}/Extruder.cpp.o ${BDIR}/SDCard.cpp.o ${BDIR}/SdFat.cpp.o ${BDIR}/SPI.cpp.o ${BDIR}/variant.cpp.o ${ADIR}/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a ${BDIR}/core.a -Wl,--end-group
#========================
# Binary Copy
#========================
${OC} -O binary ${BDIR}/${PROJECT}.cpp.elf ${BDIR}/${PROJECT}.cpp.bin
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment