2016-05-25 17:37:40 +02:00
|
|
|
# Klipper build system
|
|
|
|
#
|
2019-03-01 18:57:43 +01:00
|
|
|
# Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
|
2016-05-25 17:37:40 +02:00
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
|
|
|
|
|
|
|
# Output directory
|
|
|
|
OUT=out/
|
|
|
|
|
|
|
|
# Kconfig includes
|
|
|
|
export HOSTCC := $(CC)
|
|
|
|
export CONFIG_SHELL := sh
|
|
|
|
export KCONFIG_AUTOHEADER := autoconf.h
|
|
|
|
export KCONFIG_CONFIG := $(CURDIR)/.config
|
|
|
|
-include $(KCONFIG_CONFIG)
|
|
|
|
|
|
|
|
# Common command definitions
|
|
|
|
CC=$(CROSS_PREFIX)gcc
|
|
|
|
AS=$(CROSS_PREFIX)as
|
|
|
|
LD=$(CROSS_PREFIX)ld
|
|
|
|
OBJCOPY=$(CROSS_PREFIX)objcopy
|
|
|
|
OBJDUMP=$(CROSS_PREFIX)objdump
|
|
|
|
STRIP=$(CROSS_PREFIX)strip
|
|
|
|
CPP=cpp
|
2017-06-28 16:52:05 +02:00
|
|
|
PYTHON=python2
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
# Source files
|
2016-06-09 01:32:06 +02:00
|
|
|
src-y =
|
|
|
|
dirs-y = src
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
# Default compiler flags
|
|
|
|
cc-option=$(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`" \
|
|
|
|
; then echo "$(2)"; else echo "$(3)"; fi ;)
|
|
|
|
|
2018-05-17 18:17:43 +02:00
|
|
|
CFLAGS := -I$(OUT) -Isrc -I$(OUT)board-generic/ -std=gnu11 -O2 -MD -g \
|
2016-05-25 17:37:40 +02:00
|
|
|
-Wall -Wold-style-definition $(call cc-option,$(CC),-Wtype-limits,) \
|
|
|
|
-ffunction-sections -fdata-sections
|
2017-05-07 22:51:46 +02:00
|
|
|
CFLAGS += -flto -fwhole-program -fno-use-linker-plugin
|
2016-05-25 17:37:40 +02:00
|
|
|
|
2019-03-02 17:26:14 +01:00
|
|
|
OBJS_klipper.elf = $(patsubst %.c, $(OUT)src/%.o,$(src-y))
|
|
|
|
OBJS_klipper.elf += $(OUT)compile_time_request.o
|
2017-05-07 23:02:40 +02:00
|
|
|
CFLAGS_klipper.elf = $(CFLAGS) -Wl,--gc-sections
|
2016-05-25 17:37:40 +02:00
|
|
|
|
2016-06-11 03:11:04 +02:00
|
|
|
CPPFLAGS = -I$(OUT) -P -MD -MT $@
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
# Default targets
|
|
|
|
target-y := $(OUT)klipper.elf
|
|
|
|
|
|
|
|
all:
|
|
|
|
|
|
|
|
# Run with "make V=1" to see the actual compile commands
|
|
|
|
ifdef V
|
|
|
|
Q=
|
|
|
|
else
|
|
|
|
Q=@
|
|
|
|
MAKEFLAGS += --no-print-directory
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Include board specific makefile
|
2016-06-09 01:32:06 +02:00
|
|
|
include src/Makefile
|
2016-05-25 17:37:40 +02:00
|
|
|
-include src/$(patsubst "%",%,$(CONFIG_BOARD_DIRECTORY))/Makefile
|
|
|
|
|
|
|
|
################ Common build rules
|
|
|
|
|
|
|
|
$(OUT)%.o: %.c $(OUT)autoconf.h $(OUT)board-link
|
|
|
|
@echo " Compiling $@"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
################ Main build rules
|
|
|
|
|
|
|
|
$(OUT)board-link: $(KCONFIG_CONFIG)
|
|
|
|
@echo " Creating symbolic link $(OUT)board"
|
2016-06-08 21:40:06 +02:00
|
|
|
$(Q)mkdir -p $(addprefix $(OUT), $(dirs-y))
|
2016-05-25 17:37:40 +02:00
|
|
|
$(Q)touch $@
|
|
|
|
$(Q)ln -Tsf $(PWD)/src/$(CONFIG_BOARD_DIRECTORY) $(OUT)board
|
2016-06-05 20:52:17 +02:00
|
|
|
$(Q)mkdir -p $(OUT)board-generic
|
|
|
|
$(Q)ln -Tsf $(PWD)/src/generic $(OUT)board-generic/board
|
2016-05-25 17:37:40 +02:00
|
|
|
|
2017-05-25 22:54:31 +02:00
|
|
|
$(OUT)%.o.ctr: $(OUT)%.o
|
|
|
|
$(Q)$(OBJCOPY) -j '.compile_time_request' -O binary $^ $@
|
|
|
|
|
|
|
|
$(OUT)compile_time_request.o: $(patsubst %.c, $(OUT)src/%.o.ctr,$(src-y)) ./scripts/buildcommands.py
|
|
|
|
@echo " Building $@"
|
|
|
|
$(Q)cat $(patsubst %.c, $(OUT)src/%.o.ctr,$(src-y)) > $(OUT)klipper.compile_time_request
|
2017-12-22 00:18:18 +01:00
|
|
|
$(Q)$(PYTHON) ./scripts/buildcommands.py -d $(OUT)klipper.dict -t "$(CC);$(AS);$(LD);$(OBJCOPY);$(OBJDUMP);$(STRIP)" $(OUT)klipper.compile_time_request $(OUT)compile_time_request.c
|
2017-05-25 22:54:31 +02:00
|
|
|
$(Q)$(CC) $(CFLAGS) -c $(OUT)compile_time_request.c -o $@
|
|
|
|
|
2019-03-02 17:26:14 +01:00
|
|
|
$(OUT)klipper.elf: $(OBJS_klipper.elf)
|
2016-05-25 17:37:40 +02:00
|
|
|
@echo " Linking $@"
|
2019-03-02 17:26:14 +01:00
|
|
|
$(Q)$(CC) $(OBJS_klipper.elf) $(CFLAGS_klipper.elf) -o $@
|
2018-12-22 19:05:58 +01:00
|
|
|
$(Q)scripts/check-gcc.sh $@ $(OUT)compile_time_request.o
|
2016-05-25 17:37:40 +02:00
|
|
|
|
|
|
|
################ Kconfig rules
|
|
|
|
|
|
|
|
define do-kconfig
|
|
|
|
$(Q)mkdir -p $(OUT)/scripts/kconfig/lxdialog
|
|
|
|
$(Q)mkdir -p $(OUT)/include/config
|
|
|
|
$(Q)$(MAKE) -C $(OUT) -f $(CURDIR)/scripts/kconfig/Makefile srctree=$(CURDIR) src=scripts/kconfig obj=scripts/kconfig Q=$(Q) Kconfig=$(CURDIR)/src/Kconfig $1
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(OUT)autoconf.h : $(KCONFIG_CONFIG) ; $(call do-kconfig, silentoldconfig)
|
|
|
|
$(KCONFIG_CONFIG): src/Kconfig ; $(call do-kconfig, olddefconfig)
|
|
|
|
%onfig: ; $(call do-kconfig, $@)
|
|
|
|
help: ; $(call do-kconfig, $@)
|
|
|
|
|
|
|
|
|
|
|
|
################ Generic rules
|
|
|
|
|
|
|
|
# Make definitions
|
|
|
|
.PHONY : all clean distclean FORCE
|
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
|
|
|
|
all: $(target-y)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
$(Q)rm -rf $(OUT)
|
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
$(Q)rm -f .config .config.old
|
|
|
|
|
2016-10-21 18:00:03 +02:00
|
|
|
-include $(OUT)*.d $(patsubst %,$(OUT)%/*.d,$(dirs-y))
|