From ddf7210407b8716973b9890cf7b59561af641b96 Mon Sep 17 00:00:00 2001 From: Pieter du Preez Date: Sat, 29 Sep 2018 23:58:07 +0200 Subject: [PATCH 1/3] Moved CORE_LIB to the last position of the defined linked objects. The linking order was changed from: $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) $(OTHER_LIBS) to: $(LOCAL_OBJS) $(OTHER_OBJS) $(OTHER_LIBS) $(CORE_LIB) This makes more sense, as OTHER_OBJS would rather depend on CORE_LIB, than the other way around. Apart from libc and libm, CORE_LIB should conceptually _always_ be the last lib in the link list, as it is the core (base of everything). BTW, this was implemented correctly for the 'sam' architecture. --- Arduino.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Arduino.mk b/Arduino.mk index fa82b0e..521a747 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -1555,7 +1555,7 @@ ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam) $(CC) $(LINKER_SCRIPTS) -Wl,-Map=$(OBJDIR)/$(TARGET).map -o $@ $(LOCAL_OBJS) $(OTHER_OBJS) $(OTHER_LIBS) $(LDFLAGS) $(CORE_LIB) -Wl,--end-group # otherwise traditional else - $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) $(OTHER_LIBS) -lc -lm $(LINKER_SCRIPTS) + $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(OTHER_OBJS) $(OTHER_LIBS) $(CORE_LIB) -lc -lm $(LINKER_SCRIPTS) endif $(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(PLATFORM_LIB_OBJS) $(USER_LIB_OBJS) From a285810cb53bf454aa6133cbb589bcd3559c0e5d Mon Sep 17 00:00:00 2001 From: Pieter du Preez Date: Tue, 2 Oct 2018 23:00:14 +0200 Subject: [PATCH 2/3] Added a test case for moving CORE_LIB in PR #583. This patch is meant to test the link order, if the OTHER_OBJS variable gets used to add 3rd party archives, that depend on the Arduino core lib (the archive pointed to by the CORE_LIB variable). The examples/Blink3rdPartyLib directory contains a stripped down Blink and includes a library in the examples/Blink3rdPartyLib/Toggle sub-directory. The archive, built inside the Toggle directory mimics a 3rd party library. The archive gets built and linked in by using the OTHER_OBS variable in examples/Blink3rdPartyLib/Makefile. --- HISTORY.md | 1 + .../Blink3rdPartyLib/Blink3rdPartyLib.cpp | 23 ++++++++++++++++ examples/Blink3rdPartyLib/Makefile | 24 +++++++++++++++++ examples/Blink3rdPartyLib/Toggle/Makefile | 14 ++++++++++ .../Blink3rdPartyLib/Toggle/TogglePin.cpp | 27 +++++++++++++++++++ examples/Blink3rdPartyLib/Toggle/TogglePin.h | 19 +++++++++++++ examples/Blink3rdPartyLib/board.mk | 7 +++++ 7 files changed, 115 insertions(+) create mode 100644 examples/Blink3rdPartyLib/Blink3rdPartyLib.cpp create mode 100644 examples/Blink3rdPartyLib/Makefile create mode 100644 examples/Blink3rdPartyLib/Toggle/Makefile create mode 100644 examples/Blink3rdPartyLib/Toggle/TogglePin.cpp create mode 100644 examples/Blink3rdPartyLib/Toggle/TogglePin.h create mode 100644 examples/Blink3rdPartyLib/board.mk diff --git a/HISTORY.md b/HISTORY.md index 1743903..d46e7a2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ The following is the rough list of changes that went into different versions. I tried to give credit whenever possible. If I have missed anyone, kindly add it to the list. ### In Development +- Fix: Moved CORE_LIB to the last position of the defined linked objects. (https://github.com/wingunder) - Fix: Moved ATtiny examples to ATtinyBlink, updated alternate core instructions (issue #537) (https://github.com/sej7278) - Fix: Add -fno-devirtualize flag to workaround g++ segfault bug (issue #486). (https://github.com/sej7278) - Fix: Quote the prefix tag in the space_pad_to function diff --git a/examples/Blink3rdPartyLib/Blink3rdPartyLib.cpp b/examples/Blink3rdPartyLib/Blink3rdPartyLib.cpp new file mode 100644 index 0000000..c0ddb88 --- /dev/null +++ b/examples/Blink3rdPartyLib/Blink3rdPartyLib.cpp @@ -0,0 +1,23 @@ +// A derived Blink, that uses an example 3rd party library. +// Turns on an LED on for one second, then off for one second, repeatedly. +// This example code is in the public domain. + +#include + +#ifdef ARDUINO +#if ARDUINO >= 100 +#include "Arduino.h" +#else +#include "WProgram.h" +#endif +#endif // ARDUINO + +int main() +{ + init(); + TogglePin led(13, false); + while (true) { + delay(1000); + led.toggle(); + } +} diff --git a/examples/Blink3rdPartyLib/Makefile b/examples/Blink3rdPartyLib/Makefile new file mode 100644 index 0000000..f473dbd --- /dev/null +++ b/examples/Blink3rdPartyLib/Makefile @@ -0,0 +1,24 @@ +# This program is free software and is licensed under the same conditions as +# describe in https://github.com/sudar/Arduino-Makefile/blob/master/licence.txt + +# This is an example Makefile, that demonstrates the linking of a third party +# library. In this case the third party library resides in the ./Toggle +# sub-directory. Note that the archive TOGGLE_ARCHIVE _only_ contains the +# compiled Toggle.c.o object. The TOGGLE_ARCHIVE is thus very lean, but it +# requires the Arduino libraries, which are being build in this directory, +# together with Blink, the 'main' program. + +include board.mk + +TOGGLE_ARCHIVE = build-$(BOARD_TAG)/libtoggle.a + +CXXFLAGS += -IToggle +OTHER_OBJS = Toggle/$(TOGGLE_ARCHIVE) + +include ../../Arduino.mk + +Toggle/$(TOGGLE_ARCHIVE): + $(MAKE) -C Toggle $(TOGGLE_ARCHIVE) + +clean:: + $(MAKE) -C Toggle clean diff --git a/examples/Blink3rdPartyLib/Toggle/Makefile b/examples/Blink3rdPartyLib/Toggle/Makefile new file mode 100644 index 0000000..a6234f6 --- /dev/null +++ b/examples/Blink3rdPartyLib/Toggle/Makefile @@ -0,0 +1,14 @@ +# This program is free software and is licensed under the same conditions as +# describe in https://github.com/sudar/Arduino-Makefile/blob/master/licence.txt + +# This is an example Makefile, that is being used to build an archive +# from locally compiled objects. +# +# All source files in this directory will automatically get compiled +# and archived into the build-$(BOARD_TAG)/libtoggle.a target. + +include ../board.mk +include ../../../Arduino.mk + +build-$(BOARD_TAG)/libtoggle.a: $(LOCAL_OBJS) + $(AR) rcs $@ $(LOCAL_OBJS) diff --git a/examples/Blink3rdPartyLib/Toggle/TogglePin.cpp b/examples/Blink3rdPartyLib/Toggle/TogglePin.cpp new file mode 100644 index 0000000..fd6925d --- /dev/null +++ b/examples/Blink3rdPartyLib/Toggle/TogglePin.cpp @@ -0,0 +1,27 @@ +// This program is free software and is licensed under the same conditions as +// describe in https://github.com/sudar/Arduino-Makefile/blob/master/licence.txt + +#include "TogglePin.h" + +#ifdef ARDUINO +#if ARDUINO >= 100 +#include "Arduino.h" +#else +#include "WProgram.h" +#endif +#endif // ARDUINO + +TogglePin::TogglePin(int pinNumber, bool state) + : _pinNumber(pinNumber), _state(state) +{ + pinMode(_pinNumber, OUTPUT); + digitalWrite(_pinNumber, _state ? HIGH : LOW); +} + +bool +TogglePin::toggle() +{ + _state = !_state; + digitalWrite(_pinNumber, _state ? HIGH : LOW); + return _state; +} diff --git a/examples/Blink3rdPartyLib/Toggle/TogglePin.h b/examples/Blink3rdPartyLib/Toggle/TogglePin.h new file mode 100644 index 0000000..5a7e32c --- /dev/null +++ b/examples/Blink3rdPartyLib/Toggle/TogglePin.h @@ -0,0 +1,19 @@ +// This program is free software and is licensed under the same conditions as +// describe in https://github.com/sudar/Arduino-Makefile/blob/master/licence.txt + +#ifndef TOGGLEPIN_H_ +#define TOGGLEPIN_H_ + +class TogglePin +{ + public: + TogglePin(int pinNumber, bool state); + + bool toggle(); + + private: + const int _pinNumber; + bool _state; +}; + +#endif diff --git a/examples/Blink3rdPartyLib/board.mk b/examples/Blink3rdPartyLib/board.mk new file mode 100644 index 0000000..b405c61 --- /dev/null +++ b/examples/Blink3rdPartyLib/board.mk @@ -0,0 +1,7 @@ +# This program is free software and is licensed under the same conditions as +# describe in https://github.com/sudar/Arduino-Makefile/blob/master/licence.txt + +# The following can be overridden at make-time, by setting an environment +# variable with the same name. eg. BOARD_TAG=pro5v328 make + +BOARD_TAG ?= uno From 50e883b6404a28c47a9e401c3fa6cf03a82986f3 Mon Sep 17 00:00:00 2001 From: Pieter du Preez Date: Wed, 3 Oct 2018 14:36:49 +0200 Subject: [PATCH 3/3] Fix "does not allow use of 'sudo'" error in travis Pull requests seem to fail with the following error: > This job is running on container-based infrastructure, which does not allow use of 'sudo', setuid, and setgid executables. > If you require sudo, add 'sudo: required' to your .travis.yml This commit fixes it, by adding 'sudo: required' to .travis.yml, as suggested by the error message. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f97a4ea..630965a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: required language: c compiler: - gcc