# MIT License # # Copyright (c) 2018, Alexey Dynda # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ################################################################# # Makefile to build ssd1306 examples for different platforms # # Accept the following parameters: # CC # CXX # STRIP # AR # MCU # FREQUENCY # # ADAFRUIT=y - compile Adafruit GFX module # ADAFRUIT_DIR=path_to_adafruit_gfx_library default: all DESTDIR ?= BLD ?= ../bld PROJECT ?= ssd1306_demo PROJECTS = $(subst /,,$(wildcard */)) BACKSLASH?=/ OUTFILE?=$(BLD)/$(PROJECT).out MKDIR?=mkdir -p convert=$(subst /,$(BACKSLASH),$1) .SUFFIXES: .bin .out .hex .srec $(BLD)/%.o: %.c -$(MKDIR) $(call convert,$(dir $@)) $(CC) -std=gnu11 $(CCFLAGS) $(CCFLAGS-$@) $(CCFLAGS-$(basename $(notdir $@))) -c $< -o $@ $(BLD)/%.o: %.ino -$(MKDIR) $(call convert,$(dir $@)) $(CXX) -std=c++11 $(CCFLAGS) $(CXXFLAGS) -x c++ -c $< -o $@ $(BLD)/%.o: %.cpp -$(MKDIR) $(call convert,$(dir $@)) $(CXX) -std=c++11 $(CCFLAGS) $(CXXFLAGS) $(CCFLAGS-$(basename $(notdir $@))) -c $< -o $@ ############### OPTIONS ####################### ifeq ($(ADAFRUIT),y) ADAFRUIT_DIR ?= $(shell readlink -f ~)/Arduino/libraries/Adafruit_GFX_Library INCLUDES += -I$(ADAFRUIT_DIR) CCFLAGS-Adafruit_GFX= -DARDUINO=100 SRCS += \ $(ADAFRUIT_DIR)/Adafruit_GFX.cpp endif # ************* Common defines ******************** INCLUDES += \ -I./$(PROJECT) \ -I../src CXXFLAGS += -fno-rtti CCFLAGS += -MD -g -Os -w -ffreestanding $(INCLUDES) -Wall -Werror \ -Wl,--gc-sections -ffunction-sections -fdata-sections \ $(EXTRA_CCFLAGS) .PHONY: clean ssd1306 all help SRCS += main.cpp \ $(wildcard $(PROJECT)/*.cpp) \ $(wildcard $(PROJECT)/*.ino) OBJS = $(addprefix $(BLD)/, $(addsuffix .o, $(basename $(SRCS)))) LDFLAGS += -L$(BLD) -lssd1306 ####################### Compiling library ######################### ssd1306: $(MAKE) -C ../src -f Makefile.$(platform) MCU=$(MCU) SDL_EMULATION=$(SDL_EMULATION) \ ADAFRUIT=$(ADAFRUIT) all: $(OUTFILE) $(OUTFILE): $(OBJS) ssd1306 -$(MKDIR) $(call convert,$(dir $@)) $(CC) -o $(OUTFILE) $(CCFLAGS) $(OBJS) $(LDFLAGS) clean: rm -rf $(BLD) rm -f *~ *.out *.bin *.hex *.srec *.s *.o *.pdf *core help: @echo "Makefile accepts the following options:" @echo " ADAFRUIT=y/n Enables compilation of Adafruit GFX library" @echo " ADAFRUIT_DIR=path Path to Adafruit GFX library" @echo " SDL_EMULATION=y/n Enables SDL emulator in the library" @echo " FREQUENCY=N Frequency in Hz" @echo " MCU=mcu_code Specifies MCU to compile for (valid for AVR)" -include $(OBJS:%.o=%.d)