Browse Source

[2.0.x] Fixed Makefile for Marlin 2.0 (#10255) (#10281)

* Fixed Makefile for Marlin 2.0 (#10255)

- Makefile now supports the new Marlin 2.0 directory hierarchy.
- RELOC_WORKAROUND is now automatically enabled based on avr-gcc version.

* Makefile support for U8glib and TMC2130Stepper

- Updated paths for oliver's U8glib 1.19.1
- Added option for teemuatlut's TMC2130Stepper 2.2.1
Marcio Teixeira 6 years ago
parent
commit
4d1a61335c
1 changed files with 74 additions and 35 deletions
  1. 74
    35
      Marlin/Makefile

Marlin/src/Makefile → Marlin/Makefile View File

4
 # Arduino 0011 Makefile
4
 # Arduino 0011 Makefile
5
 # Arduino adaptation by mellis, eighthave, oli.keller
5
 # Arduino adaptation by mellis, eighthave, oli.keller
6
 # Marlin adaption by Daid
6
 # Marlin adaption by Daid
7
+# Marlin 2.0 support and RELOC_WORKAROUND by @marcio-ao
7
 #
8
 #
8
 # This has been tested with Arduino 0022.
9
 # This has been tested with Arduino 0022.
9
 #
10
 #
85
 # this defines if U8GLIB is needed (may require RELOC_WORKAROUND)
86
 # this defines if U8GLIB is needed (may require RELOC_WORKAROUND)
86
 U8GLIB             ?= 1
87
 U8GLIB             ?= 1
87
 
88
 
88
-# this defines whether to add a workaround for the avr-gcc relocation bug
89
-#	  https://www.stix.id.au/wiki/AVR_relocation_truncations_workaround
90
-RELOC_WORKAROUND   ?= 1
89
+# this defines whether to include the Trinamic TMC2630Stepper
90
+TMC2630            ?= 1
91
+
92
+############
93
+# Try to automatically determine whether RELOC_WORKAROUND is needed based
94
+# on GCC versions:
95
+#   http://www.avrfreaks.net/comment/1789106#comment-1789106
96
+
97
+CC_MAJ:=$(shell $(CC) -dM -E - < /dev/null | grep __GNUC__ | cut -f3 -d\ )
98
+CC_MIN:=$(shell $(CC) -dM -E - < /dev/null | grep __GNUC_MINOR__ | cut -f3 -d\ )
99
+CC_PATCHLEVEL:=$(shell $(CC) -dM -E - < /dev/null | grep __GNUC_PATCHLEVEL__ | cut -f3 -d\ )
100
+CC_VER:=$(shell echo $$(( $(CC_MAJ) * 10000 + $(CC_MIN) * 100 + $(CC_PATCHLEVEL) )))
101
+ifeq ($(shell test $(CC_VER) -lt 40901 && echo 1),1)
102
+  @echo This version of GCC is likely broken. Enabling relocation workaround.
103
+	RELOC_WORKAROUND = 1
104
+endif
91
 
105
 
92
 ############################################################################
106
 ############################################################################
93
 # Below here nothing should be changed...
107
 # Below here nothing should be changed...
425
 # there is no need to specify explicit pathnames as long as the
439
 # there is no need to specify explicit pathnames as long as the
426
 # directory is added here
440
 # directory is added here
427
 
441
 
442
+# The Makefile for previous versions of Marlin used VPATH for all
443
+# source files, but for Marlin 2.0, we use VPATH only for arduino
444
+# library files.
445
+
428
 VPATH = .
446
 VPATH = .
429
 VPATH += $(BUILD_DIR)
447
 VPATH += $(BUILD_DIR)
430
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/arduino/avr/cores/arduino
448
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/arduino/avr/cores/arduino
446
 endif
464
 endif
447
 ifeq ($(U8GLIB), 1)
465
 ifeq ($(U8GLIB), 1)
448
 VPATH += $(ARDUINO_INSTALL_DIR)/libraries/U8glib
466
 VPATH += $(ARDUINO_INSTALL_DIR)/libraries/U8glib
449
-VPATH += $(ARDUINO_INSTALL_DIR)/libraries/U8glib/utility
467
+VPATH += $(ARDUINO_INSTALL_DIR)/libraries/U8glib/clib
468
+endif
469
+ifeq ($(TMC2630), 1)
470
+VPATH += $(ARDUINO_INSTALL_DIR)/libraries/TMC2130Stepper/src
471
+VPATH += $(ARDUINO_INSTALL_DIR)/libraries/TMC2130Stepper/src/source
450
 endif
472
 endif
451
 
473
 
452
 ifeq ($(HARDWARE_VARIANT), arduino)
474
 ifeq ($(HARDWARE_VARIANT), arduino)
460
 VPATH += $(HARDWARE_DIR)/$(HARDWARE_VARIANT)/variants/$(HARDWARE_SUB_VARIANT)
482
 VPATH += $(HARDWARE_DIR)/$(HARDWARE_VARIANT)/variants/$(HARDWARE_SUB_VARIANT)
461
 endif
483
 endif
462
 endif
484
 endif
463
-SRC = wiring.c \
485
+LIB_SRC = wiring.c \
464
 	wiring_analog.c wiring_digital.c \
486
 	wiring_analog.c wiring_digital.c \
465
 	wiring_pulse.c \
487
 	wiring_pulse.c \
466
 	wiring_shift.c WInterrupts.c hooks.c
488
 	wiring_shift.c WInterrupts.c hooks.c
467
 
489
 
468
 ifeq ($(HARDWARE_VARIANT), Teensy)
490
 ifeq ($(HARDWARE_VARIANT), Teensy)
469
-SRC = wiring.c
491
+LIB_SRC = wiring.c
470
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/teensy/cores/teensy
492
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/teensy/cores/teensy
471
 endif
493
 endif
472
 
494
 
473
-CXXSRC = WMath.cpp WString.cpp Print.cpp SPI.cpp Tone.cpp
474
-CXXSRC += $(wildcard *.cpp)
495
+LIB_CXXSRC = WMath.cpp WString.cpp Print.cpp SPI.cpp Tone.cpp
475
 
496
 
476
 ifeq ($(NEOPIXEL), 1)
497
 ifeq ($(NEOPIXEL), 1)
477
-CXXSRC += Adafruit_NeoPixel.cpp
498
+LIB_CXXSRC += Adafruit_NeoPixel.cpp
478
 endif
499
 endif
479
 
500
 
480
 ifeq ($(LIQUID_TWI2), 0)
501
 ifeq ($(LIQUID_TWI2), 0)
481
-CXXSRC += LiquidCrystal.cpp
502
+LIB_CXXSRC += LiquidCrystal.cpp
482
 else
503
 else
483
-SRC += twi.c
484
-CXXSRC += Wire.cpp LiquidTWI2.cpp
504
+LIB_SRC += twi.c
505
+LIB_CXXSRC += Wire.cpp LiquidTWI2.cpp
485
 endif
506
 endif
486
 
507
 
487
 ifeq ($(WIRE), 1)
508
 ifeq ($(WIRE), 1)
488
-SRC += twi.c
489
-CXXSRC += Wire.cpp
509
+LIB_SRC += twi.c
510
+LIB_CXXSRC += Wire.cpp
490
 endif
511
 endif
491
 
512
 
492
 ifeq ($(U8GLIB), 1)
513
 ifeq ($(U8GLIB), 1)
493
-SRC += u8g_ll_api.c u8g_bitmap.c u8g_clip.c u8g_com_null.c u8g_delay.c u8g_page.c u8g_pb.c u8g_pb16h1.c u8g_rect.c u8g_state.c u8g_font.c u8g_font_data.c
514
+LIB_CXXSRC += U8glib.cpp
515
+LIB_SRC += u8g_ll_api.c u8g_bitmap.c u8g_clip.c u8g_com_null.c u8g_delay.c u8g_page.c u8g_pb.c u8g_pb16h1.c u8g_rect.c u8g_state.c u8g_font.c u8g_font_data.c
516
+endif
517
+
518
+ifeq ($(TMC2630), 1)
519
+LIB_CXXSRC += TMC2130Stepper.cpp TMC2130Stepper_COOLCONF.cpp TMC2130Stepper_DRV_STATUS.cpp TMC2130Stepper_IHOLD_IRUN.cpp TMC2130Stepper_CHOPCONF.cpp TMC2130Stepper_GCONF.cpp  TMC2130Stepper_PWMCONF.cpp SW_SPI.cpp
494
 endif
520
 endif
495
 
521
 
496
 ifeq ($(RELOC_WORKAROUND), 1)
522
 ifeq ($(RELOC_WORKAROUND), 1)
500
 
526
 
501
 #Check for Arduino 1.0.0 or higher and use the correct source files for that version
527
 #Check for Arduino 1.0.0 or higher and use the correct source files for that version
502
 ifeq ($(shell [ $(ARDUINO_VERSION) -ge 100 ] && echo true), true)
528
 ifeq ($(shell [ $(ARDUINO_VERSION) -ge 100 ] && echo true), true)
503
-CXXSRC += main.cpp
529
+LIB_CXXSRC += main.cpp
504
 else
530
 else
505
-SRC += pins_arduino.c main.c
531
+LIB_SRC += pins_arduino.c main.c
506
 endif
532
 endif
507
 
533
 
508
 FORMAT = ihex
534
 FORMAT = ihex
537
 
563
 
538
 ifeq ($(HARDWARE_VARIANT), Teensy)
564
 ifeq ($(HARDWARE_VARIANT), Teensy)
539
 CDEFS  += -DUSB_SERIAL
565
 CDEFS  += -DUSB_SERIAL
540
-SRC    += usb.c pins_teensy.c
541
-CXXSRC += usb_api.cpp
566
+LIB_SRC    += usb.c pins_teensy.c
567
+LIB_CXXSRC += usb_api.cpp
542
 endif
568
 endif
543
 
569
 
544
 # Add all the source directories as include directories too
570
 # Add all the source directories as include directories too
578
 	-p$(MCU) -P$(AVRDUDE_PORT) -c$(AVRDUDE_PROGRAMMER) \
604
 	-p$(MCU) -P$(AVRDUDE_PORT) -c$(AVRDUDE_PROGRAMMER) \
579
 	-b$(UPLOAD_RATE)
605
 	-b$(UPLOAD_RATE)
580
 
606
 
607
+# Since Marlin 2.0, the source files may be distributed into several
608
+# different directories, so it is necessary to find them recursively
609
+
610
+SRC    = $(shell find src -name '*.c'   -type f)
611
+CXXSRC = $(shell find src -name '*.cpp' -type f)
612
+
581
 # Define all object files.
613
 # Define all object files.
582
-OBJ = ${patsubst %.c, $(BUILD_DIR)/%.o, ${SRC}}
614
+OBJ  = ${patsubst %.c,   $(BUILD_DIR)/arduino/%.o, ${LIB_SRC}}
615
+OBJ += ${patsubst %.cpp, $(BUILD_DIR)/arduino/%.o, ${LIB_CXXSRC}}
616
+OBJ += ${patsubst %.S,   $(BUILD_DIR)/arduino/%.o, ${LIB_ASRC}}
617
+OBJ += ${patsubst %.c,   $(BUILD_DIR)/%.o, ${SRC}}
583
 OBJ += ${patsubst %.cpp, $(BUILD_DIR)/%.o, ${CXXSRC}}
618
 OBJ += ${patsubst %.cpp, $(BUILD_DIR)/%.o, ${CXXSRC}}
584
-OBJ += ${patsubst %.S, $(BUILD_DIR)/%.o, ${ASRC}}
585
 
619
 
586
 # Define all listing files.
620
 # Define all listing files.
587
-LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
621
+LST = $(LIB_ASRC:.S=.lst) $(LIB_CXXSRC:.cpp=.lst) $(LIB_SRC:.c=.lst)
588
 
622
 
589
 # Combine all necessary flags and optional flags.
623
 # Combine all necessary flags and optional flags.
590
 # Add target processor to flags.
624
 # Add target processor to flags.
601
  P=
635
  P=
602
 endif
636
 endif
603
 
637
 
638
+# Create required build hierarchy if it does not exist
639
+
640
+$(shell mkdir -p $(dir $(OBJ)))
641
+
604
 # Default target.
642
 # Default target.
605
 all: sizeafter
643
 all: sizeafter
606
 
644
 
607
-build: $(BUILD_DIR) elf hex
608
-
609
-# Creates the object directory
610
-$(BUILD_DIR):
611
-	$P mkdir -p $(BUILD_DIR)
645
+build: elf hex
612
 
646
 
613
 elf: $(BUILD_DIR)/$(TARGET).elf
647
 elf: $(BUILD_DIR)/$(TARGET).elf
614
 hex: $(BUILD_DIR)/$(TARGET).hex
648
 hex: $(BUILD_DIR)/$(TARGET).hex
674
 	$(NM) -n $< > $@
708
 	$(NM) -n $< > $@
675
 
709
 
676
 	# Link: create ELF output file from library.
710
 	# Link: create ELF output file from library.
711
+
677
 $(BUILD_DIR)/$(TARGET).elf: $(OBJ) Configuration.h
712
 $(BUILD_DIR)/$(TARGET).elf: $(OBJ) Configuration.h
678
 	$(Pecho) "  CXX   $@"
713
 	$(Pecho) "  CXX   $@"
679
 	$P $(CC) $(LD_PREFIX) $(ALL_CXXFLAGS) -Wl,--gc-sections,--relax -o $@ -L. $(OBJ) $(LDFLAGS) $(LD_SUFFIX)
714
 	$P $(CC) $(LD_PREFIX) $(ALL_CXXFLAGS) -Wl,--gc-sections,--relax -o $@ -L. $(OBJ) $(LDFLAGS) $(LD_SUFFIX)
680
 
715
 
716
+# Object files that were found in "src" will be stored in $(BUILD_DIR)
717
+# in directories that mirror the structure of "src"
718
+
681
 $(BUILD_DIR)/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE)
719
 $(BUILD_DIR)/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE)
682
 	$(Pecho) "  CC    $<"
720
 	$(Pecho) "  CC    $<"
683
 	$P $(CC) -MMD -c $(ALL_CFLAGS) $< -o $@
721
 	$P $(CC) -MMD -c $(ALL_CFLAGS) $< -o $@
684
 
722
 
685
-$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
723
+$(BUILD_DIR)/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
686
 	$(Pecho) "  CXX   $<"
724
 	$(Pecho) "  CXX   $<"
687
 	$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
725
 	$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
688
 
726
 
689
-$(BUILD_DIR)/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
727
+# Object files for Arduino libs will be created in $(BUILD_DIR)/arduino
728
+
729
+$(BUILD_DIR)/arduino/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE)
730
+	$(Pecho) "  CC    $<"
731
+	$P $(CC) -MMD -c $(ALL_CFLAGS) $< -o $@
732
+
733
+$(BUILD_DIR)/arduino/%.o: %.cpp Configuration.h Configuration_adv.h $(MAKEFILE)
690
 	$(Pecho) "  CXX   $<"
734
 	$(Pecho) "  CXX   $<"
691
 	$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
735
 	$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
692
 
736
 
693
-
694
 # Target: clean project.
737
 # Target: clean project.
695
 clean:
738
 clean:
696
-	$(Pecho) "  RM    $(BUILD_DIR)/*"
697
-	$P $(REMOVE) $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET).cof $(BUILD_DIR)/$(TARGET).elf \
698
-		$(BUILD_DIR)/$(TARGET).map $(BUILD_DIR)/$(TARGET).sym $(BUILD_DIR)/$(TARGET).lss $(BUILD_DIR)/$(TARGET).cpp \
699
-		$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
700
 	$(Pecho) "  RMDIR $(BUILD_DIR)/"
739
 	$(Pecho) "  RMDIR $(BUILD_DIR)/"
701
 	$P rm -rf $(BUILD_DIR)
740
 	$P rm -rf $(BUILD_DIR)
702
 
741
 
704
 .PHONY:	all build elf hex eep lss sym program coff extcoff clean depend sizebefore sizeafter
743
 .PHONY:	all build elf hex eep lss sym program coff extcoff clean depend sizebefore sizeafter
705
 
744
 
706
 # Automaticaly include the dependency files created by gcc
745
 # Automaticaly include the dependency files created by gcc
707
--include ${wildcard $(BUILD_DIR)/*.d}
746
+-include ${patsubst %.o, %.d, ${OBJ}}

Loading…
Cancel
Save