Skip to content

Commit

Permalink
pull in main.c by defining a dummy variable, simplify Arduino.mk
Browse files Browse the repository at this point in the history
merging main.c into wiring.c works almost always - except for a sketch
that doesn't use any Arduino functions like the BareMinimum example. Now
define a dummy variable that pulls in a reference to main().

Use $(VAR:old=new) as a more compact alternative to the full ($patsubst
%.old,%.new,VAR) syntax in the Arduino.mk makefile to replace a file name
suffix.
  • Loading branch information
tenbaht committed Dec 15, 2018
1 parent 87f15d6 commit c7ebb07
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 60 deletions.
26 changes: 9 additions & 17 deletions sduino/Arduino.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,7 @@ $(call show_separator)
# library sources
$(OBJDIR)/libs/%.c.$(OBJSUFFIX): $(ARDUINO_LIB_PATH)/%.c
@$(MKDIR) $(dir $@)
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# mv $(patsubst %.o,%.rel,$@) $@
$(CC) "-Wp-MMD $(@:.$(OBJSUFFIX)=.d)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@

$(OBJDIR)/libs/%.cpp.$(OBJSUFFIX): $(ARDUINO_LIB_PATH)/%.cpp
Expand All @@ -1204,8 +1203,7 @@ $(OBJDIR)/libs/%.S.$(OBJSUFFIX): $(ARDUINO_LIB_PATH)/%.S

$(OBJDIR)/platformlibs/%.c.$(OBJSUFFIX): $(ARDUINO_PLATFORM_LIB_PATH)/%.c
@$(MKDIR) $(dir $@)
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# mv $(patsubst %.o,%.rel,$@) $@
$(CC) "-Wp-MMD $(@:.$(OBJSUFFIX)=.d)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@

$(OBJDIR)/platformlibs/%.cpp.$(OBJSUFFIX): $(ARDUINO_PLATFORM_LIB_PATH)/%.cpp
Expand All @@ -1222,8 +1220,7 @@ $(OBJDIR)/userlibs/%.cpp.$(OBJSUFFIX): $(USER_LIB_PATH)/%.cpp

$(OBJDIR)/userlibs/%.c.$(OBJSUFFIX): $(USER_LIB_PATH)/%.c
@$(MKDIR) $(dir $@)
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# mv $(patsubst %.o,%.rel,$@) $@
$(CC) "-Wp-MMD $(@:.$(OBJSUFFIX)=.d)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@

$(OBJDIR)/userlibs/%.S.$(OBJSUFFIX): $(USER_LIB_PATH)/%.S
Expand All @@ -1239,8 +1236,7 @@ endif
# normal local sources
$(OBJDIR)/%.c.$(OBJSUFFIX): %.c $(COMMON_DEPS) | $(OBJDIR)
@$(MKDIR) $(dir $@)
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# mv $(patsubst %.o,%.rel,$@) $@
$(CC) "-Wp-MMD $(@:.$(OBJSUFFIX)=.d)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@

$(OBJDIR)/%.cc.$(OBJSUFFIX): %.cc $(COMMON_DEPS) | $(OBJDIR)
Expand All @@ -1261,16 +1257,13 @@ $(OBJDIR)/%.s.$(OBJSUFFIX): %.s $(COMMON_DEPS) | $(OBJDIR)

# the pde -> o file
$(OBJDIR)/%.pde.$(OBJSUFFIX): %.pde $(COMMON_DEPS) | $(OBJDIR)
@$(MKDIR) $(dir $@)
(echo '#include <Arduino.h>\n#line 1 "$<"'; cat $<) > "$(patsubst %.$(OBJSUFFIX),%.c,$@)"
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) "$(patsubst %.$(OBJSUFFIX),%.c,$@)" -o $@
# $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

# the ino -> o file
$(OBJDIR)/%.ino.$(OBJSUFFIX): %.ino $(COMMON_DEPS) | $(OBJDIR)
@$(MKDIR) $(dir $@)
(echo '#include <Arduino.h>\n#line 1 "$<"'; cat $<) > "$(patsubst %.$(OBJSUFFIX),%.c,$@)"
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) "$(patsubst %.$(OBJSUFFIX),%.c,$@)" -o $@
(echo '#include <$(ARDUINO_HEADER)>\n#line 1 "$<"'; \
echo "void main(void); void (*dummy_variable) () = main;"; \
cat $<) > "$(@:.$(OBJSUFFIX)=.c)"
$(CC) "-Wp-MMD $(@:.$(OBJSUFFIX)=.d)" -c $(CPPFLAGS) $(CFLAGS) "$(@:.$(OBJSUFFIX)=.c)" -o $@
# $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

# generated assembly
Expand All @@ -1289,8 +1282,7 @@ $(OBJDIR)/%.s: %.cpp $(COMMON_DEPS) | $(OBJDIR)
# core files
$(OBJDIR)/core/%.c.$(OBJSUFFIX): $(ARDUINO_CORE_PATH)/%.c $(COMMON_DEPS) | $(OBJDIR)
@$(MKDIR) $(dir $@)
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# mv $(patsubst %.o,%.rel,$@) $@
$(CC) "-Wp-MMD $(@:.$(OBJSUFFIX)=.d)" -c $(CPPFLAGS) $(CFLAGS) $< -o $@
# $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@

$(OBJDIR)/core/%.cpp.$(OBJSUFFIX): $(ARDUINO_CORE_PATH)/%.cpp $(COMMON_DEPS) | $(OBJDIR)
Expand Down
42 changes: 42 additions & 0 deletions sduino/hardware/sduino/stm8/cores/sduino/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
main.cpp - Main loop for Arduino sketches
Copyright (c) 2005-2013 Arduino Team. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <Arduino.h>

// make sure to define prototypes for all used interrupts
//#include "stm8s_it.h"

unsigned char runSerialEvent;

int main(void)
{
init();

initVariant();

setup();

for (;;) {
loop();
if (runSerialEvent) serialEvent();
}

// return 0;
}

43 changes: 0 additions & 43 deletions sduino/hardware/sduino/stm8/cores/sduino/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,46 +711,3 @@ void init()
// work there
enableInterrupts();
}


/*
main.cpp - Main loop for Arduino sketches
Copyright (c) 2005-2013 Arduino Team. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

//#include <Arduino.h>

// make sure to define prototypes for all used interrupts
//#include "stm8s_it.h"

unsigned char runSerialEvent;

void main(void)
{
init();

initVariant();

setup();

for (;;) {
loop();
if (runSerialEvent) serialEvent();
}

// return 0;
}

0 comments on commit c7ebb07

Please sign in to comment.