I'm running example code from the Arduino Wire library (Master Sender, Slave Reciever), but I get an error in the Slave-Reciever code. It's having problems with the recieveEvent function.
The code works in Arduino, so why is it different in Visual Studio Code? Is there anything that I should change in structure or anything? I don't see why this would be.
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Arduino.h>// <- I added this include
#include <Wire.h>
int led = LED_BUILTIN;
void recieveEvent(int howMany); // <- I added this
void setup(){
Wire.begin(9);
Wire.onReceive(recieveEvent); //<-This is the issue spot
Serial.begin(115200);
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
digitalWrite(led, HIGH); // briefly flash the LED
while(Wire.available() > 1) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
digitalWrite(led, LOW);
}
This is the Make File:
#******************************************************************************
# Generated by VisualTeensy V1.5.0 on 6/11/2022 at 2:32 PM
#
# Board Teensy 3.2 / 3.1
# USB Type Serial
# CPU Speed 96 MHz (overclock)
# Optimize Faster
# Keyboard Layout US English
#
# https://github.com/luni64/VisualTeensy
#******************************************************************************
SHELL := cmd.exe
export SHELL
TARGET_NAME := BASICSMasterSend
BOARD_ID := TEENSY32
MCU := mk20dx256
LIBS_SHARED_BASE := C:\Users\Sorin\OneDrive\Documents\Arduino\libraries
LIBS_SHARED := Adafruit_PWM_Servo_Driver_Library
LIBS_LOCAL_BASE := lib
LIBS_LOCAL := SPI Time Wire
CORE_BASE := C:\PROGRA~2\Arduino\hardware\teensy\avr\cores\teensy3
GCC_BASE := C:\PROGRA~2\Arduino\hardware\tools\arm\bin
UPL_PJRC_B := C:\PROGRA~2\Arduino\hardware\tools
UPL_TYCMD_B := C:\tytools096\TyTools-0.9.7-win64
#******************************************************************************
# Flags and Defines
#******************************************************************************
TIME_SYM := $(shell powershell [int][double]::Parse((Get-Date -UFormat %s)))
FLAGS_CPU := -mthumb -mcpu=cortex-m4 -fsingle-precision-constant
FLAGS_OPT := -O2
FLAGS_COM := -g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access -MMD
FLAGS_LSP :=
FLAGS_CPP := -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti
FLAGS_C :=
FLAGS_S := -x assembler-with-cpp
FLAGS_LD := -Wl,--print-memory-usage,--gc-sections,--relax,--defsym=__rtc_localtime=$(TIME_SYM) -T$(CORE_BASE)/mk20dx256.ld
LIBS := -larm_cortexM4l_math -lm -lstdc++
DEFINES := -D__MK20DX256__ -DTEENSYDUINO=154 -DARDUINO_TEENSY32 -DARDUINO=10813
DEFINES += -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH
CPP_FLAGS := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_CPP)
C_FLAGS := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_C)
S_FLAGS := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_S)
LD_FLAGS := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_LSP) $(FLAGS_LD)
AR_FLAGS := rcs
NM_FLAGS := --numeric-sort --defined-only --demangle --print-size
#******************************************************************************
# Colors
#******************************************************************************
COL_CORE := [38;2;187;206;251m
COL_LIB := [38;2;206;244;253m
COL_SRC := [38;2;100;149;237m
COL_LINK := [38;2;255;255;202m
COL_ERR := [38;2;255;159;159m
COL_OK := [38;2;179;255;179m
COL_RESET := [0m
#******************************************************************************
# Folders and Files
#******************************************************************************
USR_SRC := src
LIB_SRC := lib
CORE_SRC := $(CORE_BASE)
BIN := .vsteensy/build
USR_BIN := $(BIN)/src
CORE_BIN := $(BIN)/core
LIB_BIN := $(BIN)/lib
CORE_LIB := $(BIN)/core.a
TARGET_HEX := $(BIN)/$(TARGET_NAME).hex
TARGET_ELF := $(BIN)/$(TARGET_NAME).elf
TARGET_LST := $(BIN)/$(TARGET_NAME).lst
TARGET_SYM := $(BIN)/$(TARGET_NAME).sym
#******************************************************************************
# BINARIES
#******************************************************************************
CC := $(GCC_BASE)/arm-none-eabi-gcc
CXX := $(GCC_BASE)/arm-none-eabi-g++
AR := $(GCC_BASE)/arm-none-eabi-gcc-ar
NM := $(GCC_BASE)/arm-none-eabi-gcc-nm
SIZE := $(GCC_BASE)/arm-none-eabi-size
OBJDUMP := $(GCC_BASE)/arm-none-eabi-objdump
OBJCOPY := $(GCC_BASE)/arm-none-eabi-objcopy
UPL_PJRC := "$(UPL_PJRC_B)/teensy_post_compile" -test -file=$(TARGET_NAME) -path=$(BIN) -tools="$(UPL_PJRC_B)" -board=$(BOARD_ID) -reboot
UPL_TYCMD := $(UPL_TYCMD_B)/tyCommanderC upload $(TARGET_HEX) --autostart --wait --multi
UPL_CLICMD := $(UPL_CLICMD_B)/teensy_loader_cli -mmcu=$(MCU) -v $(TARGET_HEX)
UPL_JLINK := $(UPL_JLINK_B)/jlink -commanderscript .vsteensy/flash.jlink
#******************************************************************************
# Source and Include Files
#******************************************************************************
# Recursively create list of source and object files in USR_SRC and CORE_SRC
# and corresponding subdirectories.
# The function rwildcard is taken from http://stackoverflow.com/a/12959694)
rwildcard =$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
#User Sources -----------------------------------------------------------------
USR_C_FILES := $(call rwildcard,$(USR_SRC)/,*.c)
USR_CPP_FILES := $(call rwildcard,$(USR_SRC)/,*.cpp)
USR_S_FILES := $(call rwildcard,$(USR_SRC)/,*.S)
USR_OBJ := $(USR_S_FILES:$(USR_SRC)/%.S=$(USR_BIN)/%.s.o) $(USR_C_FILES:$(USR_SRC)/%.c=$(USR_BIN)/%.c.o) $(USR_CPP_FILES:$(USR_SRC)/%.cpp=$(USR_BIN)/%.cpp.o)
# Core library sources --------------------------------------------------------
CORE_CPP_FILES := $(call rwildcard,$(CORE_SRC)/,*.cpp)
CORE_C_FILES := $(call rwildcard,$(CORE_SRC)/,*.c)
CORE_S_FILES := $(call rwildcard,$(CORE_SRC)/,*.S)
CORE_OBJ := $(CORE_S_FILES:$(CORE_SRC)/%.S=$(CORE_BIN)/%.s.o) $(CORE_C_FILES:$(CORE_SRC)/%.c=$(CORE_BIN)/%.c.o) $(CORE_CPP_FILES:$(CORE_SRC)/%.cpp=$(CORE_BIN)/%.cpp.o)
# User library sources (see https://github.com/arduino/arduino/wiki/arduino-ide-1.5:-library-specification)
LIB_DIRS_SHARED := $(foreach d, $(LIBS_SHARED), $(LIBS_SHARED_BASE)/$d/ $(LIBS_SHARED_BASE)/$d/utility/) # base and /utility
LIB_DIRS_SHARED += $(foreach d, $(LIBS_SHARED), $(LIBS_SHARED_BASE)/$d/src/ $(dir $(call rwildcard,$(LIBS_SHARED_BASE)/$d/src/,*/.))) # src and all subdirs of base
LIB_DIRS_LOCAL := $(foreach d, $(LIBS_LOCAL), $(LIBS_LOCAL_BASE)/$d/ $(LIBS_LOCAL_BASE)/$d/utility/ ) # base and /utility
LIB_DIRS_LOCAL += $(foreach d, $(LIBS_LOCAL), $(LIBS_LOCAL_BASE)/$d/src/ $(dir $(call rwildcard,$(LIBS_LOCAL_BASE)/$d/src/,*/.))) # src and all subdirs of base
LIB_CPP_SHARED := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.cpp))
LIB_C_SHARED := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.c))
LIB_S_SHARED := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.S))
LIB_CPP_LOCAL := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.cpp))
LIB_C_LOCAL := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.c))
LIB_S_LOCAL := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.S))
LIB_OBJ := $(LIB_CPP_SHARED:$(LIBS_SHARED_BASE)/%.cpp=$(LIB_BIN)/%.cpp.o) $(LIB_CPP_LOCAL:$(LIBS_LOCAL_BASE)/%.cpp=$(LIB_BIN)/%.cpp.o)
LIB_OBJ += $(LIB_C_SHARED:$(LIBS_SHARED_BASE)/%.c=$(LIB_BIN)/%.c.o) $(LIB_C_LOCAL:$(LIBS_LOCAL_BASE)/%.c=$(LIB_BIN)/%.c.o)
LIB_OBJ += $(LIB_S_SHARED:$(LIBS_SHARED_BASE)/%.S=$(LIB_BIN)/%.s.o) $(LIB_S_LOCAL:$(LIBS_LOCAL_BASE)/%.S=$(LIB_BIN)/%.s.o)
# Includes -------------------------------------------------------------
INCLUDE := -I./$(USR_SRC) -I$(CORE_SRC)
INCLUDE += $(foreach d, $(LIBS_LOCAL),-I$(LIBS_LOCAL_BASE)/$d/ -I$(LIBS_LOCAL_BASE)/$d/src -I$(LIBS_LOCAL_BASE)/$d/utility/)
INCLUDE += $(foreach d, $(LIBS_SHARED), -I$(LIBS_SHARED_BASE)/$d/ -I$(LIBS_SHARED_BASE)/$d/src -I$(LIBS_SHARED_BASE)/$d/utility/)
# Generate directories --------------------------------------------------------
DIRECTORIES := $(sort $(dir $(CORE_OBJ) $(USR_OBJ) $(LIB_OBJ)))
generateDirs := $(foreach d, $(DIRECTORIES), $(shell if not exist "$d" mkdir "$d"))
#$(info dirs: $(DIRECTORIES))
#******************************************************************************
# Rules:
#******************************************************************************
.PHONY: directories all rebuild upload uploadTy uploadCLI clean cleanUser cleanCore
all: $(TARGET_LST) $(TARGET_SYM) $(TARGET_HEX)
rebuild: cleanUser all
clean: cleanUser cleanCore cleanLib
#echo $(COL_OK)cleaning done$(COL_RESET)
upload: all
#$(UPL_PJRC)
uploadTy: all
#$(UPL_TYCMD)
uploadCLI: all
#$(UPL_CLICMD)
uploadJLink: all
#$(UPL_JLINK)
# Core library ----------------------------------------------------------------
$(CORE_BIN)/%.s.o: $(CORE_SRC)/%.S
#echo $(COL_CORE)CORE [ASM] $(notdir $<) $(COL_ERR)
#"$(CC)" $(S_FLAGS) $(INCLUDE) -o $# -c $<
$(CORE_BIN)/%.c.o: $(CORE_SRC)/%.c
#echo $(COL_CORE)CORE [CC] $(notdir $<) $(COL_ERR)
#"$(CC)" $(C_FLAGS) $(INCLUDE) -o $# -c $<
$(CORE_BIN)/%.cpp.o: $(CORE_SRC)/%.cpp
#echo $(COL_CORE)CORE [CPP] $(notdir $<) $(COL_ERR)
#"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $# -c $<
$(CORE_LIB) : $(CORE_OBJ)
#echo $(COL_LINK)CORE [AR] $# $(COL_ERR)
#$(AR) $(AR_FLAGS) $# $^
#echo $(COL_OK)Teensy core built successfully &&echo.
# Shared Libraries ------------------------------------------------------------
$(LIB_BIN)/%.s.o: $(LIBS_SHARED_BASE)/%.S
#echo $(COL_LIB)LIB [ASM] $(notdir $<) $(COL_ERR)
#"$(CC)" $(S_FLAGS) $(INCLUDE) -o $# -c $<
$(LIB_BIN)/%.cpp.o: $(LIBS_SHARED_BASE)/%.cpp
#echo $(COL_LIB)LIB [CPP] $(notdir $<) $(COL_ERR)
#"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $# -c $<
$(LIB_BIN)/%.c.o: $(LIBS_SHARED_BASE)/%.c
#echo $(COL_LIB)LIB [CC] $(notdir $<) $(COL_ERR)
#"$(CC)" $(C_FLAGS) $(INCLUDE) -o $# -c $<
# Local Libraries -------------------------------------------------------------
$(LIB_BIN)/%.s.o: $(LIBS_LOCAL_BASE)/%.S
#echo $(COL_LIB)LIB [ASM] $(notdir $<) $(COL_ERR)
#"$(CC)" $(S_FLAGS) $(INCLUDE) -o $# -c $<
$(LIB_BIN)/%.cpp.o: $(LIBS_LOCAL_BASE)/%.cpp
#echo $(COL_LIB)LIB [CPP] $(notdir $<) $(COL_ERR)
#"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $# -c $<
$(LIB_BIN)/%.c.o: $(LIBS_LOCAL_BASE)/%.c
#echo $(COL_LIB)LIB [CC] $(notdir $<) $(COL_ERR)
#"$(CC)" $(C_FLAGS) $(INCLUDE) -o $# -c $<
# Handle user sources ---------------------------------------------------------
$(USR_BIN)/%.s.o: $(USR_SRC)/%.S
#echo $(COL_SRC)USER [ASM] $< $(COL_ERR)
#"$(CC)" $(S_FLAGS) $(INCLUDE) -o "$#" -c $<
$(USR_BIN)/%.c.o: $(USR_SRC)/%.c
#echo $(COL_SRC)USER [CC] $(notdir $<) $(COL_ERR)
#"$(CC)" $(C_FLAGS) $(INCLUDE) -o "$#" -c $<
$(USR_BIN)/%.cpp.o: $(USR_SRC)/%.cpp
#echo $(COL_SRC)USER [CPP] $(notdir $<) $(COL_ERR)
#"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o "$#" -c $<
# Linking ---------------------------------------------------------------------
$(TARGET_ELF): $(CORE_LIB) $(LIB_OBJ) $(USR_OBJ)
#echo $(COL_LINK)
#echo [LD] $# $(COL_ERR)
#$(CC) $(LD_FLAGS) -o "$#" $(USR_OBJ) $(LIB_OBJ) $(CORE_LIB) $(LIBS)
#echo $(COL_OK)User code built and linked to libraries &&echo.
%.lst: %.elf
#echo [LST] $#
#$(OBJDUMP) -d -S --demangle --no-show-raw-insn "$<" > "$#"
#echo $(COL_OK)Sucessfully built project$(COL_RESET) &&echo.
%.sym: %.elf
#echo [SYM] $#
#$(NM) $(NM_FLAGS) "$<" > "$#"
%.hex: %.elf
#echo $(COL_LINK)[HEX] $#
#$(OBJCOPY) -O ihex -R.eeprom "$<" "$#"
# Cleaning --------------------------------------------------------------------
cleanUser:
#echo $(COL_LINK)Cleaning user binaries...$(COL_RESET)
#if exist $(USR_BIN) rd /s/q "$(USR_BIN)"
#if exist "$(TARGET_LST)" del $(subst /,\,$(TARGET_LST))
cleanCore:
#echo $(COL_LINK)Cleaning core binaries...$(COL_RESET)
#if exist $(CORE_BIN) rd /s/q "$(CORE_BIN)"
#if exist $(CORE_LIB) del $(subst /,\,$(CORE_LIB))
cleanLib:
#echo $(COL_LINK)Cleaning user library binaries...$(COL_RESET)
#if exist $(LIB_BIN) rd /s/q "$(LIB_BIN)"
# compiler generated dependency info ------------------------------------------
-include $(CORE_OBJ:.o=.d)
-include $(USR_OBJ:.o=.d)
-include $(LIB_OBJ:.o=.d)
This info may or may not not be necessary: I'm running a Teensy 3.2 on Visual Studio Code using Visual Teensy and TyCommander
Related
I wrote makefile which seems to works fine except for one case:
When I change the makefile itself it does not recompile all files.
I've done all those steps:
make clean
make all
make all (it returns "Nothing to be done for all") - ok
change makefile (add empty line etc.)
make all (still it returns "Nothing to be done for all" - not ok at all
In my opinion, it should recompile when the makefile file was changed.
What can be improved to force makefile to recompile all files when I make modifications in makefile?
Makefile:
################################### VARIABLES ############################################
# Output settings:
BUILD_DIR := ./build
BIN_DIR := $(BUILD_DIR)/bin
TARGET_FOLDER := $(BUILD_DIR)
TARGET_NAME := app.exe
# Input settings:
SOURCE_DIR = ./
SOURCES := $(SOURCE_DIR)/main.cpp
INCLUDES := $(SOURCE_DIR)
# Compilator settings:
CC := gcc
CXX := g++
# Compilation flags:
COMMON_FLAGS := -Wall -Werror
CFLAGS := $(COMMON_FLAGS)
CXXFLAGS := $(COMMON_FLAGS)
LDFLAGS :=
# VERBOSE OPTION
VERBOSE ?= 0 # Set to zero to silent makefile output
ifeq ($(VERBOSE),1)
NO_ECHO :=
else
NO_ECHO := #
endif
############################### MAGID PART START #########################################
TARGET := $(abspath $(TARGET_FOLDER)/$(TARGET_NAME))
# Remove double slash (//) from path, it can make issue with vpath.
# Just use abspath :)
SOURCES_ABS := $(abspath $(SOURCES) )
INCLUDES_ABS := $(abspath $(INCLUDES) )
SOURCES_C := $(filter %.c, $(SOURCES_ABS) )
SOURCES_CC := $(filter %.cc, $(SOURCES_ABS) )
SOURCES_CPP := $(filter %.cpp, $(SOURCES_ABS) )
OBJECTS_LIST := $(notdir $(patsubst %.c, %.o, $(SOURCES_C) ) )
OBJECTS_LIST += $(notdir $(patsubst %.cc, %.o, $(SOURCES_CC) ) )
OBJECTS_LIST += $(notdir $(patsubst %.cpp, %.o, $(SOURCES_CPP) ) )
OBJECTS := $(addprefix $(BIN_DIR)/, $(OBJECTS_LIST) )
DEPENDENCIES := $(patsubst %.o, %.d, $(OBJECTS) )
INCLUDES_FLAG := $(addprefix -I, $(INCLUDES_ABS) )
COMMON_FLAGS += $(INCLUDES_FLAG)
COMMON_FLAGS += -MMD -MP # Generate dependency files
CFLAGS += $(COMMON_FLAGS)
CXXFLAGS += $(COMMON_FLAGS)
# Use vpath to search sources:
VPATH += $(sort $(dir $(SOURCES_C) ) )
VPATH += $(sort $(dir $(SOURCES_CC) ) )
VPATH += $(sort $(dir $(SOURCES_CPP) ) )
all: app
app: $(TARGET)
$(TARGET): $(OBJECTS) | $(BUILD_DIR)
$(info Preparing: $#)
$(NO_ECHO) $(CXX) $(CXXFLAGS) -o $# $^
$(BIN_DIR)/%.o : %.c | $(BIN_DIR)
$(info Preparing: $#)
$(NO_ECHO) $(CC) -c $(CFLAGS) $< -o $#
$(BIN_DIR)/%.o : %.cc | $(BIN_DIR)
$(info Preparing: $#)
$(NO_ECHO) $(CXX) -c $(CXXFLAGS) $< -o $#
$(BIN_DIR)/%.o : %.cpp | $(BIN_DIR)
$(info Preparing: $#)
$(NO_ECHO) $(CXX) -c $(CXXFLAGS) $< -o $#
$(BIN_DIR): |$(BUILD_DIR)
$(NO_ECHO) -mkdir $#
$(BUILD_DIR):
$(NO_ECHO) -mkdir $#
.PHONY : clean
clean:
-rm -fr $(TARGET) $(BUILD_DIR) *.o *.d
-include $(DEPENDENCIES)
main.cpp
#include <iostream>
using namespace std;
int main(void)
{
cout<<"HA HA"<<endl;
return 0;
}
I have c++ Makefile project. Project simplified folder looks as below:
tmp|
|--Makefile
|--lvgl
| |--lvgl.h
|--lv_drivers
| |--display
| |--fbdev.h
Unit fbdev.h contains include:
#include "lvgl/lvgl.h"
I have error while build related to this include:
lvgl/lvgl.h: No such file or directory
How to ask build system to find lvgl/lvgl.h by searching from from project root folder. Should I somehow define in Makefile project root location?
Autogenerated Makefile:
#Generated by VisualGDB project wizard.
#Note: VisualGDB will automatically update this file when you add new sources to the project.
#All other changes you make in this file will be preserved.
#Visit http://visualgdb.com/makefiles for more details
#VisualGDB: AutoSourceFiles #<--- remove this line to disable auto-updating of SOURCEFILES and EXTERNAL_LIBS
TARGETNAME := boilerX
#TARGETTYPE can be APP, STATIC or SHARED
TARGETTYPE := APP
to_lowercase = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
macros-to-preprocessor-directives = $(foreach __macro, $(strip $1), \
$(if $(findstring =,$(__macro)), \
--pd "$(firstword $(subst =, ,$(__macro))) SETA $(subst ",\",$(lastword $(subst =, ,$(__macro))))", \
--pd "$(__macro) SETA 1")) \
CONFIG ?= DEBUG
CONFIGURATION_FLAGS_FILE := $(call to_lowercase,$(CONFIG)).mak
TOOLCHAIN_ROOT ?= $(toolchain_root)
include $(CONFIGURATION_FLAGS_FILE)
#LINKER_SCRIPT defined inside the configuration file (e.g. debug.mak) should override any linker scripts defined in shared .mak files
CONFIGURATION_LINKER_SCRIPT := $(LINKER_SCRIPT)
include $(ADDITIONAL_MAKE_FILES)
ifneq ($(CONFIGURATION_LINKER_SCRIPT),)
LINKER_SCRIPT := $(CONFIGURATION_LINKER_SCRIPT)
endif
ifneq ($(LINKER_SCRIPT),)
ifeq ($(TOOLCHAIN_SUBTYPE),iar)
LDFLAGS += --config $(LINKER_SCRIPT)
else
LDFLAGS += -T$(LINKER_SCRIPT)
endif
endif
ifeq ($(AS),)
AS := as
endif
ifeq ($(AS),as)
AS := $(CC)
ASFLAGS := $(CFLAGS) $(ASFLAGS)
endif
ifeq ($(TOOLCHAIN_SUBTYPE),iar)
CC_DEPENDENCY_FILE_SPECIFIER := --dependencies=m
ASM_DEPENDENCY_FILE_SPECIFIER := && echo >
CXXFLAGS += --c++
COMMONFLAGS += --silent
else ifeq ($(TOOLCHAIN_SUBTYPE),armcc)
CC_DEPENDENCY_FILE_SPECIFIER := --depend
ASM_DEPENDENCY_FILE_SPECIFIER := --depend
USING_KEIL_TOOLCHAIN := 1
else ifeq ($(TOOLCHAIN_SUBTYPE),armclang)
CC_DEPENDENCY_FILE_SPECIFIER := -MD -MF
ASM_DEPENDENCY_FILE_SPECIFIER := --depend
USING_KEIL_TOOLCHAIN := 1
else
CC_DEPENDENCY_FILE_SPECIFIER := -MD -MF
ASM_DEPENDENCY_FILE_SPECIFIER := -MD -MF
endif
ifeq ($(BINARYDIR),)
error:
$(error Invalid configuration, please check your inputs)
endif
SOURCEFILES := boiler.cpp boilerX.cpp boiler_ui.cpp lvgl/examples/porting/lv_port_disp_template.c lvgl/examples/porting/lv_port_fs_template.c lvgl/examples/porting/lv_port_indev_template.c lvgl/src/lv_core/lv_disp.c lvgl/src/lv_core/lv_group.c lvgl/src/lv_core/lv_indev.c lvgl/src/lv_core/lv_obj.c lvgl/src/lv_core/lv_refr.c lvgl/src/lv_core/lv_style.c lvgl/src/lv_draw/lv_draw_arc.c lvgl/src/lv_draw/lv_draw_blend.c lvgl/src/lv_draw/lv_draw_img.c lvgl/src/lv_draw/lv_draw_label.c lvgl/src/lv_draw/lv_draw_line.c lvgl/src/lv_draw/lv_draw_mask.c lvgl/src/lv_draw/lv_draw_rect.c lvgl/src/lv_draw/lv_draw_triangle.c lvgl/src/lv_draw/lv_img_buf.c lvgl/src/lv_draw/lv_img_cache.c lvgl/src/lv_draw/lv_img_decoder.c lvgl/src/lv_font/lv_font.c lvgl/src/lv_font/lv_font_dejavu_16_persian_hebrew.c lvgl/src/lv_font/lv_font_fmt_txt.c lvgl/src/lv_font/lv_font_loader.c lvgl/src/lv_font/lv_font_montserrat_10.c lvgl/src/lv_font/lv_font_montserrat_12.c lvgl/src/lv_font/lv_font_montserrat_12_subpx.c lvgl/src/lv_font/lv_font_montserrat_14.c lvgl/src/lv_font/lv_font_montserrat_16.c lvgl/src/lv_font/lv_font_montserrat_18.c lvgl/src/lv_font/lv_font_montserrat_20.c lvgl/src/lv_font/lv_font_montserrat_22.c lvgl/src/lv_font/lv_font_montserrat_24.c lvgl/src/lv_font/lv_font_montserrat_26.c lvgl/src/lv_font/lv_font_montserrat_28.c lvgl/src/lv_font/lv_font_montserrat_28_compressed.c lvgl/src/lv_font/lv_font_montserrat_30.c lvgl/src/lv_font/lv_font_montserrat_32.c lvgl/src/lv_font/lv_font_montserrat_34.c lvgl/src/lv_font/lv_font_montserrat_36.c lvgl/src/lv_font/lv_font_montserrat_38.c lvgl/src/lv_font/lv_font_montserrat_40.c lvgl/src/lv_font/lv_font_montserrat_42.c lvgl/src/lv_font/lv_font_montserrat_44.c lvgl/src/lv_font/lv_font_montserrat_46.c lvgl/src/lv_font/lv_font_montserrat_48.c lvgl/src/lv_font/lv_font_montserrat_8.c lvgl/src/lv_font/lv_font_simsun_16_cjk.c lvgl/src/lv_font/lv_font_unscii_16.c lvgl/src/lv_font/lv_font_unscii_8.c lvgl/src/lv_gpu/lv_gpu_nxp_pxp.c lvgl/src/lv_gpu/lv_gpu_nxp_pxp_osa.c lvgl/src/lv_gpu/lv_gpu_nxp_vglite.c lvgl/src/lv_gpu/lv_gpu_stm32_dma2d.c lvgl/src/lv_hal/lv_hal_disp.c lvgl/src/lv_hal/lv_hal_indev.c lvgl/src/lv_hal/lv_hal_tick.c lvgl/src/lv_misc/lv_anim.c lvgl/src/lv_misc/lv_area.c lvgl/src/lv_misc/lv_async.c lvgl/src/lv_misc/lv_bidi.c lvgl/src/lv_misc/lv_color.c lvgl/src/lv_misc/lv_debug.c lvgl/src/lv_misc/lv_fs.c lvgl/src/lv_misc/lv_gc.c lvgl/src/lv_misc/lv_ll.c lvgl/src/lv_misc/lv_log.c lvgl/src/lv_misc/lv_math.c lvgl/src/lv_misc/lv_mem.c lvgl/src/lv_misc/lv_printf.c lvgl/src/lv_misc/lv_task.c lvgl/src/lv_misc/lv_templ.c lvgl/src/lv_misc/lv_txt.c lvgl/src/lv_misc/lv_txt_ap.c lvgl/src/lv_misc/lv_utils.c lvgl/src/lv_themes/lv_theme.c lvgl/src/lv_themes/lv_theme_empty.c lvgl/src/lv_themes/lv_theme_material.c lvgl/src/lv_themes/lv_theme_mono.c lvgl/src/lv_themes/lv_theme_template.c lvgl/src/lv_widgets/lv_arc.c lvgl/src/lv_widgets/lv_bar.c lvgl/src/lv_widgets/lv_btn.c lvgl/src/lv_widgets/lv_btnmatrix.c lvgl/src/lv_widgets/lv_calendar.c lvgl/src/lv_widgets/lv_canvas.c lvgl/src/lv_widgets/lv_chart.c lvgl/src/lv_widgets/lv_checkbox.c lvgl/src/lv_widgets/lv_cont.c lvgl/src/lv_widgets/lv_cpicker.c lvgl/src/lv_widgets/lv_dropdown.c lvgl/src/lv_widgets/lv_gauge.c lvgl/src/lv_widgets/lv_img.c lvgl/src/lv_widgets/lv_imgbtn.c lvgl/src/lv_widgets/lv_keyboard.c lvgl/src/lv_widgets/lv_label.c lvgl/src/lv_widgets/lv_led.c lvgl/src/lv_widgets/lv_line.c lvgl/src/lv_widgets/lv_linemeter.c lvgl/src/lv_widgets/lv_list.c lvgl/src/lv_widgets/lv_msgbox.c lvgl/src/lv_widgets/lv_objmask.c lvgl/src/lv_widgets/lv_objx_templ.c lvgl/src/lv_widgets/lv_page.c lvgl/src/lv_widgets/lv_roller.c lvgl/src/lv_widgets/lv_slider.c lvgl/src/lv_widgets/lv_spinbox.c lvgl/src/lv_widgets/lv_spinner.c lvgl/src/lv_widgets/lv_switch.c lvgl/src/lv_widgets/lv_table.c lvgl/src/lv_widgets/lv_tabview.c lvgl/src/lv_widgets/lv_textarea.c lvgl/src/lv_widgets/lv_tileview.c lvgl/src/lv_widgets/lv_win.c lvgl/tests/lv_test_assert.c lvgl/tests/lv_test_core/lv_test_core.c lvgl/tests/lv_test_core/lv_test_font_loader.c lvgl/tests/lv_test_core/lv_test_obj.c lvgl/tests/lv_test_core/lv_test_style.c lvgl/tests/lv_test_fonts/font_1.c lvgl/tests/lv_test_fonts/font_2.c lvgl/tests/lv_test_fonts/font_3.c lvgl/tests/lv_test_main.c lvgl/tests/lv_test_widgets/lv_test_label.c
EXTERNAL_LIBS :=
EXTERNAL_LIBS_COPIED := $(foreach lib, $(EXTERNAL_LIBS),$(BINARYDIR)/$(notdir $(lib)))
CFLAGS += $(COMMONFLAGS)
CXXFLAGS += $(COMMONFLAGS)
ASFLAGS += $(COMMONFLAGS)
LDFLAGS += $(COMMONFLAGS)
CFLAGS += $(addprefix -I,$(INCLUDE_DIRS))
CXXFLAGS += $(addprefix -I,$(INCLUDE_DIRS))
CFLAGS += $(addprefix -D,$(PREPROCESSOR_MACROS))
CXXFLAGS += $(addprefix -D,$(PREPROCESSOR_MACROS))
ifeq ($(USING_KEIL_TOOLCHAIN),1)
ASFLAGS +=$(call macros-to-preprocesor-directives, $(PREPROCESSOR_MACROS))
else ifeq ($(TOOLCHAIN_SUBTYPE),iar)
ASFLAGS := $(subst --cpu=,--cpu ,$(ASFLAGS))
ASFLAGS := $(subst --fpu=,--fpu ,$(ASFLAGS))
ASFLAGS := $(subst --silent,-S ,$(ASFLAGS))
ASFLAGS += $(addprefix -D,$(PREPROCESSOR_MACROS))
else
ASFLAGS += $(addprefix -D,$(PREPROCESSOR_MACROS))
endif
CXXFLAGS += $(addprefix -framework ,$(MACOS_FRAMEWORKS))
CFLAGS += $(addprefix -framework ,$(MACOS_FRAMEWORKS))
LDFLAGS += $(addprefix -framework ,$(MACOS_FRAMEWORKS))
LDFLAGS += $(addprefix -L,$(LIBRARY_DIRS))
ifeq ($(GENERATE_MAP_FILE),1)
LDFLAGS += -Wl,-Map=$(BINARYDIR)/$(basename $(TARGETNAME)).map
endif
LIBRARY_LDFLAGS = $(addprefix -l,$(LIBRARY_NAMES))
ifeq ($(IS_LINUX_PROJECT),1)
RPATH_PREFIX := -Wl,--rpath='$$ORIGIN/../
LIBRARY_LDFLAGS += $(EXTERNAL_LIBS)
LIBRARY_LDFLAGS += -Wl,--rpath='$$ORIGIN'
LIBRARY_LDFLAGS += $(addsuffix ',$(addprefix $(RPATH_PREFIX),$(dir $(EXTERNAL_LIBS))))
ifeq ($(TARGETTYPE),SHARED)
CFLAGS += -fPIC
CXXFLAGS += -fPIC
ASFLAGS += -fPIC
LIBRARY_LDFLAGS += -Wl,-soname,$(TARGETNAME)
endif
ifneq ($(LINUX_PACKAGES),)
PACKAGE_CFLAGS := $(foreach pkg,$(LINUX_PACKAGES),$(shell pkg-config --cflags $(pkg)))
PACKAGE_LDFLAGS := $(foreach pkg,$(LINUX_PACKAGES),$(shell pkg-config --libs $(pkg)))
CFLAGS += $(PACKAGE_CFLAGS)
CXXFLAGS += $(PACKAGE_CFLAGS)
LIBRARY_LDFLAGS += $(PACKAGE_LDFLAGS)
endif
else
LIBRARY_LDFLAGS += $(EXTERNAL_LIBS)
endif
LIBRARY_LDFLAGS += $(ADDITIONAL_LINKER_INPUTS)
all_make_files := $(firstword $(MAKEFILE_LIST)) $(CONFIGURATION_FLAGS_FILE) $(ADDITIONAL_MAKE_FILES)
ifeq ($(STARTUPFILES),)
all_source_files := $(SOURCEFILES)
else
all_source_files := $(STARTUPFILES) $(filter-out $(STARTUPFILES),$(SOURCEFILES))
endif
source_obj1 := $(all_source_files:.cpp=.o)
source_obj2 := $(source_obj1:.c=.o)
source_obj3 := $(source_obj2:.s=.o)
source_obj4 := $(source_obj3:.S=.o)
source_obj5 := $(source_obj4:.cc=.o)
source_objs := $(source_obj5:.cxx=.o)
all_objs := $(addprefix $(BINARYDIR)/, $(notdir $(source_objs)))
PRIMARY_OUTPUTS :=
ifeq ($(GENERATE_BIN_FILE),1)
PRIMARY_OUTPUTS += $(BINARYDIR)/$(basename $(TARGETNAME)).bin
endif
ifeq ($(GENERATE_IHEX_FILE),1)
PRIMARY_OUTPUTS += $(BINARYDIR)/$(basename $(TARGETNAME)).ihex
endif
ifeq ($(PRIMARY_OUTPUTS),)
PRIMARY_OUTPUTS := $(BINARYDIR)/$(TARGETNAME)
endif
all: $(PRIMARY_OUTPUTS)
ifeq ($(USING_KEIL_TOOLCHAIN),1)
$(BINARYDIR)/$(basename $(TARGETNAME)).bin: $(BINARYDIR)/$(TARGETNAME)
$(OBJCOPY) --bin $< --output $#
$(BINARYDIR)/$(basename $(TARGETNAME)).ihex: $(BINARYDIR)/$(TARGETNAME)
$(OBJCOPY) --i32 $< --output $#
else ifeq ($(TOOLCHAIN_SUBTYPE),iar)
$(BINARYDIR)/$(basename $(TARGETNAME)).bin: $(BINARYDIR)/$(TARGETNAME)
$(OBJCOPY) --silent --bin $< $#
$(BINARYDIR)/$(basename $(TARGETNAME)).ihex: $(BINARYDIR)/$(TARGETNAME)
$(OBJCOPY) --silent --bin $< $#
else
$(BINARYDIR)/$(basename $(TARGETNAME)).bin: $(BINARYDIR)/$(TARGETNAME)
$(OBJCOPY) -O binary $< $#
$(BINARYDIR)/$(basename $(TARGETNAME)).ihex: $(BINARYDIR)/$(TARGETNAME)
$(OBJCOPY) -O ihex $< $#
endif
EXTRA_DEPENDENCIES :=
ifneq ($(LINKER_SCRIPT),)
EXTRA_DEPENDENCIES += $(LINKER_SCRIPT)
endif
ifeq ($(TARGETTYPE),APP)
$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTERNAL_LIBS) $(EXTRA_DEPENDENCIES)
ifeq ($(DETACH_CODE_COVERAGE),1)
$(VISUALGDB_DIR)/VisualGDB.exe /decover $# $(all_objs)
endif
$(LD) -o $# $(LDFLAGS) $(START_GROUP) $(all_objs) $(LIBRARY_LDFLAGS) $(END_GROUP)
endif
ifeq ($(TARGETTYPE),SHARED)
$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTERNAL_LIBS) $(EXTRA_DEPENDENCIES)
$(LD) -shared -o $# $(LDFLAGS) $(START_GROUP) $(all_objs) $(LIBRARY_LDFLAGS) $(END_GROUP)
endif
ifeq ($(TARGETTYPE),STATIC)
$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTRA_DEPENDENCIES)
$(AR) -r $# $^
endif
-include $(all_objs:.o=.dep)
clean:
ifeq ($(USE_DEL_TO_CLEAN),1)
cmd /C del /S /Q $(BINARYDIR)
else
rm -rf $(BINARYDIR)
endif
$(BINARYDIR):
mkdir $(BINARYDIR)
#VisualGDB: FileSpecificTemplates #<--- VisualGDB will use the following lines to define rules for source files in subdirectories
$(BINARYDIR)/%.o : %.cpp $(all_make_files) |$(BINARYDIR)
$(CXX) $(CXXFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/%.o : %.c $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/%.o : %.S $(all_make_files) |$(BINARYDIR)
$(AS) $(ASFLAGS) -c $< -o $# $(ASM_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/%.o : %.s $(all_make_files) |$(BINARYDIR)
$(AS) $(ASFLAGS) -c $< -o $# $(ASM_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/%.o : %.cc $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) $(CXXFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/%.o : %.cxx $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) $(CXXFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER)F $(#:.o=.dep)
#VisualGDB: GeneratedRules #<--- All lines below are auto-generated. Remove this line to suppress auto-generation of file rules.
$(BINARYDIR)/lv_port_disp_template.o : lvgl/examples/porting/lv_port_disp_template.c $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/lv_port_fs_template.o : lvgl/examples/porting/lv_port_fs_template.c $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/lv_port_indev_template.o : lvgl/examples/porting/lv_port_indev_template.c $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/lv_disp.o : lvgl/src/lv_core/lv_disp.c $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/lv_group.o : lvgl/src/lv_core/lv_group.c $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
$(BINARYDIR)/lv_indev.o : lvgl/src/lv_core/lv_indev.c $(all_make_files) |$(BINARYDIR)
$(CC) $(CFLAGS) -c $< -o $# $(CC_DEPENDENCY_FILE_SPECIFIER) $(#:.o=.dep)
.............
I'm currently using MinGW64, G++, and a makefile to compile my c++ project on VSCode. I have two src directories src and src/vendor/imGui containing .cpp files that I compile. As of now, the makefile is able to compile both src folders. However, the .o files are outputted in their respective src folders. How can I make it so that every .o file generated gets sent to one specific folder/directory?
Current Makefile:
CXX = g++
CXXFLAGS := -std=c++17 -Wall -Wextra -g
LFLAGS += -LC:/mingw64/x86_64-w64-mingw32/bin
LFLAGS += -LC:/mingw64/x86_64-w64-mingw32/lib
OUTPUT := output
SRC := src
SRC += src/vendor/imGui
INCLUDE := include
LIB := lib
ifeq ($(OS),Windows_NT)
MAIN := main.exe
SOURCEDIRS := $(SRC)
INCLUDEDIRS := $(INCLUDE)
LIBDIRS := $(LIB)
FIXPATH = $(subst /,\,$1)
RM := del /q /f
MD := mkdir
else
MAIN := main
SOURCEDIRS := $(shell find $(SRC) -type d)
INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
LIBDIRS := $(shell find $(LIB) -type d)
FIXPATH = $1
RM = rm -f
MD := mkdir -p
endif
INCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
INCLUDES += -IC:/Users/kimda/Desktop/Projects/C++/Libraries/glm
INCLUDES += -IC:/mingw64/x86_64-w64-mingw32/include
INCLUDES += -IC:/Users/kimda/Desktop/Projects/C++/OpenGL/src/vendor/imGui
LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
LIBS += -lglew32
LIBS += -lopengl32
LIBS += -lglfw3
LIBS += -lgdi32
LIBS += -lglu32
SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
OBJECTS := $(SOURCES:.cpp=.o)
OUTPUTMAIN := $(call FIXPATH,$(OUTPUT)/$(MAIN))
all: $(OUTPUT) $(MAIN)
#echo Building complete!
$(OUTPUT):
#$(MD) $(OUTPUT)
$(MAIN): $(OBJECTS)
#$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(OBJECTS) $(LFLAGS) $(LIBS)
.cpp.o:
#$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $#
.PHONY: clean
clean:
#$(RM) $(OUTPUTMAIN)
#$(RM) $(call FIXPATH,$(OBJECTS))
#echo Cleanup complete!
run: clean all
#./$(OUTPUTMAIN)
#echo Executing complete!
If I understand you correctly you want to send all object files to some 'build' directory.
I usually do something like this
BUILDDIR := build
[...]
OBJECTS := $(addprefix $(BUILDDIR)/,$(SOURCES:.cpp=.o))
[...]
and then change your
.cpp.o:
#$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $#
to
$(BUILDDIR)/%.o: %.cpp
#$(MD) $(dir $#)
#$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $#
I'm using CODEO (Eclipse + overlay) to build an app for the ELinOS RTOS.
Thing is, I lose the ability to auto-generate the Makefile using eclipse CDT and I have a generic Makefile alreayd generated.
Instead of typing this huge Makefile (Lots and lots of include and sources directories), I tried things with addprefix patsubst and some wildcard but that didn't work out, mainly because I suck with generic makefile !
Regarding libraries, only a few are used, so I'll write them by hand.
Here is how my code is structured.
Top directory
|
---> common ---> inc/
| src/
---> pack_AAA ---> comp_AAA ---> inc/
| | src/
| ----> comp_AAB ---> inc/
| src/
---> comp_BBB ---> inc/
| src/
---> main.cpp
I'd like to enumerate only the top folders (common, pack_AAA, comp_BBB and so on, mostly because not every TOP folder has to be compiled, my Makefile is in one of these top folder).
Below there is a variable amount of subdirectories. Leafs are ALWAYS inc/ (.hpp files) and src/ (as you might guess, .cpp files) folders.
Moreover, the amount of TOP folders won't change, so I mind declaring them, but subfolders will.
Objects files can be anywhere they want (separate top build/ directory, within src/ ...) as long as the resulting executable, let's call it HUGE_PROJECT is in the top directory
Thanks in advance !
SOKS
Here is the generated makefile that I have to start with
-include makefile.init
RM := rm -rf
PROG = HUGE_PROJECT_EXECUTABLE
MODULES := common comp_AAA comp_BBB pack_AAA pack_BBB pack_CCC
SRC_DIRS := $(addprefix ../../,$(MODULES))
#BUILD_DIR := $(addprefix ../../build/,$(MODULES))
#Original non-recursive & working example
OBJS = $(patsubst %.cpp,%.o,$(wildcard ./src/*.cpp))
DEPS = $(patsubst %.cpp,%.d,$(wildcard ./src/*.cpp))
#bad attempt
#SRCS := $(foreach sdir,$(SRC_DIRS),$(wildcard $(sdir)/*.cpp))
#OBJS := $(patsubst %.cpp,%.o,$(SRCS))
#INCLUDES := $(addprefix -I,$(SRC_DIR))
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(DEPS)),)
-include $(DEPS)
endif
endif
-include makefile.defs
# All Target
all: $(PROG).tgz
$(PROG).tgz: $(PROG).mkefs $(PROG)
#echo 'Building file: $#'
#echo 'Invoking: Embeddable file system generator'
mkefs -a -s -o"$#" -f"$<"
#echo 'Finished building: $#'
#echo ' '
$(PROG): $(OBJS) $(USER_OBJS)
#echo 'Building target: $#'
#echo 'Invoking: ELinOS C/C++ Linker'
$(CXX) -o "$(PROG)" $(SRCS) $(USER_OBJS) $(LIBS)
#echo 'Finished building target: $#'
#echo ' '
clean:
-$(RM) $(OBJS) $(DEPS) $(PROG) $(PROG).tgz
-#echo ' '
./src/%.o: ./src/%.cpp
#echo 'Building file: $<'
#echo 'Invoking: ELinOS C/C++ Compiler'
$(CXX) -I./include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#:%.o=%.d)" -o "$#" "$<"
#echo 'Finished building: $<'
#echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include makefile.targets
Here is the Makefile I ended up with.
I had to hide components name.
#Executables
RM := rm -rf
CXX=YOUR_CXX_COMPILER
CC=YOUR_CC_COMPILER
PROG=YOUR_PROGRAM
#Root directory of your program (all files should be in it)
ROOT_DIR := ../../
#####################################
########################################
# Define here all directories #
# containing src/ and inc/ folders #
########################################
#pack_AAA folders
#Modules containing both src/ and inc/.
AAA_MODULES := moduleA moduleB
#Modules with an include folder only + module with both
AAA_DIRS_INC := moduleD moduleEF $(AAA_MODULES)
#pack_BBB modules list
BBB_MODULES := comp_A comp_B comp_C comp_B/comp_D comp_B/comp_E
MMM_MODULES := comp_F comp_G comp_H
PPP_MODULES := . I
CCC_MODULES := J comp_K comp_L \
comp_L/comp_M \
$(addprefix pack_BBB/,$(BBB_MODULES)) \
$(addprefix pack_MMM/,$(MMM_MODULES)) \
$(addprefix comp_PPP/,$(PPP_MODULES))
#pack_DDD
DDD_MODULES := M comp_N comp_N/comp_O
#comp_EEE
EEE_MODULES := . P Q
OTHER_MODULES := R S comp_T
#All folders containing src/ subdir
SRC_MODULES := $(OTHER_MODULES) \
$(addprefix comp_EEE/,$(EEE_MODULES)) \
$(addprefix pack_DDD/,$(DDD_MODULES)) \
$(addprefix pack_AAA/,$(AAA_MODULES)) \
$(addprefix pack_CCC/, $(CCC_MODULES))
#All folders containing inc/ subdir
INCLUDE_MODULES := $(OTHER_MODULES) \
$(addprefix comp_EEE/,$(EEE_MODULES)) \
$(addprefix pack_DDD/,$(DDD_MODULES)) \
$(addprefix pack_AAA/,$(AAA_DIRS_INC)) \
$(addprefix pack_CCC/, $(CCC_MODULES))
#####################################
#WRAPPERS
ROOT_DIR_WRAPPERS := $(ROOT_DIR)../WRAPPERS/
LIST_WRAPPERS := WA WB WC WD
SRC_WRAPPERS := $(addprefix pack_Wrappers/csc_Wrapper,$(LIST_WRAPPERS))
#DRIVERS
LIST_DRIVERS := DA DB DC DD
DIR_DRIVERS := $(addprefix pack_Drivers/csc_Driver,$(LIST_DRIVERS))
SRC_DIRS_WRAPPERS := $(addsuffix /src,$(SRC_WRAPPERS))
INCLUDE_DIRS_WRAPPERS := $(addsuffix /inc,$(SRC_WRAPPERS)) \
$(addsuffix /inc,$(DIR_DRIVERS)) \
Common
#####################################
#LIB_1 INCLUDE
ROOT_DIR_LIB_1 := $(ROOT_DIR)../../ObjetsCompiles/LIB_1/
INCLUDE_DIRS_LIB_1 := dir1 dir2 dir3
#####################################
#LIB_2 INCLUDE
ROOT_DIR_LIB_2 := $(ROOT_DIR)../../ObjetsCompiles/LIB_2/include
INCLUDE_DIRS_LIB_2 := . dir1 dir2 dir3/subdir dir4
#####################################
#Add "." to find main.cpp
SRC_DIRS := $(addsuffix /src,$(SRC_MODULES)) .
INCLUDE_DIRS_SRC:= $(addsuffix /inc,$(INCLUDE_MODULES)) pack_ZZZ/comp_Without_Inc_Folder
#All include dirs, LIB_1 + LIB_2
INCLUDE_DIRS := $(addprefix -I$(ROOT_DIR),$(INCLUDE_DIRS_SRC)) \
$(addprefix -I$(ROOT_DIR_LIB_1),$(INCLUDE_DIRS_LIB_1)) \
$(addprefix -I$(ROOT_DIR_LIB_2),$(INCLUDE_DIRS_LIB_2))
INCLUDE_DIRS_CC := $(addprefix -I$(ROOT_DIR_WRAPPERS),$(INCLUDE_DIRS_WRAPPERS)) \
$(addprefix -I$(ROOT_DIR_LIB_2),$(INCLUDE_DIRS_LIB_2))
#All objects (all .cpp & all .c)
OBJS := $(foreach dir,$(SRC_DIRS), \
$(patsubst %.cpp,%.o,$(wildcard $(ROOT_DIR)$(dir)/*.cpp))) \
$(foreach dirs,$(SRC_DIRS_WRAPPERS), \
$(patsubst %.c,%.o,$(wildcard $(ROOT_DIR_WRAPPERS)$(dirs)/*.c)))
#All dependencies (same list as OBJS)
DEPS := $(foreach dir,$(SRC_DIRS), \
$(patsubst %.cpp,%.d,$(wildcard $(ROOT_DIR)$(dir)/*.cpp))) \
$(foreach dirs,$(SRC_DIRS_WRAPPERS), \
$(patsubst %.c,%.d,$(wildcard $(ROOT_DIR_WRAPPERS)$(dirs)/*.c)))
#Exclude files from build
#Win32 socket files + some misc
EXCLUDED_FILES_LIST := pack_AAA/comp_BBB/src/SocketWindowsOnLinuxForExample.cpp \
pack_BBB/comp_CCC/src/SomeOtherThingForWindows.cpp
EXCLUDED_FILES_PATH := $(addprefix $(ROOT_DIR),$(EXCLUDED_FILES_LIST))
#Remove some objects (compilation is done, but no link)
EXCLUDED_OBJS := $(patsubst %.cpp,%.o,$(EXCLUDED_FILES_PATH))
EXCLUDED_DEPS := $(patsubst %.cpp,%.d,$(EXCLUDED_FILES_PATH))
#Update OBJS & DEPS list with excluded files
OBJS := $(filter-out $(EXCLUDED_OBJS),$(OBJS))
DEPS := $(filter-out $(EXCLUDED_DEPS),$(DEPS))
#FLAGS for DEBUG and RELEASE compilation
CPPFLAGS := -D__CPPFLAG1__ -D__CPPFLAG2__
CFLAGS_D := -O0 -g2 -Wall -c -fmessage-length=0
CXXFLAGS_D := -O0 -g2 -Wall -c -fmessage-length=0 -m32 -mcpu=powerpc -Winline
CFLAGS_R := -O2 -g0 -Wall -c -fmessage-length=0
CXXFLAGS_R := -O2 -g0 -Wall -c -fmessage-length=0 -m32 -mcpu=powerpc -Winline
# L
LD_PATH := -L../../path_library_1 -L../../path_library_2
LD_LIBS := -lpthread_rt -lROHC -lpthread -lnative -lrtdm -lrt
MAP := $(PROG).map
# -s (to strip)
LD_FLAGS_D := -Wl,--wrap,pthread_create -Wl,--wrap,pthread_kill -Wl,-Map,$(MAP)
LD_FLAGS_R := -s -Wl,--wrap,pthread_create -Wl,--wrap,pthread_kill -Wl,-Map,$(MAP)
##################################################
#TARGETS
default: release
#Debug flags (-00 + -g2)
debug: CFLAGS := $(CFLAGS_D)
debug: CXXFLAGS := $(CXXFLAGS_D)
debug: LD_FLAGS := $(LD_FLAGS_D)
debug: all
#Release flags (-s + -02 + -g0)
release: CFLAGS := $(CFLAGS_R)
release: CXXFLAGS := $(CXXFLAGS_R)
release: LD_FLAGS := $(LD_FLAGS_R)
release: all
all: $(PROG)
# Tool invocations
$(PROG): $(OBJS)
#echo 'Building target: $#'
#$(CXX) $(LD_FLAGS) $(LD_PATH) -o "$(PROG)" $(OBJS) $(LD_LIBS)
#echo 'Finished building target: $#'
#echo ' '
# CXX compiler used by most of the code
%.o: %.cpp
#echo 'Building file: $<'
#$(CXX) $(CPPFLAGS) $(INCLUDE_DIRS) $(CXXFLAGS) -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#:%.o=%.d)" -o "$#" "$<"
# CC compiler used by Wrappers only
%.o: %.c
#echo 'Building file: $<'
#$(CC) $(INCLUDE_DIRS_CC) $(CFLAGS) -MMD -MP -MF"$(#:%.o=%.d)" -MT"$(#:%.o=%.d)" -o "$#" "$<"
# Other Targets
clean:
-$(RM) $(OBJS) $(DEPS) $(PROG) $(MAP)
-#echo ' '
.PHONY: all clean dependents
.SECONDARY:
I am coding to the NRF51822 bluetooth chip, in Eclipse with GCC and a makefile that I maintain myself.
My problem is that every time I press build, it will compile everything, which is beginning to take quite some time. I am not that experienced in creating and maintaining make-files, so I have no idea where to start in order to get it to build incremtal instead?
My makefile is composed like this (I know there's a lot, and I haven't created this myself - found it in a tutorial, so I don't know what's relevant and what's not :-) ):
PROJECT_NAME := my_project
export OUTPUT_FILENAME
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
TEMPLATE_PATH = nrf51_sdk/toolchain/gcc
ifeq ($(OS),Windows_NT)
include $(TEMPLATE_PATH)/Makefile.windows
else
include $(TEMPLATE_PATH)/Makefile.posix
endif
MK := mkdir
RM := rm -rf
#echo suspend
ifeq ("$(VERBOSE)","1")
NO_ECHO :=
else
NO_ECHO := #
endif
# Toolchain commands
CC := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc"
AS := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as"
AR := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r
LD := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld"
NM := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm"
OBJDUMP := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump"
OBJCOPY := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy"
SIZE := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size"
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
#source common to all targets
C_SOURCE_FILES += \
main.c \
file1.c \
file2.c \
file3.c \
file4.c \
#assembly files common to all targets
ASM_SOURCE_FILES = nrf51_sdk/toolchain/gcc/gcc_startup_nrf51.s
#includes common to all targets
INC_PATHS = -I Dir1/
INC_PATHS = -I Dir2
INC_PATHS += -I Dir3
INC_PATHS += -I Dir4
OBJECT_DIRECTORY = _build
LISTING_DIRECTORY =$(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY =$(OBJECT_DIRECTORY)
# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
#flags common to all targets
CFLAGS = -DSOFTDEVICE_PRESENT
CFLAGS += -DNRF51
CFLAGS += -DS110
CFLAGS += -DBOARD_PCA10028
CFLAGS += -DBLE_STACK_SUPPORT_REQD
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -O0 -g3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
#CFLAGS += -flto -fno-builtin
# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys
# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DSOFTDEVICE_PRESENT
ASMFLAGS += -DNRF51
ASMFLAGS += -DS110
ASMFLAGS += -DBOARD_PCA10028
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
#default target - first one defined
default: clean nrf51422_xxac_s110
#building all targets
all: clean
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e cleanobj
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e nrf51422_xxac_s110
#target for printing all targets
help:
#echo following targets are available:
#echo nrf51422_xxac_s110
#echo flash_softdevice
C_SOURCE_FILE_NAMES = $(notdir $(C_SOURCE_FILES))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
nrf51422_xxac_s110: OUTPUT_FILENAME := nrf51422_xxac_s110
nrf51422_xxac_s110: LINKER_SCRIPT=ble_app_hrs_gcc_nrf51.ld
nrf51422_xxac_s110: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
## Create build directories
$(BUILD_DIRECTORIES):
echo $(MAKEFILE_NAME)
$(MK) $#
# Create objects from C SRC files
$(OBJECT_DIRECTORY)/%.o: %.c
#echo Compiling file: $(notdir $<)
#echo arm-none-eabi-gcc $(CFLAGS) $(INC_PATHS) -c -o $# $<
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $# $<
# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
#echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $# $<
# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(OBJECTS)
#echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
## Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
finalize: genbin genhex echosize
genbin:
#echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
genhex:
#echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
echosize:
-#echo ""
$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
-#echo ""
clean:
$(RM) $(BUILD_DIRECTORIES)
cleanobj:
$(RM) $(BUILD_DIRECTORIES)/*.o
flash: $(MAKECMDGOALS)
#echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex)
## Flash softdevice
flash_softdevice:
#echo Flashing: s110_softdevice.hex
nrfjprog --reset --program nrf51_sdk/softdevice/s110/hex/s110_softdevice.hex
all: clean
check this line. The default (first) Target of your Makefile depends on clean, so before any build is started, the clean target is executed that likely will remove all built files, to rebuild them.
Drop the clean and you should get the incremental behaviour make was designed for.