1# NOTE: to compile with avr-gcc less than verson 4.2.3, you must
2# remove the atmega328p from the list of target devices below:
3devices := atmega48 atmega168 atmega328p atmega324p atmega644p atmega1284p atmega1284p_x2
4mcu_atmega48 := atmega48
5mcu_atmega168 := atmega168
6mcu_atmega328p := atmega328p
7mcu_atmega324p := atmega324p
8mcu_atmega644p := atmega644p
9mcu_atmega1284p := atmega1284p
10mcu_atmega1284p_x2 := atmega1284p
11
12LIBRARY_OBJECTS=\
13	OrangutanAnalog \
14	OrangutanBuzzer \
15	OrangutanDigital \
16	OrangutanLCD \
17	OrangutanLEDs \
18	OrangutanMotors \
19	OrangutanPulseIn \
20	OrangutanPushbuttons \
21	OrangutanResources \
22	OrangutanSerial \
23	OrangutanServos \
24	OrangutanSPIMaster \
25	OrangutanTime \
26	OrangutanSVP \
27	OrangutanX2 \
28	Pololu3pi \
29	PololuQTRSensors \
30	PololuWheelEncoders
31
32
33SHELL = sh
34
35# We need to do our recursive make with cd, since WinAVR does not support make -C.
36# See WinAVR bug 1932584, "recursive make call fails"
37.PHONY: library_files
38library_files:
39	@echo making library files
40	$(foreach device,$(devices),cd devices/$(device) && $(MAKE) && cd ../.. &&) echo -n
41
42# Change the path to allow make within sh to work: see WinAVR bug 1915456 "make ignores parameters when executed from sh"
43PATH := $(shell echo $$PATH | sed 's/\(WinAVR-[0-9]*\)\/bin/\\1\/utils\/bin/g'):$(PATH)
44
45LIBRARY_FILES := $(foreach device,$(devices),libpololu_$(device).a)
46
47.PHONY: clean
48clean:
49	$(foreach device,$(devices),cd devices/$(device) && $(MAKE) clean && cd ../.. &&) echo -n
50	rm -f $(LIBRARY_FILES)
51
52# "make install" basically just copies the .a and files to the lib directory,
53# and the header files to the include directory.  The tricky thing is
54# determining which directories those are in this makefile.
55#
56# By default, this makefile will install .a files in $(LIB)
57# and header files in $(LIB)/../include/pololu, where LIB is determined
58# by running `avr-gcc -print-search-dirs`, looking on the libraries
59# line, taking the last directory listed.
60#
61# This seems to be a good choice on most systems because it points to
62# a path that does not include the avr-gcc version number.
63#
64# You can check what directories this makefile will use by running
65#    make show_prefix
66#
67# You can override this behavior by inserting a line below that manually
68# sets INCLUDE_POLOLU and LIB to a directory of your choice.
69# For example, you could uncomment these lines:
70#   LIB := /usr/lib/avr/lib
71#   INCLUDE_POLOLU := /usr/lib/avr/include
72#
73# Note: Unless you specify LIB and INCLUDE_POLOLU as described above,
74# or you add the AVR Studio 5 toolchain to your path, running
75# 'make install' will NOT install the library into the AVR Studio 5
76# toolchain.  For Windows users, we recommend using the library's
77# executable installer.
78
79# Figure out what operating system we are running in.
80UNAME := $(shell uname)
81ifeq ($(findstring NT, $(UNAME)), NT)
82  WINDOWS=true
83endif
84ifeq ($(findstring MINGW, $(UNAME)), MINGW)
85  WINDOWS=true
86endif
87
88ifeq ($(origin LIB), undefined)
89  ifdef WINDOWS
90    # Directories are separated with ;
91    LIB := $(shell avr-gcc -print-search-dirs | grep -e "^libraries" | sed 's/.*;//')
92  else
93    # Directories are separated with :
94    LIB := $(shell avr-gcc -print-search-dirs | grep -e "^libraries" | sed 's/.*://')
95  endif
96endif
97
98INCLUDE_POLOLU ?= $(LIB)/../include/pololu
99
100# Normalize the directory names so they don't have ".." in them.
101# Doesn't work in Windows.
102ifndef WINDOWS
103  LIB := $(abspath $(LIB))
104  INCLUDE_POLOLU := $(abspath $(INCLUDE_POLOLU))
105endif
106
107INSTALL_FILES := install -m=r--
108
109.PHONY: show_prefix
110show_prefix:
111	@echo The Pololu AVR Library object files \(.a\) will be installed in $(LIB)
112	@echo The header files \(.h\) will be installed in $(INCLUDE_POLOLU)
113
114.PHONY: install
115install: $(LIBRARY_FILES)
116	install -d $(LIB)
117	install -d $(INCLUDE_POLOLU)
118	install $(foreach device,$(devices),libpololu_$(device).a) $(LIB)
119	$(INSTALL_FILES) pololu/*.h $(INCLUDE_POLOLU)
120	for OrangutanObject in $(LIBRARY_OBJECTS); do install -d $(INCLUDE_POLOLU)/$$OrangutanObject ; $(INSTALL_FILES) src/$$OrangutanObject/*.h $(INCLUDE_POLOLU)/$$OrangutanObject ; done
121	install -d $(INCLUDE_POLOLU)/OrangutanResources/include
122	$(INSTALL_FILES) src/OrangutanResources/include/*.h $(INCLUDE_POLOLU)/OrangutanResources/include
123	$(INSTALL_FILES) pololu/orangutan $(INCLUDE_POLOLU)
124	@echo "Installation is complete."
125
126# Include additional Makefile rules that are only available if you have
127# downloaded the actual source of the library (from github).
128# Silently fail otherwise.
129-include src.mk
130