Просмотр исходного кода

[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 лет назад
Родитель
Сommit
4d1a61335c
1 измененных файлов: 74 добавлений и 35 удалений
  1. 74
    35
      Marlin/Makefile

Marlin/src/Makefile → Marlin/Makefile Просмотреть файл

@@ -4,6 +4,7 @@
4 4
 # Arduino 0011 Makefile
5 5
 # Arduino adaptation by mellis, eighthave, oli.keller
6 6
 # Marlin adaption by Daid
7
+# Marlin 2.0 support and RELOC_WORKAROUND by @marcio-ao
7 8
 #
8 9
 # This has been tested with Arduino 0022.
9 10
 #
@@ -85,9 +86,22 @@ WIRE               ?= 0
85 86
 # this defines if U8GLIB is needed (may require RELOC_WORKAROUND)
86 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 107
 # Below here nothing should be changed...
@@ -425,6 +439,10 @@ TARGET = $(notdir $(CURDIR))
425 439
 # there is no need to specify explicit pathnames as long as the
426 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 446
 VPATH = .
429 447
 VPATH += $(BUILD_DIR)
430 448
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/arduino/avr/cores/arduino
@@ -446,7 +464,11 @@ VPATH += $(ARDUINO_INSTALL_DIR)/libraries/Adafruit_NeoPixel
446 464
 endif
447 465
 ifeq ($(U8GLIB), 1)
448 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 472
 endif
451 473
 
452 474
 ifeq ($(HARDWARE_VARIANT), arduino)
@@ -460,37 +482,41 @@ HARDWARE_SUB_VARIANT ?= standard
460 482
 VPATH += $(HARDWARE_DIR)/$(HARDWARE_VARIANT)/variants/$(HARDWARE_SUB_VARIANT)
461 483
 endif
462 484
 endif
463
-SRC = wiring.c \
485
+LIB_SRC = wiring.c \
464 486
 	wiring_analog.c wiring_digital.c \
465 487
 	wiring_pulse.c \
466 488
 	wiring_shift.c WInterrupts.c hooks.c
467 489
 
468 490
 ifeq ($(HARDWARE_VARIANT), Teensy)
469
-SRC = wiring.c
491
+LIB_SRC = wiring.c
470 492
 VPATH += $(ARDUINO_INSTALL_DIR)/hardware/teensy/cores/teensy
471 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 497
 ifeq ($(NEOPIXEL), 1)
477
-CXXSRC += Adafruit_NeoPixel.cpp
498
+LIB_CXXSRC += Adafruit_NeoPixel.cpp
478 499
 endif
479 500
 
480 501
 ifeq ($(LIQUID_TWI2), 0)
481
-CXXSRC += LiquidCrystal.cpp
502
+LIB_CXXSRC += LiquidCrystal.cpp
482 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 506
 endif
486 507
 
487 508
 ifeq ($(WIRE), 1)
488
-SRC += twi.c
489
-CXXSRC += Wire.cpp
509
+LIB_SRC += twi.c
510
+LIB_CXXSRC += Wire.cpp
490 511
 endif
491 512
 
492 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 520
 endif
495 521
 
496 522
 ifeq ($(RELOC_WORKAROUND), 1)
@@ -500,9 +526,9 @@ endif
500 526
 
501 527
 #Check for Arduino 1.0.0 or higher and use the correct source files for that version
502 528
 ifeq ($(shell [ $(ARDUINO_VERSION) -ge 100 ] && echo true), true)
503
-CXXSRC += main.cpp
529
+LIB_CXXSRC += main.cpp
504 530
 else
505
-SRC += pins_arduino.c main.c
531
+LIB_SRC += pins_arduino.c main.c
506 532
 endif
507 533
 
508 534
 FORMAT = ihex
@@ -537,8 +563,8 @@ CXXDEFS  = $(CDEFS)
537 563
 
538 564
 ifeq ($(HARDWARE_VARIANT), Teensy)
539 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 568
 endif
543 569
 
544 570
 # Add all the source directories as include directories too
@@ -578,13 +604,21 @@ AVRDUDE_FLAGS = -D -C$(AVRDUDE_CONF) \
578 604
 	-p$(MCU) -P$(AVRDUDE_PORT) -c$(AVRDUDE_PROGRAMMER) \
579 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 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 618
 OBJ += ${patsubst %.cpp, $(BUILD_DIR)/%.o, ${CXXSRC}}
584
-OBJ += ${patsubst %.S, $(BUILD_DIR)/%.o, ${ASRC}}
585 619
 
586 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 623
 # Combine all necessary flags and optional flags.
590 624
 # Add target processor to flags.
@@ -601,14 +635,14 @@ else
601 635
  P=
602 636
 endif
603 637
 
638
+# Create required build hierarchy if it does not exist
639
+
640
+$(shell mkdir -p $(dir $(OBJ)))
641
+
604 642
 # Default target.
605 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 647
 elf: $(BUILD_DIR)/$(TARGET).elf
614 648
 hex: $(BUILD_DIR)/$(TARGET).hex
@@ -674,29 +708,34 @@ extcoff: $(TARGET).elf
674 708
 	$(NM) -n $< > $@
675 709
 
676 710
 	# Link: create ELF output file from library.
711
+
677 712
 $(BUILD_DIR)/$(TARGET).elf: $(OBJ) Configuration.h
678 713
 	$(Pecho) "  CXX   $@"
679 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 719
 $(BUILD_DIR)/%.o: %.c Configuration.h Configuration_adv.h $(MAKEFILE)
682 720
 	$(Pecho) "  CC    $<"
683 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 724
 	$(Pecho) "  CXX   $<"
687 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 734
 	$(Pecho) "  CXX   $<"
691 735
 	$P $(CXX) -MMD -c $(ALL_CXXFLAGS) $< -o $@
692 736
 
693
-
694 737
 # Target: clean project.
695 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 739
 	$(Pecho) "  RMDIR $(BUILD_DIR)/"
701 740
 	$P rm -rf $(BUILD_DIR)
702 741
 
@@ -704,4 +743,4 @@ clean:
704 743
 .PHONY:	all build elf hex eep lss sym program coff extcoff clean depend sizebefore sizeafter
705 744
 
706 745
 # Automaticaly include the dependency files created by gcc
707
--include ${wildcard $(BUILD_DIR)/*.d}
746
+-include ${patsubst %.o, %.d, ${OBJ}}

Загрузка…
Отмена
Сохранить