mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Support Arduino C++ on Windows. Move entire Makefile into template.
Also added the command shell console to the cdt 4.5 target so we can test the Arduino command shell. Change-Id: I185f9b39d23a6718204112e1fd4388c2458f7e5e
This commit is contained in:
parent
8292adcb90
commit
3688cd7f04
6 changed files with 255 additions and 222 deletions
|
@ -1,61 +1,66 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<?pde version="3.8"?><target name="cdt_e4.5" sequenceNumber="30">
|
<?pde version="3.8"?><target name="cdt_e4.5" sequenceNumber="35">
|
||||||
<locations>
|
<locations>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<unit id="org.apache.commons.compress" version="0.0.0"/>
|
<unit id="org.apache.commons.compress" version="0.0.0"/>
|
||||||
<unit id="org.apache.log4j" version="0.0.0"/>
|
<unit id="org.apache.log4j" version="0.0.0"/>
|
||||||
<unit id="org.apache.log4j.source" version="0.0.0"/>
|
<unit id="org.apache.log4j.source" version="0.0.0"/>
|
||||||
<unit id="net.sourceforge.lpg.lpgjavaruntime" version="0.0.0"/>
|
<unit id="net.sourceforge.lpg.lpgjavaruntime" version="0.0.0"/>
|
||||||
<unit id="org.junit" version="0.0.0"/>
|
<unit id="org.junit" version="0.0.0"/>
|
||||||
<unit id="org.junit.source" version="0.0.0"/>
|
<unit id="org.junit.source" version="0.0.0"/>
|
||||||
<unit id="org.mockito" version="0.0.0"/>
|
<unit id="org.mockito" version="0.0.0"/>
|
||||||
<unit id="org.hamcrest.core" version="0.0.0"/>
|
<unit id="org.hamcrest.core" version="0.0.0"/>
|
||||||
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/"/>
|
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/"/>
|
||||||
</location>
|
</location>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<unit id="org.eclipse.swtbot.eclipse.feature.group" version="0.0.0"/>
|
<unit id="org.eclipse.swtbot.eclipse.feature.group" version="0.0.0"/>
|
||||||
<unit id="org.eclipse.swtbot.feature.group" version="0.0.0"/>
|
<unit id="org.eclipse.swtbot.feature.group" version="0.0.0"/>
|
||||||
<unit id="org.eclipse.swtbot.eclipse.test.junit.feature.group" version="0.0.0"/>
|
<unit id="org.eclipse.swtbot.eclipse.test.junit.feature.group" version="0.0.0"/>
|
||||||
<repository location="http://download.eclipse.org/technology/swtbot/releases/latest/"/>
|
<repository location="http://download.eclipse.org/technology/swtbot/releases/latest/"/>
|
||||||
</location>
|
</location>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<unit id="org.eclipse.rse.feature.group" version="0.0.0"/>
|
<unit id="org.eclipse.rse.feature.group" version="0.0.0"/>
|
||||||
<repository location="http://download.eclipse.org/tm/updates/3.6milestones/"/>
|
<repository location="http://download.eclipse.org/tm/updates/3.6milestones/"/>
|
||||||
</location>
|
</location>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<unit id="org.eclipse.remote.feature.group" version="0.0.0"/>
|
<unit id="org.eclipse.remote.feature.group" version="0.0.0"/>
|
||||||
<unit id="org.eclipse.remote.serial.feature.group" version="0.0.0"/>
|
<unit id="org.eclipse.remote.serial.feature.group" version="0.0.0"/>
|
||||||
<repository location="http://download.eclipse.org/tools/ptp/builds/remote/2.0.0/"/>
|
<unit id="org.eclipse.remote.console.feature.group" version="0.0.0"/>
|
||||||
</location>
|
<repository location="http://download.eclipse.org/tools/ptp/builds/remote/2.0.0/"/>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
</location>
|
||||||
<unit id="org.eclipse.license.feature.group" version="0.0.0"/>
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<repository location="http://download.eclipse.org/cbi/updates/license/"/>
|
<unit id="org.eclipse.license.feature.group" version="0.0.0"/>
|
||||||
</location>
|
<repository location="http://download.eclipse.org/cbi/updates/license/"/>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
</location>
|
||||||
<unit id="org.eclipse.test.feature.group" version="0.0.0"/>
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<unit id="org.eclipse.sdk.ide" version="0.0.0"/>
|
<unit id="org.eclipse.test.feature.group" version="0.0.0"/>
|
||||||
<unit id="org.eclipse.equinox.executable.feature.group" version="0.0.0"/>
|
<unit id="org.eclipse.sdk.ide" version="0.0.0"/>
|
||||||
<repository location="http://download.eclipse.org/eclipse/updates/4.5milestones/"/>
|
<unit id="org.eclipse.equinox.executable.feature.group" version="0.0.0"/>
|
||||||
</location>
|
<repository location="http://download.eclipse.org/eclipse/updates/4.5milestones/"/>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
</location>
|
||||||
<unit id="org.eclipse.launchbar.feature.group" version="0.0.0"/>
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<repository location="https://hudson.eclipse.org/cdt/job/launchbar-master/lastSuccessfulBuild/artifact/repo/target/repository/"/>
|
<unit id="org.eclipse.launchbar.feature.group" version="0.0.0"/>
|
||||||
</location>
|
<repository location="https://hudson.eclipse.org/cdt/job/launchbar-master/lastSuccessfulBuild/artifact/repo/target/repository/"/>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
</location>
|
||||||
<unit id="org.eclipse.cdt.native.feature.group" version="0.0.0"/>
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<repository location="https://hudson.eclipse.org/cdt/job/cdt-master/lastSuccessfulBuild/artifact/releng/org.eclipse.cdt.repo/target/repository/"/>
|
<unit id="org.eclipse.cdt.native.feature.group" version="0.0.0"/>
|
||||||
</location>
|
<repository location="https://hudson.eclipse.org/cdt/job/cdt-master/lastSuccessfulBuild/artifact/releng/org.eclipse.cdt.repo/target/repository/"/>
|
||||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
</location>
|
||||||
<unit id="org.eclipse.linuxtools.docker.feature.feature.group" version="0.0.0"/>
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<repository location="http://download.eclipse.org/linuxtools/updates-docker-nightly/"/>
|
<unit id="org.eclipse.linuxtools.docker.feature.feature.group" version="0.0.0"/>
|
||||||
</location>
|
<repository location="http://download.eclipse.org/linuxtools/updates-docker-nightly/"/>
|
||||||
</locations>
|
</location>
|
||||||
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||||
<launcherArgs>
|
<unit id="org.eclipse.tm.terminal.control" version="0.0.0"/>
|
||||||
<vmArgs>-Xms40m
|
<repository location="http://download.eclipse.org/tm/terminal/builds/development/nightly/"/>
|
||||||
-Xmx512M
|
</location>
|
||||||
-XX:MaxPermSize=256m
|
</locations>
|
||||||
-ea</vmArgs>
|
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||||
<programArgs>-consolelog</programArgs>
|
<launcherArgs>
|
||||||
</launcherArgs>
|
<vmArgs>-Xms40m
|
||||||
</target>
|
-Xmx512M
|
||||||
|
-XX:MaxPermSize=256m
|
||||||
|
-ea</vmArgs>
|
||||||
|
<programArgs>-consolelog</programArgs>
|
||||||
|
</launcherArgs>
|
||||||
|
</target>
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
bin.includes = feature.xml,\
|
bin.includes = feature.xml,\
|
||||||
feature.properties
|
feature.properties
|
||||||
root = rootfiles
|
|
||||||
|
|
|
@ -1,113 +0,0 @@
|
||||||
VERSION = 156
|
|
||||||
|
|
||||||
BOARD ?= uno
|
|
||||||
OUTPUT_DIR ?= build/Default
|
|
||||||
|
|
||||||
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
|
|
||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
|
||||||
RMDIR = rmdir /s /q
|
|
||||||
fixpath = $(subst /,\,$1)
|
|
||||||
mymkdir = if not exist "$(call fixpath,$1)" mkdir $(call fixpath,$1)
|
|
||||||
else
|
|
||||||
RMDIR = rm -fr
|
|
||||||
fixpath = $1
|
|
||||||
mymkdir = mkdir -p $1
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(BOARD),uno)
|
|
||||||
ARCH = avr
|
|
||||||
BUILD_CORE = arduino
|
|
||||||
BUILD_VARIANT = standard
|
|
||||||
BUILD_MCU = atmega328p
|
|
||||||
BUILD_F_CPU = 16000000L
|
|
||||||
BUILD_BOARD = AVR_UNO
|
|
||||||
LOADER = avrdude
|
|
||||||
LOADER_PROTOCOL = arduino
|
|
||||||
LOADER_SPEED = 115200
|
|
||||||
LOADER_MAX_SIZE = 32256
|
|
||||||
LOADER_MAX_DATA = 2048
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(ARCH),avr)
|
|
||||||
CXXFLAGS = -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD \
|
|
||||||
-mmcu=$(BUILD_MCU) -DF_CPU=$(BUILD_F_CPU) -DARDUINO=$(VERSION) -DARDUINO_$(BUILD_BOARD) -DARDUINO_ARCH_AVR $(INCLUDES)
|
|
||||||
CFLAGS = -g -Os -w -ffunction-sections -fdata-sections -MMD \
|
|
||||||
-mmcu=$(BUILD_MCU) -DF_CPU=$(BUILD_F_CPU) -DARDUINO=156 -DARDUINO_$(BUILD_BOARD) -DARDUINO_ARCH_AVR $(INCLUDES)
|
|
||||||
|
|
||||||
CXX = avr-g++
|
|
||||||
CC = avr-gcc
|
|
||||||
AR = avr-ar
|
|
||||||
OBJCOPY = avr-objcopy
|
|
||||||
|
|
||||||
define do_link
|
|
||||||
$(CC) -Os -Wl,--gc-sections -mmcu=$(BUILD_MCU) -o $(OUTPUT_DIR)/$(EXE).elf $^
|
|
||||||
avr-objcopy -O ihex -R .eeprom $(OUTPUT_DIR)/$(EXE).elf $(OUTPUT_DIR)/$(EXE).hex
|
|
||||||
$(do_link_extra)
|
|
||||||
avr-size $(OUTPUT_DIR)/$(EXE).elf
|
|
||||||
@echo Max text: $(LOADER_MAX_SIZE)
|
|
||||||
@echo Max data + bss: $(LOADER_MAX_DATA)
|
|
||||||
endef
|
|
||||||
|
|
||||||
define do_eeprom
|
|
||||||
avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load \
|
|
||||||
--no-change-warnings --change-section-lma .eeprom=0 \
|
|
||||||
$(OUTPUT_DIR)/$(EXE).elf $(OUTPUT_DIR)/$(EXE).eep
|
|
||||||
endef
|
|
||||||
|
|
||||||
define do_load_avrdude
|
|
||||||
avrdude -C"$(ARDUINO_HOME)/hardware/tools/avr/etc/avrdude.conf" -p$(BUILD_MCU) -c$(LOADER_PROTOCOL) \
|
|
||||||
-P$(SERIAL_PORT) -b$(LOADER_SPEED) -D "-Uflash:w:$(OUTPUT_DIR)/$(EXE).hex:i"
|
|
||||||
endef
|
|
||||||
|
|
||||||
endif # ARCH = avr
|
|
||||||
|
|
||||||
LIB_ROOT = $(ARDUINO_HOME)/hardware/arduino/$(ARCH)/cores/$(BUILD_CORE)
|
|
||||||
|
|
||||||
LIB_SRCS = $(call rwildcard, $(LIB_ROOT)/, *.c *.cpp)
|
|
||||||
|
|
||||||
LIB_OBJS = $(patsubst $(LIB_ROOT)/%.c, $(OUTPUT_DIR)/arduino/%.o, $(filter %.c, $(LIB_SRCS))) \
|
|
||||||
$(patsubst $(LIB_ROOT)/%.cpp, $(OUTPUT_DIR)/arduino/%.o, $(filter %.cpp, $(LIB_SRCS)))
|
|
||||||
|
|
||||||
LIBS_ROOTS = $(ARDUINO_LIBS) $(ARDUINO_HOME)/hardware/arduino/$(ARCH)/libraries $(ARDUINO_HOME)/libraries
|
|
||||||
|
|
||||||
LIBS_DIRS = $(foreach lib, $(LIBS), $(firstword $(realpath $(foreach lib_root, $(LIBS_ROOTS), $(lib_root)/$(lib)))))
|
|
||||||
|
|
||||||
INCLUDES = -I$(ARDUINO_HOME)/hardware/arduino/$(ARCH)/cores/$(BUILD_CORE) \
|
|
||||||
-I$(ARDUINO_HOME)/hardware/arduino/$(ARCH)/variants/$(BUILD_VARIANT) \
|
|
||||||
$(foreach lib, $(LIBS_DIRS), -I$(lib))
|
|
||||||
|
|
||||||
SRCS = $(call rwildcard, ./, *.c *.cpp) $(foreach lib, $(LIBS_DIRS), $(wildcard $(lib)/*.c $(lib)/*.cpp $(lib)/utility/*.c $(lib)/utility/*.cpp))
|
|
||||||
|
|
||||||
OBJS = $(patsubst %.cpp, $(OUTPUT_DIR)/%.o, $(filter %.cpp, $(SRCS))) \
|
|
||||||
$(patsubst %.c, $(OUTPUT_DIR)/%.o, $(filter %.c, $(SRCS)))
|
|
||||||
|
|
||||||
all: $(OUTPUT_DIR)/$(EXE).hex
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RMDIR) $(call fixpath,$(OUTPUT_DIR))
|
|
||||||
|
|
||||||
load: #$(OUTPUT_DIR)/$(EXE).hex
|
|
||||||
$(do_load_$(LOADER))
|
|
||||||
|
|
||||||
$(OUTPUT_DIR)/$(EXE).hex: $(OBJS) $(OUTPUT_DIR)/core.a
|
|
||||||
$(do_link)
|
|
||||||
|
|
||||||
$(OUTPUT_DIR)/core.a: $(LIB_OBJS)
|
|
||||||
$(AR) r $@ $?
|
|
||||||
|
|
||||||
$(OUTPUT_DIR)/arduino/%.o: $(LIB_ROOT)/%.c
|
|
||||||
@-$(call mymkdir,$(dir $@))
|
|
||||||
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
$(OUTPUT_DIR)/arduino/%.o: $(LIB_ROOT)/%.cpp
|
|
||||||
@-$(call mymkdir,$(dir $@))
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
$(OUTPUT_DIR)/%.o: %.c
|
|
||||||
@-$(call mymkdir,$(dir $@))
|
|
||||||
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
|
|
||||||
|
|
||||||
$(OUTPUT_DIR)/%.o: %.cpp
|
|
||||||
@-$(call mymkdir,$(dir $@))
|
|
||||||
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
|
|
|
@ -11,39 +11,20 @@
|
||||||
package org.eclipse.cdt.arduino.core.internal;
|
package org.eclipse.cdt.arduino.core.internal;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
|
||||||
public class ArduinoHome {
|
public class ArduinoHome {
|
||||||
|
|
||||||
private static File home;
|
|
||||||
|
|
||||||
public static File getRootfileDir() {
|
|
||||||
if (home == null) {
|
|
||||||
String arduinoPathStr = System.getProperty("org.eclipse.cdt.arduino.home"); //$NON-NLS-1$
|
|
||||||
if (arduinoPathStr != null) {
|
|
||||||
home = new File(arduinoPathStr);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
home = new File(new File(Platform.getInstallLocation().getURL().toURI()), "arduino"); //$NON-NLS-1$
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
// TODO log
|
|
||||||
e.printStackTrace();
|
|
||||||
home = new File("nohome"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return home;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getArduinoDir() {
|
public static File getArduinoDir() {
|
||||||
return new File("/Applications/Arduino.app/Contents/Java"); //$NON-NLS-1$
|
switch (Platform.getOS()) {
|
||||||
}
|
case Platform.OS_MACOSX:
|
||||||
|
return new File("/Applications/Arduino.app/Contents/Java"); //$NON-NLS-1$
|
||||||
public static File getArduinoLibsDir() {
|
case Platform.OS_WIN32:
|
||||||
File home = new File(System.getProperty("user.home")); //$NON-NLS-1$
|
return new File("C:\\Program Files (x86)\\Arduino"); //$NON-NLS-1$
|
||||||
return new File(home, "/Documents/Arduino/libraries"); //$NON-NLS-1$
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
|
||||||
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
|
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
|
||||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
|
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
|
||||||
public class EnvVarSupplier implements IConfigurationEnvironmentVariableSupplier {
|
public class EnvVarSupplier implements IConfigurationEnvironmentVariableSupplier {
|
||||||
|
|
||||||
private EnvVar arduinoRoot;
|
|
||||||
private EnvVar arduinoHome;
|
private EnvVar arduinoHome;
|
||||||
private EnvVar arduinoLibs;
|
private EnvVar arduinoLibs;
|
||||||
private EnvVar path;
|
private EnvVar path;
|
||||||
|
@ -42,39 +42,41 @@ public class EnvVarSupplier implements IConfigurationEnvironmentVariableSupplier
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOperation() {
|
public int getOperation() {
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDelimiter() {
|
public String getDelimiter() {
|
||||||
return delimiter;
|
return delimiter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnvVarSupplier() {
|
private String clean(String str) {
|
||||||
arduinoRoot = new EnvVar();
|
return str.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
arduinoRoot.name = "ARDUINO_ROOT"; //$NON-NLS-1$
|
}
|
||||||
arduinoRoot.value = ArduinoHome.getRootfileDir().getAbsolutePath();
|
|
||||||
|
|
||||||
|
public EnvVarSupplier() {
|
||||||
arduinoHome = new EnvVar();
|
arduinoHome = new EnvVar();
|
||||||
arduinoHome.name = "ARDUINO_HOME"; //$NON-NLS-1$
|
arduinoHome.name = "ARDUINO_HOME"; //$NON-NLS-1$
|
||||||
arduinoHome.value = ArduinoHome.getArduinoDir().getAbsolutePath();
|
arduinoHome.value = clean(ArduinoHome.getArduinoDir().getAbsolutePath());
|
||||||
|
|
||||||
arduinoLibs = new EnvVar();
|
arduinoLibs = new EnvVar();
|
||||||
arduinoLibs.name = "ARDUINO_LIBS"; //$NON-NLS-1$
|
arduinoLibs.name = "ARDUINO_USER_LIBS"; //$NON-NLS-1$
|
||||||
arduinoLibs.value = ArduinoHome.getArduinoLibsDir().getAbsolutePath();
|
arduinoLibs.value = clean(System.getProperty("user.home") + "/Documents/Arduino/libraries"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
File avrPath = new File(ArduinoHome.getArduinoDir(), "hardware/tools/avr/bin"); //$NON-NLS-1$
|
|
||||||
String pathStr = avrPath.getAbsolutePath();
|
|
||||||
|
|
||||||
|
String avrDir = ArduinoHome.getArduinoDir().toString() + "/hardware/tools/avr/bin"; //$NON-NLS-1$
|
||||||
|
String installDir = Platform.getInstallLocation().getURL().getPath();
|
||||||
path = new EnvVar();
|
path = new EnvVar();
|
||||||
path.name = "PATH"; //$NON-NLS-1$
|
path.name = "PATH"; //$NON-NLS-1$
|
||||||
path.value = pathStr;
|
path.value = avrDir + File.pathSeparator + installDir;
|
||||||
path.operation = IBuildEnvironmentVariable.ENVVAR_PREPEND;
|
path.operation = IBuildEnvironmentVariable.ENVVAR_PREPEND;
|
||||||
path.delimiter = File.pathSeparator;
|
path.delimiter = File.pathSeparator;
|
||||||
}
|
}
|
||||||
|
@ -103,12 +105,10 @@ public class EnvVarSupplier implements IConfigurationEnvironmentVariableSupplier
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBuildEnvironmentVariable getVariable(String variableName,
|
public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration,
|
||||||
IConfiguration configuration, IEnvironmentVariableProvider provider) {
|
IEnvironmentVariableProvider provider) {
|
||||||
if (variableName.equals(path.name)) {
|
if (variableName.equals(path.name)) {
|
||||||
return path;
|
return path;
|
||||||
} else if (variableName.equals(arduinoRoot.name)) {
|
|
||||||
return arduinoRoot;
|
|
||||||
} else if (variableName.equals(arduinoHome.name)) {
|
} else if (variableName.equals(arduinoHome.name)) {
|
||||||
return arduinoHome;
|
return arduinoHome;
|
||||||
} else if (variableName.equals(arduinoLibs.name)) {
|
} else if (variableName.equals(arduinoLibs.name)) {
|
||||||
|
@ -122,12 +122,11 @@ public class EnvVarSupplier implements IConfigurationEnvironmentVariableSupplier
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBuildEnvironmentVariable[] getVariables(
|
public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration,
|
||||||
IConfiguration configuration, IEnvironmentVariableProvider provider) {
|
IEnvironmentVariableProvider provider) {
|
||||||
List<IBuildEnvironmentVariable> vars = new ArrayList<>();
|
List<IBuildEnvironmentVariable> vars = new ArrayList<>();
|
||||||
|
|
||||||
vars.add(path);
|
vars.add(path);
|
||||||
vars.add(arduinoRoot);
|
|
||||||
vars.add(arduinoHome);
|
vars.add(arduinoHome);
|
||||||
vars.add(arduinoLibs);
|
vars.add(arduinoLibs);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,165 @@
|
||||||
EXE = ${projectName}
|
EXE = ${projectName}
|
||||||
|
LIBS =
|
||||||
|
BOARD ?= uno
|
||||||
|
OUTPUT_DIR ?= build/$(BOARD)
|
||||||
|
|
||||||
include $(ARDUINO_ROOT)/arduino.mk
|
ifeq ($(BOARD),uno)
|
||||||
|
ARCH = avr
|
||||||
|
BUILD_CORE = arduino
|
||||||
|
BUILD_VARIANT = standard
|
||||||
|
BUILD_MCU = atmega328p
|
||||||
|
BUILD_F_CPU = 16000000L
|
||||||
|
BUILD_BOARD = AVR_UNO
|
||||||
|
LOADER = avrdude
|
||||||
|
LOADER_PROTOCOL = arduino
|
||||||
|
LOADER_SPEED = 115200
|
||||||
|
LOADER_MAX_SIZE = 32256
|
||||||
|
LOADER_MAX_DATA = 2048
|
||||||
|
endif
|
||||||
|
|
||||||
|
VERSION = 164
|
||||||
|
|
||||||
|
ifeq ($(ARCH),avr)
|
||||||
|
CXXFLAGS = -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD \
|
||||||
|
-mmcu=$(BUILD_MCU) -DF_CPU=$(BUILD_F_CPU) -DARDUINO=$(VERSION) -DARDUINO_$(BUILD_BOARD) -DARDUINO_ARCH_AVR $(INCLUDES)
|
||||||
|
CFLAGS = -g -Os -w -ffunction-sections -fdata-sections -MMD \
|
||||||
|
-mmcu=$(BUILD_MCU) -DF_CPU=$(BUILD_F_CPU) -DARDUINO=156 -DARDUINO_$(BUILD_BOARD) -DARDUINO_ARCH_AVR $(INCLUDES)
|
||||||
|
|
||||||
|
CXX = avr-g++
|
||||||
|
CC = avr-gcc
|
||||||
|
AR = avr-ar
|
||||||
|
OBJCOPY = avr-objcopy
|
||||||
|
|
||||||
|
define do_link
|
||||||
|
$(CC) -Os -Wl,--gc-sections -mmcu=$(BUILD_MCU) -o $(OUTPUT_DIR)/$(EXE).elf $^
|
||||||
|
avr-objcopy -O ihex -R .eeprom $(OUTPUT_DIR)/$(EXE).elf $(OUTPUT_DIR)/$(EXE).hex
|
||||||
|
$(do_link_extra)
|
||||||
|
avr-size $(OUTPUT_DIR)/$(EXE).elf
|
||||||
|
@echo Max text: $(LOADER_MAX_SIZE)
|
||||||
|
@echo Max data + bss: $(LOADER_MAX_DATA)
|
||||||
|
endef
|
||||||
|
|
||||||
|
define do_eeprom
|
||||||
|
avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load \
|
||||||
|
--no-change-warnings --change-section-lma .eeprom=0 \
|
||||||
|
$(OUTPUT_DIR)/$(EXE).elf $(OUTPUT_DIR)/$(EXE).eep
|
||||||
|
endef
|
||||||
|
|
||||||
|
define do_load_avrdude
|
||||||
|
avrdude -C"$(ARDUINO_HOME)/hardware/tools/avr/etc/avrdude.conf" -p$(BUILD_MCU) -c$(LOADER_PROTOCOL) \
|
||||||
|
-P$(SERIAL_PORT) -b$(LOADER_SPEED) -D "-Uflash:w:$(OUTPUT_DIR)/$(EXE).hex:i"
|
||||||
|
endef
|
||||||
|
|
||||||
|
endif # ARCH = avr
|
||||||
|
|
||||||
|
space :=
|
||||||
|
space +=
|
||||||
|
spacify = $(subst $(space),\$(space),$1)
|
||||||
|
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
RMDIR = rmdir /s /q
|
||||||
|
fixpath = $(subst /,\,$1)
|
||||||
|
mymkdir = if not exist "$(call fixpath,$1)" mkdir $(call fixpath,$1)
|
||||||
|
else
|
||||||
|
RMDIR = rm -fr
|
||||||
|
fixpath = $1
|
||||||
|
mymkdir = mkdir -p $1
|
||||||
|
endif
|
||||||
|
|
||||||
|
src_recurse = $(foreach d,$(subst $2/,,$(wildcard $1*)),$(call src_recurse,$3/$d/,$2,$3) $(filter %.c %.cpp,$d))
|
||||||
|
src = $(foreach lib,$3,$(if $(wildcard $2/$(lib)/src),$(call src_recurse,$2/$(lib)/src/,$1,$2),\
|
||||||
|
$(subst $1/,,\
|
||||||
|
$(wildcard $2/$(lib)/*.c)\
|
||||||
|
$(wildcard $2/$(lib)/*.cpp)\
|
||||||
|
$(wildcard $2/$(lib)/utility/*.c)\
|
||||||
|
$(wildcard $2/$(lib)/utility/*.cpp)))))
|
||||||
|
objs = $(patsubst %.c,$2/%.o,$(filter %.c,$1)) $(patsubst %.cpp,$2/%.o,$(filter %.cpp,$1))
|
||||||
|
incs = $(foreach lib,$1,$(if $(wildcard $3/$(lib)/src),-I"$2/$(lib)/src",-I"$2/$(lib)" -I"$2/$(lib)/utility"))
|
||||||
|
|
||||||
|
PROJECT_OBJS = $(call objs,$(call src_recurse,./,.,.),$(OUTPUT_DIR)/src)
|
||||||
|
|
||||||
|
LIB_ROOT = $(ARDUINO_HOME)/hardware/arduino/$(ARCH)/cores/$(BUILD_CORE)
|
||||||
|
LIB_ROOT_SPC = $(call spacify,$(LIB_ROOT))
|
||||||
|
LIB_ROOT_SPC2 = $(subst :,\:,$(subst \,\\\,$(LIB_ROOT_SPC)))
|
||||||
|
LIB_OBJS = $(call objs,$(call src_recurse,$(LIB_ROOT_SPC)/,$(LIB_ROOT),$(LIB_ROOT_SPC)),$(OUTPUT_DIR)/lib)
|
||||||
|
|
||||||
|
USER_LIB_ROOT = $(ARDUINO_USER_LIBS)
|
||||||
|
USER_LIB_ROOT_SPC = $(call spacify,$(USER_LIB_ROOT))
|
||||||
|
USER_LIB_ROOT_SPC2 = $(subst :,\:,$(subst \,\\\,$(USER_LIB_ROOT_SPC)))
|
||||||
|
USER_LIBS = $(foreach lib,$(LIBS),$(subst $(USER_LIB_ROOT)/,,$(wildcard $(USER_LIB_ROOT_SPC)/$(lib))))
|
||||||
|
USER_INCLUDES = $(call incs,$(USER_LIBS),$(USER_LIB_ROOT),$(USER_LIB_ROOT_SPC))
|
||||||
|
USER_OBJS = $(call objs,$(call src,$(USER_LIB_ROOT),$(USER_LIB_ROOT_SPC),$(USER_LIBS)),$(OUTPUT_DIR)/user)
|
||||||
|
|
||||||
|
HW_LIB_ROOT = $(ARDUINO_HOME)/hardware/arduino/$(ARCH)/libraries
|
||||||
|
HW_LIB_ROOT_SPC = $(call spacify,$(HW_LIB_ROOT))
|
||||||
|
HW_LIB_ROOT_SPC2 = $(subst :,\:,$(subst \,\\\,$(HW_LIB_ROOT_SPC)))
|
||||||
|
HW_LIBS = $(foreach lib, $(LIBS), $(subst $(HW_LIB_ROOT)/,,$(wildcard $(HW_LIB_ROOT_SPC)/$(lib))))
|
||||||
|
HW_INCLUDES = $(call incs,$(HW_LIBS),$(HW_LIB_ROOT),$(HW_LIB_ROOT_SPC))
|
||||||
|
HW_OBJS = $(call objs,$(call src,$(HW_LIB_ROOT),$(HW_LIB_ROOT_SPC),$(HW_LIBS)),$(OUTPUT_DIR)/hw)
|
||||||
|
|
||||||
|
ARDUINO_LIB_ROOT = $(ARDUINO_HOME)/libraries
|
||||||
|
ARDUINO_LIB_ROOT_SPC = $(call spacify,$(ARDUINO_LIB_ROOT))
|
||||||
|
ARDUINO_LIB_ROOT_SPC2 = $(subst :,\:,$(subst \,\\\,$(ARDUINO_LIB_ROOT_SPC)))
|
||||||
|
ARDUINO_LIBS = $(foreach lib, $(LIBS), $(subst $(ARDUINO_LIB_ROOT)/,,$(wildcard $(ARDUINO_LIB_ROOT_SPC)/$(lib))))
|
||||||
|
ARDUINO_INCLUDES = $(call incs,$(ARDUINO_LIBS),$(ARDUINO_LIB_ROOT),$(ARDUINO_LIB_ROOT_SPC))
|
||||||
|
ARDUINO_OBJS = $(call objs,$(call src,$(ARDUINO_LIB_ROOT),$(ARDUINO_LIB_ROOT_SPC),$(ARDUINO_LIBS)),$(OUTPUT_DIR)/arduino)
|
||||||
|
|
||||||
|
INCLUDES = -I"$(ARDUINO_HOME)/hardware/arduino/$(ARCH)/cores/$(BUILD_CORE)" \
|
||||||
|
-I"$(ARDUINO_HOME)/hardware/arduino/$(ARCH)/variants/$(BUILD_VARIANT)" \
|
||||||
|
$(USER_INCLUDES) $(HW_INCLUDES) $(ARDUINO_INCLUDES)
|
||||||
|
|
||||||
|
OBJS = $(PROJECT_OBJS) $(USER_OBJS) $(HW_OBJS) $(ARDUINO_OBJS)
|
||||||
|
|
||||||
|
all: $(OUTPUT_DIR)/$(EXE).hex
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RMDIR) $(call fixpath,$(OUTPUT_DIR))
|
||||||
|
|
||||||
|
load: $(OUTPUT_DIR)/$(EXE).hex
|
||||||
|
$(do_load_$(LOADER))
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/$(EXE).hex: $(OBJS) $(OUTPUT_DIR)/core.a
|
||||||
|
$(do_link)
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/core.a: $(LIB_OBJS)
|
||||||
|
$(AR) r $@ $?
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/lib/%.o: $(LIB_ROOT_SPC2)/%.c
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ "$<"
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/lib/%.o: $(LIB_ROOT_SPC2)/%.cpp
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ "$<"
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/user/%.o: $(USER_LIB_ROOT_SPC2)/%.c
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ "$<"
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/user/%.o: $(USER_LIB_ROOT_SPC2)/%.cpp
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ "$<"
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/hw/%.o: $(HW_LIB_ROOT_SPC2)/%.c
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ "$<"
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/hw/%.o: $(HW_LIB_ROOT_SPC2)/%.cpp
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ "$<"
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/arduino/%.o: $(ARDUINO_LIB_ROOT_SPC2)/%.c
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ "$<"
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/arduino/%.o: $(ARDUINO_LIB_ROOT_SPC2)/%.cpp
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ "$<"
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/src/%.o: %.c
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(OUTPUT_DIR)/src/%.o: %.cpp
|
||||||
|
@-$(call mymkdir,$(dir $@))
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
|
||||||
|
|
Loading…
Add table
Reference in a new issue