Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / ocrandom / test / arduino / makefile
1 # Override with `make BUILD=release`
2 # default to debug build
3 BUILD := debug
4
5 # You must create the file "local.propertiessudo" on your local machine which contains any local paths, etc
6 # local_settings.mk should NOT be committed to repo
7 include ../../local.properties
8
9 # Compilers                   
10 CC := avr-gcc
11 CXX     := avr-g++
12 AR := avr-ar
13 OBJCopy := avr-objcopy
14
15 # Name of testing application
16 PROG := randomtest
17 C_COMPONENTS_DIR := ocrandom
18
19 # Folders that contain C source code
20 C_SRC_DIR := $(foreach d, $(C_COMPONENTS_DIR),../../../$d/src)
21
22 #Folders that contain C source code related to arduino
23 C_SRC_DIR_ARDUINO := $(ARDUINO_DIR)/hardware/arduino/cores/arduino
24
25 #Folders that contain CPP source code
26 CPP_SRC_DIR := ../../test/arduino
27
28 #Folders that contain CPP source code related to arduino
29 CPP_SRC_DIR_ARDUINO := $(ARDUINO_DIR)/hardware/arduino/cores/arduino
30
31 # Folders that contain Headers
32 TEMP_INC_DIR := $(foreach d, $(C_COMPONENTS_DIR),../../../$d/include)
33 TEMP_INC_DIR2 := $(foreach d, $(CXX_COMPONENTS_DIR),../../../$d/include)
34 INC_DIR := $(TEMP_INC_DIR) $(TEMP_INC_DIR2)
35 INC_DIR += $(ARDUINO_DIR)/hardware/arduino/cores/arduino
36 INC_DIR += $(ARDUINO_DIR)/hardware/arduino/variants/mega
37 INC_CMD = $(foreach d, $(INC_DIR), -I$d)
38
39 # Compiler flags specific to arduino
40 ARDUINO_FLAGS = -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -MMD
41
42 # Compiler flags
43 CC_FLAGS.debug := -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -std=c99 -DATMEGA2560 -DTB_LOG
44 CC_FLAGS.release := -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -std=c99 -DATMEGA2560
45 CC_FLAGS := $(CC_FLAGS.$(BUILD))
46
47 CXX_FLAGS.debug := -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -std=c++0x -DATMEGA2560 -DTB_LOG
48 CXX_FLAGS.release := -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -std=c++0x -DATMEGA2560
49 CXX_FLAGS := $(CXX_FLAGS.$(BUILD))
50
51 # using make's computed variables to select object and bin folders
52 # depending on the build type
53 OBJ_DIR.debug := ./obj/debug
54 OBJ_DIR.release := ./obj/release
55 OBJ_DIR := $(OBJ_DIR.$(BUILD))
56
57 BIN_DIR.debug := ./bin/debug
58 BIN_DIR.release := ./bin/release
59 BIN_DIR := $(BIN_DIR.$(BUILD))
60
61 C_FILES := $(shell find $(C_SRC_DIR) -maxdepth 1 -name '*.c')
62 CPP_FILES := $(shell find $(CPP_SRC_DIR) -maxdepth 1 -name '*.cpp')
63 OBJ_FILES := $(addprefix $(OBJ_DIR)/,$(notdir $(CPP_FILES:.cpp=.o) $(C_FILES:.c=.o)))
64
65 C_FILES_ARDUINO := $(shell find $(C_SRC_DIR_ARDUINO) -maxdepth 1 -name '*.c')
66 CPP_FILES_ARDUINO := $(shell find $(CPP_SRC_DIR_ARDUINO) -maxdepth 1 -name '*.cpp')
67 OBJ_FILES_ARDUINO := $(addprefix $(OBJ_DIR)/,$(notdir $(CPP_FILES_ARDUINO:.cpp=.o) $(C_FILES_ARDUINO:.c=.o)))
68
69 all: $(BIN_DIR)/$(PROG).hex
70
71 $(BIN_DIR)/core.a: $(OBJ_FILES_ARDUINO)
72         mkdir -p $(BIN_DIR)
73         $(AR) rcs $@ $^
74         #mv ./core.a ./$(BIN_DIR)
75         @echo ""
76         @echo 'done making core.a'
77
78 $(OBJ_DIR)/%.o: $(CPP_SRC_DIR_ARDUINO)/%.cpp
79         mkdir -p $(OBJ_DIR)
80         $(CXX) $(CXX_FLAGS) $(ARDUINO_FLAGS) $(INC_CMD) $< -o $@
81
82 $(OBJ_DIR)/%.o: $(CPP_SRC_DIR)/%.cpp
83         mkdir -p $(OBJ_DIR)
84         $(CXX) $(CXX_FLAGS) $(ARDUINO_FLAGS) $(INC_CMD) $< -o $@
85
86 $(OBJ_DIR)/%.o: $(C_SRC_DIR_ARDUINO)/%.c
87         mkdir -p $(OBJ_DIR)
88         $(CC) $(CC_FLAGS) $(ARDUINO_FLAGS) $(INC_CMD) $< -o $@
89
90 $(OBJ_DIR)/%.o: $(C_SRC_DIR)/%.c
91         mkdir -p $(OBJ_DIR)
92         $(CXX) $(CXX_FLAGS) $(ARDUINO_FLAGS) $(INC_CMD) $< -o $@
93
94 $(BIN_DIR)/$(PROG).elf: $(OBJ_FILES) $(BIN_DIR)/core.a
95         #$(CC) -Os -Wl,--gc-sections,--relax $(ARDUINO_FLAGS) $< $(BIN_DIR)/core.a -lm -o $@
96         #$(CC) -Os -Wl,--gc-sections,--relax $(ARDUINO_FLAGS) $(OBJ_FILES) $(OBJ_FILES_ARDUINO) -lm -o $@
97         $(CC) -Os -Wl,--gc-sections,--relax $(ARDUINO_FLAGS) $(OBJ_FILES) $(BIN_DIR)/core.a -lm -o $@
98         @echo ""
99         @echo 'done making elf'
100
101 $(BIN_DIR)/$(PROG).hex: $(BIN_DIR)/$(PROG).elf
102         $(OBJCopy) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $(BIN_DIR)/$(PROG).eep
103         $(OBJCopy) -O ihex -R .eeprom $< $@
104         @echo ""
105         @echo 'done making hex'
106
107 install: all
108         #$(ARDUINO_DIR)/hardware/tools/avrdude -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/ttyACM0 -b115200 -D -Uflash:w:$(BIN_DIR)/$(PROG).hex:i
109         avrdude -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/ttyACM0 -b115200 -D -Uflash:w:$(BIN_DIR)/$(PROG).hex:i
110
111 .PHONY: clean
112 clean :
113         rm -rf ./obj/debug/*
114         rm -rf ./obj/release/*
115         rm -rf ./lib/debug/*
116         rm -rf ./lib/release/*
117         rm -rf ./bin/debug/*
118         rm -rf ./bin/release/*
119         rm -rf ./test/tst_*.txt
120         rm -fr $(BIN_DIR)
121         rm -fr $(OBJ_DIR)
122
123
124 .PHONY: print_vars
125 print_vars:
126         @echo ""
127         @echo 'BUILD                = '$(value BUILD)
128         @echo 'C_SRC_DIR            = '$(value C_SRC_DIR)
129         @echo 'C_SRC_DIR_ARDUINO    = '$(value C_SRC_DIR_ARDUINO)
130         @echo 'CPP_SRC_DIR          = '$(CPP_SRC_DIR)
131         @echo 'CPP_SRC_DIR_ARDUINO  = '$(value CPP_SRC_DIR_ARDUINO)
132         @echo 'INC_DIR              = '$(INC_DIR)
133         @echo 'H_FILES              = '$(H_FILES)
134         @echo 'C_FILES              = '$(C_FILES)
135         @echo 'CPP_FILES            = '$(CPP_FILES)
136         @echo 'C_FILES_ARDUINO      = '$(C_FILES_ARDUINO)
137         @echo 'CPP_FILES_ARDUINO    = '$(CPP_FILES_ARDUINO)
138         @echo 'OBJ_FILES            = '$(OBJ_FILES)
139         @echo 'OBJ_FILES_ARDUINO    = '$(OBJ_FILES_ARDUINO)