Skip to content

Instantly share code, notes, and snippets.

@rjha
Created December 26, 2015 20:45
Show Gist options
  • Save rjha/b7cda6312552c3e15486 to your computer and use it in GitHub Desktop.
Save rjha/b7cda6312552c3e15486 to your computer and use it in GitHub Desktop.
makefile to compile Arduino Core into a static library
BIN=C:/arduino-1.0.5-r2/hardware/tools/avr/bin
TOOLS=C:/arduino-1.0.5-r2/hardware/tools/avr/bin
LIB=d:/rajeev/code/bitbucket/dl/lib
INC=d:/rajeev/code/bitbucket/dl/include
ROOT=d:/rajeev/code/bitbucket/dl
PROG=aout
MCU=atmega2560
ASRC=d:/rajeev/code/bitbucket/dl/lib/arduino
CPU_SPEED=16000000L
# ===============================================================
#
# compiler flags
# -c compile or assemble the source file but donot link
# -Os optimize for size
# change F_CPU value for target
#
# ================================================================
CFLAGS=-c -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=$(MCU) -MMD -DF_CPU=$(CPU_SPEED)
CC=avr-gcc
CXX=avr-g++
all: clean main
lib: compile
#$(BIN)/avr-ar rcs $(BUILD)/a/libarduino.a $(BUILD)/a/WInterrupts.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/realloc.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/malloc.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/wiring_shift.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/wiring_digital.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/wiring.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/wiring_analog.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/wiring_pulse.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/main.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/Tone.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/Stream.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/WString.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/new.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/WMath.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/HardwareSerial.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/HID.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/USBCore.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/CDC.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/Print.o
$(BIN)/avr-ar rcs $(BUILD)/libarduino.a $(BUILD)/IPAddress.o
compile:
$(BIN)/avr-gcc $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/avr-libc/realloc.c -o $(BUILD)/realloc.o
$(BIN)/avr-gcc $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/avr-libc/malloc.c -o $(BUILD)/malloc.o
$(BIN)/avr-gcc $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/wiring_shift.c -o $(BUILD)/wiring_shift.o
$(BIN)/avr-gcc $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/wiring_digital.c -o $(BUILD)/wiring_digital.o
$(BIN)/avr-gcc $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/wiring.c -o $(BUILD)/wiring.o
$(BIN)/avr-gcc $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/wiring_analog.c -o $(BUILD)/wiring_analog.o
$(BIN)/avr-gcc $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/wiring_pulse.c -o $(BUILD)/wiring_pulse.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/main.cpp -o $(BUILD)/main.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/Tone.cpp -o $(BUILD)/Tone.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/Stream.cpp -o $(BUILD)/Stream.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/WString.cpp -o $(BUILD)/WString.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/new.cpp -o $(BUILD)/new.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/WMath.cpp -o $(BUILD)/WMath.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/HardwareSerial.cpp -o $(BUILD)/HardwareSerial.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/HID.cpp -o $(BUILD)/HID.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/USBCore.cpp -o $(BUILD)/USBCore.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/CDC.cpp -o $(BUILD)/CDC.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/Print.cpp -o $(BUILD)/Print.o
$(BIN)/avr-g++ $(CFLAGS) -I$(ASRC)/cores -I$(ASRC)/variants/mega $(ASRC)/cores/IPAddress.cpp -o $(BUILD)/IPAddress.o
.PHONY: clean
clean:
-rm -rf $(BUILD)/*.o $(BUILD)/*.d $(BUILD)/*.a $(BUILD)/*.elf $(BUILD)/*.hex $(BUILD)/*.eep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment