blob: 5410a71b652aa6322e85960d49ee504d9608b5e2 [file] [log] [blame]
Ollie Lho184a4042005-11-26 21:55:36 +00001#
Uwe Hermannf78cff12009-06-12 14:05:25 +00002# This file is part of the flashrom project.
3#
4# Copyright (C) 2005 coresystems GmbH <stepan@coresystems.de>
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +00005# Copyright (C) 2009,2010,2012 Carl-Daniel Hailfinger
Uwe Hermannf78cff12009-06-12 14:05:25 +00006#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Ollie Lho184a4042005-11-26 21:55:36 +000019#
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000020
Ollie Lho184a4042005-11-26 21:55:36 +000021PROGRAM = flashrom
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000022
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000023###############################################################################
24# Defaults for the toolchain.
25
26# If you want to cross-compile, just run e.g.
27# make CC=i586-pc-msdosdjgpp-gcc
28# You may have to specify STRIP/AR/RANLIB as well.
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +000029#
30# Note for anyone editing this Makefile: gnumake will happily ignore any
31# changes in this Makefile to variables set on the command line.
Uwe Hermannc2a9c9c2009-05-14 14:51:14 +000032CC ?= gcc
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +000033STRIP ?= strip
Christian Ruppertdb9d9f42009-05-14 14:17:07 +000034INSTALL = install
Paul Fox05dfbe62009-06-16 21:08:06 +000035DIFF = diff
Christian Ruppertdb9d9f42009-05-14 14:17:07 +000036PREFIX ?= /usr/local
Uwe Hermann56b2cb02009-05-21 15:59:58 +000037MANDIR ?= $(PREFIX)/share/man
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +000038CFLAGS ?= -Os -Wall -Wshadow
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +000039EXPORTDIR ?= .
Patrick Georgi97bc95c2011-03-08 07:17:44 +000040AR ?= ar
41RANLIB ?= ranlib
Stefan Taunerfd0d4132012-09-25 21:24:55 +000042# The following parameter changes the default programmer that will be used if there is no -p/--programmer
43# argument given when running flashrom. The predefined setting does not enable any default so that every
44# user has to declare the programmer he wants to use on every run. The rationale for this to be not set
45# (to e.g. the internal programmer) is that forgetting to specify this when working with another programmer
46# easily puts the system attached to the default programmer at risk (e.g. you want to flash coreboot to another
47# system attached to an external programmer while the default programmer is set to the internal programmer, and
48# you forget to use the -p parameter. This would (try to) overwrite the existing firmware of the computer
49# running flashrom). Please do not enable this without thinking about the possible consequences. Possible
50# values are those specified in enum programmer in programmer.h (which depend on other CONFIG_* options
51# evaluated below, namely those that enable/disable the various programmers).
52# Compilation will fail for unspecified values.
53CONFIG_DEFAULT_PROGRAMMER ?= PROGRAMMER_INVALID
Christian Ruppertdb9d9f42009-05-14 14:17:07 +000054
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000055# If your compiler spits out excessive warnings, run make WARNERROR=no
56# You shouldn't have to change this flag.
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +000057WARNERROR ?= yes
58
59ifeq ($(WARNERROR), yes)
60CFLAGS += -Werror
61endif
62
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000063###############################################################################
Stefan Tauner037cd842013-08-25 00:10:56 +000064# General OS-specific settings.
65# 1. Prepare for later by gathering information about host and target OS
66# 2. Set compiler flags and parameters according to OSes
67# 3. Likewise verify user-supplied CONFIG_* variables.
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000068
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +000069# HOST_OS is only used to work around local toolchain issues.
Stefan Tauner037cd842013-08-25 00:10:56 +000070HOST_OS ?= $(shell uname)
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +000071ifeq ($(HOST_OS), MINGW32_NT-5.1)
72# Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found".
73CC = gcc
74endif
75ifneq ($(HOST_OS), SunOS)
Adam Kaufman064b1f22007-02-06 19:47:50 +000076STRIP_ARGS = -s
77endif
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +000078
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000079# Determine the destination OS.
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +000080# IMPORTANT: The following line must be placed before TARGET_OS is ever used
81# (of course), but should come after any lines setting CC because the line
82# below uses CC itself.
83override TARGET_OS := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E os.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
84
85ifeq ($(TARGET_OS), Darwin)
Stefan Reinauer2fea3f32010-01-21 20:26:30 +000086CPPFLAGS += -I/opt/local/include -I/usr/local/include
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000087LDFLAGS += -L/opt/local/lib -L/usr/local/lib
Stefan Reinauerf79edb92009-01-26 01:23:31 +000088endif
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000089
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +000090ifeq ($(TARGET_OS), FreeBSD)
Stefan Reinauer2fea3f32010-01-21 20:26:30 +000091CPPFLAGS += -I/usr/local/include
Andriy Gapon65c1b862008-05-22 13:22:45 +000092LDFLAGS += -L/usr/local/lib
93endif
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000094
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +000095ifeq ($(TARGET_OS), OpenBSD)
Carl-Daniel Hailfingerb63b0672010-07-02 17:12:50 +000096CPPFLAGS += -I/usr/local/include
97LDFLAGS += -L/usr/local/lib
98endif
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000099
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000100ifeq ($(TARGET_OS), DOS)
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000101EXEC_SUFFIX := .exe
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000102CPPFLAGS += -I../libgetopt
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000103# DJGPP has odd uint*_t definitions which cause lots of format string warnings.
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +0000104CFLAGS += -Wno-format
Carl-Daniel Hailfinger5bdf2982010-06-14 12:42:05 +0000105# FIXME Check if we can achieve the same effect with -L../libgetopt -lgetopt
106LIBS += ../libgetopt/libgetopt.a
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000107# Bus Pirate, Serprog and PonyProg are not supported under DOS (missing serial support).
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +0000108ifeq ($(CONFIG_BUSPIRATE_SPI), yes)
109UNSUPPORTED_FEATURES += CONFIG_BUSPIRATE_SPI=yes
110else
111override CONFIG_BUSPIRATE_SPI = no
112endif
113ifeq ($(CONFIG_SERPROG), yes)
114UNSUPPORTED_FEATURES += CONFIG_SERPROG=yes
115else
116override CONFIG_SERPROG = no
117endif
Stefan Taunerd94d25d2012-07-28 03:17:15 +0000118ifeq ($(CONFIG_PONY_SPI), yes)
119UNSUPPORTED_FEATURES += CONFIG_PONY_SPI=yes
120else
121override CONFIG_PONY_SPI = no
122endif
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +0000123# Dediprog and FT2232 are not supported under DOS (missing USB support).
124ifeq ($(CONFIG_DEDIPROG), yes)
125UNSUPPORTED_FEATURES += CONFIG_DEDIPROG=yes
126else
127override CONFIG_DEDIPROG = no
128endif
129ifeq ($(CONFIG_FT2232_SPI), yes)
130UNSUPPORTED_FEATURES += CONFIG_FT2232_SPI=yes
131else
132override CONFIG_FT2232_SPI = no
133endif
James Lairdc60de0e2013-03-27 13:00:23 +0000134ifeq ($(CONFIG_USBBLASTER_SPI), yes)
135UNSUPPORTED_FEATURES += CONFIG_USBBLASTER_SPI=yes
136else
137override CONFIG_USBBLASTER_SPI = no
138endif
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000139endif
Ollie Lho184a4042005-11-26 21:55:36 +0000140
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000141# FIXME: Should we check for Cygwin/MSVC as well?
142ifeq ($(TARGET_OS), MinGW)
143EXEC_SUFFIX := .exe
Uwe Hermannd5e85d62011-07-03 19:44:12 +0000144# MinGW doesn't have the ffs() function, but we can use gcc's __builtin_ffs().
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +0000145FLASHROM_CFLAGS += -Dffs=__builtin_ffs
Carl-Daniel Hailfinger11990da2013-07-13 23:21:05 +0000146# Some functions provided by Microsoft do not work as described in C99 specifications. This macro fixes that
147# for MinGW. See http://sourceforge.net/apps/trac/mingw-w64/wiki/printf%20and%20scanf%20family */
148FLASHROM_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
Uwe Hermannd5e85d62011-07-03 19:44:12 +0000149# libusb-win32/libftdi stuff is usually installed in /usr/local.
150CPPFLAGS += -I/usr/local/include
151LDFLAGS += -L/usr/local/lib
Uwe Hermannd5e85d62011-07-03 19:44:12 +0000152# For now we disable all PCI-based programmers on Windows/MinGW (no libpci).
153ifeq ($(CONFIG_INTERNAL), yes)
154UNSUPPORTED_FEATURES += CONFIG_INTERNAL=yes
155else
156override CONFIG_INTERNAL = no
157endif
158ifeq ($(CONFIG_RAYER_SPI), yes)
159UNSUPPORTED_FEATURES += CONFIG_RAYER_SPI=yes
160else
161override CONFIG_RAYER_SPI = no
162endif
163ifeq ($(CONFIG_NIC3COM), yes)
164UNSUPPORTED_FEATURES += CONFIG_NIC3COM=yes
165else
166override CONFIG_NIC3COM = no
167endif
168ifeq ($(CONFIG_GFXNVIDIA), yes)
169UNSUPPORTED_FEATURES += CONFIG_GFXNVIDIA=yes
170else
171override CONFIG_GFXNVIDIA = no
172endif
173ifeq ($(CONFIG_SATASII), yes)
174UNSUPPORTED_FEATURES += CONFIG_SATASII=yes
175else
176override CONFIG_SATASII = no
177endif
178ifeq ($(CONFIG_ATAHPT), yes)
179UNSUPPORTED_FEATURES += CONFIG_ATAHPT=yes
180else
181override CONFIG_ATAHPT = no
182endif
183ifeq ($(CONFIG_DRKAISER), yes)
184UNSUPPORTED_FEATURES += CONFIG_DRKAISER=yes
185else
186override CONFIG_DRKAISER = no
187endif
188ifeq ($(CONFIG_NICREALTEK), yes)
189UNSUPPORTED_FEATURES += CONFIG_NICREALTEK=yes
190else
191override CONFIG_NICREALTEK = no
192endif
193ifeq ($(CONFIG_NICNATSEMI), yes)
194UNSUPPORTED_FEATURES += CONFIG_NICNATSEMI=yes
195else
196override CONFIG_NICNATSEMI = no
197endif
198ifeq ($(CONFIG_NICINTEL), yes)
199UNSUPPORTED_FEATURES += CONFIG_NICINTEL=yes
200else
201override CONFIG_NICINTEL = no
202endif
203ifeq ($(CONFIG_NICINTEL_SPI), yes)
204UNSUPPORTED_FEATURES += CONFIG_NICINTEL_SPI=yes
205else
206override CONFIG_NICINTEL_SPI = no
207endif
208ifeq ($(CONFIG_OGP_SPI), yes)
209UNSUPPORTED_FEATURES += CONFIG_OGP_SPI=yes
210else
211override CONFIG_OGP_SPI = no
212endif
213ifeq ($(CONFIG_SATAMV), yes)
214UNSUPPORTED_FEATURES += CONFIG_SATAMV=yes
215else
216override CONFIG_SATAMV = no
217endif
218endif
219
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000220ifeq ($(TARGET_OS), libpayload)
Stefan Tauner8e19b042013-08-28 09:55:04 +0000221ifeq ($(MAKECMDGOALS),)
222.DEFAULT_GOAL := libflashrom.a
223$(info Setting default goal to libflashrom.a)
224endif
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +0000225FLASHROM_CFLAGS += -DSTANDALONE
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000226ifeq ($(CONFIG_DUMMY), yes)
227UNSUPPORTED_FEATURES += CONFIG_DUMMY=yes
228else
229override CONFIG_DUMMY = no
230endif
Carl-Daniel Hailfinger11990da2013-07-13 23:21:05 +0000231# Bus Pirate, Serprog and PonyProg are not supported with libpayload (missing serial support).
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000232ifeq ($(CONFIG_BUSPIRATE_SPI), yes)
233UNSUPPORTED_FEATURES += CONFIG_BUSPIRATE_SPI=yes
234else
235override CONFIG_BUSPIRATE_SPI = no
236endif
237ifeq ($(CONFIG_SERPROG), yes)
238UNSUPPORTED_FEATURES += CONFIG_SERPROG=yes
239else
240override CONFIG_SERPROG = no
241endif
Carl-Daniel Hailfinger11990da2013-07-13 23:21:05 +0000242ifeq ($(CONFIG_PONY_SPI), yes)
243UNSUPPORTED_FEATURES += CONFIG_PONY_SPI=yes
244else
245override CONFIG_PONY_SPI = no
246endif
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000247# Dediprog and FT2232 are not supported with libpayload (missing libusb support)
248ifeq ($(CONFIG_DEDIPROG), yes)
249UNSUPPORTED_FEATURES += CONFIG_DEDIPROG=yes
250else
251override CONFIG_DEDIPROG = no
252endif
253ifeq ($(CONFIG_FT2232_SPI), yes)
254UNSUPPORTED_FEATURES += CONFIG_FT2232_SPI=yes
255else
256override CONFIG_FT2232_SPI = no
257endif
James Lairdc60de0e2013-03-27 13:00:23 +0000258ifeq ($(CONFIG_USBBLASTER_SPI), yes)
259UNSUPPORTED_FEATURES += CONFIG_USBBLASTER_SPI=yes
260else
261override CONFIG_USBBLASTER_SPI = no
262endif
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000263endif
264
Carl-Daniel Hailfinger8541d232012-02-16 21:00:27 +0000265ifneq ($(TARGET_OS), Linux)
266ifeq ($(CONFIG_LINUX_SPI), yes)
267UNSUPPORTED_FEATURES += CONFIG_LINUX_SPI=yes
268else
269override CONFIG_LINUX_SPI = no
270endif
271endif
272
Stefan Tauner037cd842013-08-25 00:10:56 +0000273###############################################################################
274# General architecture-specific settings.
275# Like above for the OS, below we verify user-supplied options depending on the target architecture.
276
Uwe Hermann44ffd582011-08-20 14:16:00 +0000277# Determine the destination processor architecture.
278# IMPORTANT: The following line must be placed before ARCH is ever used
279# (of course), but should come after any lines setting CC because the line
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000280# below uses CC itself.
281override ARCH := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E arch.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
Uwe Hermann44ffd582011-08-20 14:16:00 +0000282
David Hendricksb286da72012-02-13 00:35:35 +0000283# PCI port I/O support is unimplemented on PPC/MIPS and unavailable on ARM.
284# Right now this means the drivers below only work on x86.
285ifneq ($(ARCH), x86)
Uwe Hermann21b10c62011-07-29 12:13:01 +0000286ifeq ($(CONFIG_NIC3COM), yes)
287UNSUPPORTED_FEATURES += CONFIG_NIC3COM=yes
288else
289override CONFIG_NIC3COM = no
290endif
291ifeq ($(CONFIG_NICREALTEK), yes)
292UNSUPPORTED_FEATURES += CONFIG_NICREALTEK=yes
293else
294override CONFIG_NICREALTEK = no
295endif
296ifeq ($(CONFIG_NICNATSEMI), yes)
297UNSUPPORTED_FEATURES += CONFIG_NICNATSEMI=yes
298else
299override CONFIG_NICNATSEMI = no
300endif
301ifeq ($(CONFIG_RAYER_SPI), yes)
302UNSUPPORTED_FEATURES += CONFIG_RAYER_SPI=yes
303else
304override CONFIG_RAYER_SPI = no
305endif
306ifeq ($(CONFIG_ATAHPT), yes)
307UNSUPPORTED_FEATURES += CONFIG_ATAHPT=yes
308else
309override CONFIG_ATAHPT = no
310endif
311ifeq ($(CONFIG_SATAMV), yes)
312UNSUPPORTED_FEATURES += CONFIG_SATAMV=yes
313else
314override CONFIG_SATAMV = no
315endif
316endif
317
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000318###############################################################################
319# Flash chip drivers and bus support infrastructure.
320
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000321CHIP_OBJS = jedec.o stm50flw0x0x.o w39.o w29ee011.o \
Sean Nelson35727f72010-01-28 23:55:12 +0000322 sst28sf040.o m29f400bt.o 82802ab.o pm49fl00x.o \
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000323 sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o spi25_statusreg.o \
Aidan Thorntondb4e87d2013-08-27 18:01:53 +0000324 opaque.o sfdp.o en29lv640b.o at45db.o
Sean Nelson5d134642009-12-24 16:54:21 +0000325
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000326###############################################################################
327# Library code.
Sean Nelson5d134642009-12-24 16:54:21 +0000328
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000329LIB_OBJS = layout.o flashrom.o udelay.o programmer.o
Sean Nelson5d134642009-12-24 16:54:21 +0000330
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000331###############################################################################
332# Frontend related stuff.
Ollie Lho184a4042005-11-26 21:55:36 +0000333
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000334CLI_OBJS = cli_classic.o cli_output.o print.o
Ollie Lho184a4042005-11-26 21:55:36 +0000335
Carl-Daniel Hailfinger9e675852009-05-04 12:29:59 +0000336# Set the flashrom version string from the highest revision number
337# of the checked out flashrom files.
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +0000338# Note to packagers: Any tree exported with "make export" or "make tarball"
339# will not require subversion. The downloadable snapshots are already exported.
David Hendricks36e9f4b2013-08-14 14:47:26 +0000340SVNVERSION := $(shell ./util/getrevision.sh -u)
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +0000341
Stefan Tauner241e9d52013-08-13 22:13:01 +0000342RELEASE := 0.9.7
Carl-Daniel Hailfinger48e5e092009-08-31 16:25:08 +0000343VERSION := $(RELEASE)-r$(SVNVERSION)
344RELEASENAME ?= $(VERSION)
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +0000345
346SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"'
Bernhard Walle201bde32008-01-21 15:24:22 +0000347
Stefan Tauner037cd842013-08-25 00:10:56 +0000348###############################################################################
349# Default settings of CONFIG_* variables.
350
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000351# Always enable internal/onboard support for now.
352CONFIG_INTERNAL ?= yes
353
Stefan Tauner52b6e9d2013-04-01 00:46:05 +0000354# Always enable serprog for now.
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000355CONFIG_SERPROG ?= yes
356
Carl-Daniel Hailfingere7fdd6e2010-07-21 10:26:01 +0000357# RayeR SPIPGM hardware support
358CONFIG_RAYER_SPI ?= yes
359
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000360# PonyProg2000 SPI hardware support
361CONFIG_PONY_SPI ?= yes
362
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000363# Always enable 3Com NICs for now.
364CONFIG_NIC3COM ?= yes
365
Carl-Daniel Hailfingerbf3af292010-07-29 14:41:46 +0000366# Enable NVIDIA graphics cards. Note: write and erase do not work properly.
367CONFIG_GFXNVIDIA ?= yes
Uwe Hermann2bc98f62009-09-30 18:29:55 +0000368
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000369# Always enable SiI SATA controllers for now.
370CONFIG_SATASII ?= yes
371
Uwe Hermannddd5c9e2010-02-21 21:17:00 +0000372# Highpoint (HPT) ATA/RAID controller support.
373# IMPORTANT: This code is not yet working!
374CONFIG_ATAHPT ?= no
375
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000376# Always enable FT2232 SPI dongles for now.
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000377CONFIG_FT2232_SPI ?= yes
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000378
James Lairdc60de0e2013-03-27 13:00:23 +0000379# Always enable Altera USB-Blaster dongles for now.
380CONFIG_USBBLASTER_SPI ?= yes
381
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000382# Always enable dummy tracing for now.
383CONFIG_DUMMY ?= yes
384
385# Always enable Dr. Kaiser for now.
386CONFIG_DRKAISER ?= yes
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000387
Joerg Fischer5665ef32010-05-21 21:54:07 +0000388# Always enable Realtek NICs for now.
389CONFIG_NICREALTEK ?= yes
390
Andrew Morganc29c2e72010-06-07 22:37:54 +0000391# Disable National Semiconductor NICs until support is complete and tested.
392CONFIG_NICNATSEMI ?= no
393
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000394# Always enable Intel NICs for now.
395CONFIG_NICINTEL ?= yes
396
Idwer Vollering004f4b72010-09-03 18:21:21 +0000397# Always enable SPI on Intel NICs for now.
398CONFIG_NICINTEL_SPI ?= yes
399
Mark Marshall90021f22010-12-03 14:48:11 +0000400# Always enable SPI on OGP cards for now.
401CONFIG_OGP_SPI ?= yes
402
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000403# Always enable Bus Pirate SPI for now.
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000404CONFIG_BUSPIRATE_SPI ?= yes
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000405
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +0000406# Disable Dediprog SF100 until support is complete and tested.
407CONFIG_DEDIPROG ?= no
408
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000409# Always enable Marvell SATA controllers for now.
410CONFIG_SATAMV ?= yes
411
Carl-Daniel Hailfinger8541d232012-02-16 21:00:27 +0000412# Enable Linux spidev interface by default. We disable it on non-Linux targets.
413CONFIG_LINUX_SPI ?= yes
414
Carl-Daniel Hailfinger6161ff12009-11-16 21:22:24 +0000415# Disable wiki printing by default. It is only useful if you have wiki access.
Uwe Hermann2db77a02010-06-04 17:07:39 +0000416CONFIG_PRINT_WIKI ?= no
Carl-Daniel Hailfinger9c8476b2009-09-16 12:19:03 +0000417
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +0000418# Bitbanging SPI infrastructure, default off unless needed.
419ifeq ($(CONFIG_RAYER_SPI), yes)
420override CONFIG_BITBANG_SPI = yes
421else
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000422ifeq ($(CONFIG_PONY_SPI), yes)
423override CONFIG_BITBANG_SPI = yes
424else
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +0000425ifeq ($(CONFIG_INTERNAL), yes)
426override CONFIG_BITBANG_SPI = yes
427else
428ifeq ($(CONFIG_NICINTEL_SPI), yes)
429override CONFIG_BITBANG_SPI = yes
430else
Mark Marshall90021f22010-12-03 14:48:11 +0000431ifeq ($(CONFIG_OGP_SPI), yes)
432override CONFIG_BITBANG_SPI = yes
433else
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +0000434CONFIG_BITBANG_SPI ?= no
435endif
436endif
437endif
Mark Marshall90021f22010-12-03 14:48:11 +0000438endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000439endif
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +0000440
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000441###############################################################################
442# Programmer drivers and programmer support infrastructure.
Stefan Tauner037cd842013-08-25 00:10:56 +0000443# Depending on the CONFIG_* variables set and verified above we set compiler flags and parameters below.
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000444
Stefan Taunerfd0d4132012-09-25 21:24:55 +0000445FEATURE_CFLAGS += -D'CONFIG_DEFAULT_PROGRAMMER=$(CONFIG_DEFAULT_PROGRAMMER)'
446
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000447ifeq ($(CONFIG_INTERNAL), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000448FEATURE_CFLAGS += -D'CONFIG_INTERNAL=1'
Carl-Daniel Hailfingerb5b161b2010-06-04 19:05:39 +0000449PROGRAMMER_OBJS += processor_enable.o chipset_enable.o board_enable.o cbtable.o dmi.o internal.o
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000450ifeq ($(ARCH), x86)
Rudolf Marek70e14592013-07-25 22:58:56 +0000451PROGRAMMER_OBJS += it87spi.o it85spi.o sb600spi.o amd_imc.o wbsio_spi.o mcp6x_spi.o
Stefan Tauner1e146392011-09-15 23:52:55 +0000452PROGRAMMER_OBJS += ichspi.o ich_descriptors.o
Carl-Daniel Hailfinger91199a12011-07-07 06:59:18 +0000453else
454endif
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000455NEED_PCI := yes
456endif
457
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000458ifeq ($(CONFIG_SERPROG), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000459FEATURE_CFLAGS += -D'CONFIG_SERPROG=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000460PROGRAMMER_OBJS += serprog.o
Carl-Daniel Hailfinger5bdf2982010-06-14 12:42:05 +0000461NEED_SERIAL := yes
462NEED_NET := yes
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000463endif
464
Carl-Daniel Hailfingere7fdd6e2010-07-21 10:26:01 +0000465ifeq ($(CONFIG_RAYER_SPI), yes)
466FEATURE_CFLAGS += -D'CONFIG_RAYER_SPI=1'
467PROGRAMMER_OBJS += rayer_spi.o
468# Actually, NEED_PCI is wrong. NEED_IOPORT_ACCESS would be more correct.
469NEED_PCI := yes
470endif
471
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000472ifeq ($(CONFIG_PONY_SPI), yes)
473FEATURE_CFLAGS += -D'CONFIG_PONY_SPI=1'
474PROGRAMMER_OBJS += pony_spi.o
475NEED_SERIAL := yes
476endif
477
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000478ifeq ($(CONFIG_BITBANG_SPI), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000479FEATURE_CFLAGS += -D'CONFIG_BITBANG_SPI=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000480PROGRAMMER_OBJS += bitbang_spi.o
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000481endif
482
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000483ifeq ($(CONFIG_NIC3COM), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000484FEATURE_CFLAGS += -D'CONFIG_NIC3COM=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000485PROGRAMMER_OBJS += nic3com.o
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000486NEED_PCI := yes
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000487endif
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000488
Uwe Hermann2bc98f62009-09-30 18:29:55 +0000489ifeq ($(CONFIG_GFXNVIDIA), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000490FEATURE_CFLAGS += -D'CONFIG_GFXNVIDIA=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000491PROGRAMMER_OBJS += gfxnvidia.o
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000492NEED_PCI := yes
Uwe Hermann2bc98f62009-09-30 18:29:55 +0000493endif
494
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000495ifeq ($(CONFIG_SATASII), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000496FEATURE_CFLAGS += -D'CONFIG_SATASII=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000497PROGRAMMER_OBJS += satasii.o
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000498NEED_PCI := yes
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000499endif
500
Uwe Hermannddd5c9e2010-02-21 21:17:00 +0000501ifeq ($(CONFIG_ATAHPT), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000502FEATURE_CFLAGS += -D'CONFIG_ATAHPT=1'
Uwe Hermannddd5c9e2010-02-21 21:17:00 +0000503PROGRAMMER_OBJS += atahpt.o
504NEED_PCI := yes
505endif
506
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000507ifeq ($(CONFIG_FT2232_SPI), yes)
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000508# This is a totally ugly hack.
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000509FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "FTDISUPPORT := yes" .features && printf "%s" "-D'CONFIG_FT2232_SPI=1'")
James Lairdc60de0e2013-03-27 13:00:23 +0000510NEED_FTDI := yes
511PROGRAMMER_OBJS += ft2232_spi.o
512endif
513
514ifeq ($(CONFIG_USBBLASTER_SPI), yes)
515# This is a totally ugly hack.
516FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "FTDISUPPORT := yes" .features && printf "%s" "-D'CONFIG_USBBLASTER_SPI=1'")
517NEED_FTDI := yes
518PROGRAMMER_OBJS += usbblaster_spi.o
519endif
520
521ifeq ($(NEED_FTDI), yes)
522FTDILIBS := $(shell pkg-config --libs libftdi 2>/dev/null || printf "%s" "-lftdi -lusb")
Ilya A. Volynets-Evenbakh2c714ab2012-09-26 00:47:09 +0000523FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "FT232H := yes" .features && printf "%s" "-D'HAVE_FT232H=1'")
Jörg Mayer8776db22009-11-16 14:05:13 +0000524FEATURE_LIBS += $(shell LC_ALL=C grep -q "FTDISUPPORT := yes" .features && printf "%s" "$(FTDILIBS)")
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000525# We can't set NEED_USB here because that would transform libftdi auto-enabling
526# into a hard requirement for libusb, defeating the purpose of auto-enabling.
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000527endif
528
529ifeq ($(CONFIG_DUMMY), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000530FEATURE_CFLAGS += -D'CONFIG_DUMMY=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000531PROGRAMMER_OBJS += dummyflasher.o
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000532endif
533
534ifeq ($(CONFIG_DRKAISER), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000535FEATURE_CFLAGS += -D'CONFIG_DRKAISER=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000536PROGRAMMER_OBJS += drkaiser.o
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000537NEED_PCI := yes
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000538endif
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000539
Joerg Fischer5665ef32010-05-21 21:54:07 +0000540ifeq ($(CONFIG_NICREALTEK), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000541FEATURE_CFLAGS += -D'CONFIG_NICREALTEK=1'
Joerg Fischer5665ef32010-05-21 21:54:07 +0000542PROGRAMMER_OBJS += nicrealtek.o
543NEED_PCI := yes
544endif
545
Andrew Morganc29c2e72010-06-07 22:37:54 +0000546ifeq ($(CONFIG_NICNATSEMI), yes)
547FEATURE_CFLAGS += -D'CONFIG_NICNATSEMI=1'
548PROGRAMMER_OBJS += nicnatsemi.o
549NEED_PCI := yes
550endif
551
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000552ifeq ($(CONFIG_NICINTEL), yes)
553FEATURE_CFLAGS += -D'CONFIG_NICINTEL=1'
554PROGRAMMER_OBJS += nicintel.o
555NEED_PCI := yes
556endif
557
Idwer Vollering004f4b72010-09-03 18:21:21 +0000558ifeq ($(CONFIG_NICINTEL_SPI), yes)
559FEATURE_CFLAGS += -D'CONFIG_NICINTEL_SPI=1'
560PROGRAMMER_OBJS += nicintel_spi.o
561NEED_PCI := yes
562endif
563
Mark Marshall90021f22010-12-03 14:48:11 +0000564ifeq ($(CONFIG_OGP_SPI), yes)
565FEATURE_CFLAGS += -D'CONFIG_OGP_SPI=1'
566PROGRAMMER_OBJS += ogp_spi.o
567NEED_PCI := yes
568endif
569
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000570ifeq ($(CONFIG_BUSPIRATE_SPI), yes)
571FEATURE_CFLAGS += -D'CONFIG_BUSPIRATE_SPI=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000572PROGRAMMER_OBJS += buspirate_spi.o
Carl-Daniel Hailfinger5bdf2982010-06-14 12:42:05 +0000573NEED_SERIAL := yes
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000574endif
575
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +0000576ifeq ($(CONFIG_DEDIPROG), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000577FEATURE_CFLAGS += -D'CONFIG_DEDIPROG=1'
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +0000578PROGRAMMER_OBJS += dediprog.o
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000579NEED_USB := yes
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +0000580endif
581
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000582ifeq ($(CONFIG_SATAMV), yes)
583FEATURE_CFLAGS += -D'CONFIG_SATAMV=1'
584PROGRAMMER_OBJS += satamv.o
585NEED_PCI := yes
586endif
587
Carl-Daniel Hailfinger8541d232012-02-16 21:00:27 +0000588ifeq ($(CONFIG_LINUX_SPI), yes)
Stefan Tauner8868db32012-03-13 00:18:19 +0000589# This is a totally ugly hack.
590FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "LINUX_SPI_SUPPORT := yes" .features && printf "%s" "-D'CONFIG_LINUX_SPI=1'")
Carl-Daniel Hailfinger8541d232012-02-16 21:00:27 +0000591PROGRAMMER_OBJS += linux_spi.o
592endif
593
Carl-Daniel Hailfinger5bdf2982010-06-14 12:42:05 +0000594ifeq ($(NEED_SERIAL), yes)
Sean Nelson5d134642009-12-24 16:54:21 +0000595LIB_OBJS += serial.o
Carl-Daniel Hailfinger5bdf2982010-06-14 12:42:05 +0000596endif
597
598ifeq ($(NEED_NET), yes)
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000599ifeq ($(TARGET_OS), SunOS)
Carl-Daniel Hailfinger5bdf2982010-06-14 12:42:05 +0000600LIBS += -lsocket
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000601endif
Carl-Daniel Hailfingere51ea102009-11-23 19:20:11 +0000602endif
603
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000604ifeq ($(NEED_PCI), yes)
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000605CHECK_LIBPCI = yes
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000606FEATURE_CFLAGS += -D'NEED_PCI=1'
Carl-Daniel Hailfingerfb0828f2010-02-12 19:35:25 +0000607PROGRAMMER_OBJS += pcidev.o physmap.o hwaccess.o
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000608ifeq ($(TARGET_OS), NetBSD)
Carl-Daniel Hailfinger460b2822010-06-04 23:24:57 +0000609# The libpci we want is called libpciutils on NetBSD and needs NetBSD libpci.
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000610PCILIBS += -lpciutils -lpci
Carl-Daniel Hailfinger460b2822010-06-04 23:24:57 +0000611# For (i386|x86_64)_iopl(2).
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000612PCILIBS += -l$(shell uname -p)
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000613else
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000614ifeq ($(TARGET_OS), DOS)
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000615# FIXME There needs to be a better way to do this
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000616CPPFLAGS += -I../libpci/include
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000617PCILIBS += ../libpci/lib/libpci.a
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000618else
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000619PCILIBS += -lpci
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000620ifeq ($(TARGET_OS), OpenBSD)
Carl-Daniel Hailfingerb63b0672010-07-02 17:12:50 +0000621# For (i386|amd64)_iopl(2).
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000622PCILIBS += -l$(shell uname -m)
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000623else
624ifeq ($(TARGET_OS), Darwin)
625# DirectHW framework can be found in the DirectHW library.
Stefan Taunere34e3e82013-01-01 00:06:51 +0000626PCILIBS += -framework IOKit -framework DirectHW
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000627else
628endif
Carl-Daniel Hailfingerb63b0672010-07-02 17:12:50 +0000629endif
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000630endif
Jonathan A. Kollasch3646c8f2010-01-08 21:18:08 +0000631endif
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000632endif
633
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000634ifeq ($(NEED_USB), yes)
635CHECK_LIBUSB0 = yes
636FEATURE_CFLAGS += -D'NEED_USB=1'
637USBLIBS := $(shell pkg-config --libs libusb 2>/dev/null || printf "%s" "-lusb")
638endif
639
Carl-Daniel Hailfinger9c8476b2009-09-16 12:19:03 +0000640ifeq ($(CONFIG_PRINT_WIKI), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000641FEATURE_CFLAGS += -D'CONFIG_PRINT_WIKI=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000642CLI_OBJS += print_wiki.o
Carl-Daniel Hailfinger9c8476b2009-09-16 12:19:03 +0000643endif
644
Carl-Daniel Hailfinger132e2ec2010-03-27 16:36:40 +0000645FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "UTSNAME := yes" .features && printf "%s" "-D'HAVE_UTSNAME=1'")
646
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000647# We could use PULLED_IN_LIBS, but that would be ugly.
648FEATURE_LIBS += $(shell LC_ALL=C grep -q "NEEDLIBZ := yes" .libdeps && printf "%s" "-lz")
649
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000650LIBFLASHROM_OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS)
Stefan Taunerd94d25d2012-07-28 03:17:15 +0000651OBJS = $(CLI_OBJS) $(LIBFLASHROM_OBJS)
Sean Nelson5d134642009-12-24 16:54:21 +0000652
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000653all: hwlibs features $(PROGRAM)$(EXEC_SUFFIX)
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000654ifeq ($(ARCH), x86)
655 @+$(MAKE) -C util/ich_descriptors_tool/ TARGET_OS=$(TARGET_OS) EXEC_SUFFIX=$(EXEC_SUFFIX)
656endif
657
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000658$(PROGRAM)$(EXEC_SUFFIX): $(OBJS)
Carl-Daniel Hailfinger11990da2013-07-13 23:21:05 +0000659 $(CC) $(LDFLAGS) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJS) $(LIBS) $(PCILIBS) $(FEATURE_LIBS) $(USBLIBS)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000660
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000661libflashrom.a: $(LIBFLASHROM_OBJS)
662 $(AR) rcs $@ $^
663 $(RANLIB) $@
664
Carl-Daniel Hailfinger8ef7dce2009-07-10 20:19:48 +0000665# TAROPTIONS reduces information leakage from the packager's system.
666# If other tar programs support command line arguments for setting uid/gid of
667# stored files, they can be handled here as well.
668TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
Carl-Daniel Hailfingerb18ecbc2009-06-19 14:20:34 +0000669
Paul Fox05dfbe62009-06-16 21:08:06 +0000670%.o: %.c .features
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +0000671 $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) $(FEATURE_CFLAGS) $(SVNDEF) -o $@ -c $<
Clark Rawlins02016f72008-02-14 23:22:20 +0000672
Carl-Daniel Hailfingera0020df2010-05-30 22:35:14 +0000673# Make sure to add all names of generated binaries here.
674# This includes all frontends and libflashrom.
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000675# We don't use EXEC_SUFFIX here because we want to clean everything.
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000676clean:
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000677 rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a *.o *.d
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000678 @+$(MAKE) -C util/ich_descriptors_tool/ clean
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000679
Ollie Lho184a4042005-11-26 21:55:36 +0000680distclean: clean
Stefan Reinauere2f01582010-06-07 11:08:07 +0000681 rm -f .features .libdeps
Christian Ruppertdb9d9f42009-05-14 14:17:07 +0000682
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000683strip: $(PROGRAM)$(EXEC_SUFFIX)
684 $(STRIP) $(STRIP_ARGS) $(PROGRAM)$(EXEC_SUFFIX)
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000685
Stefan Tauner56787082011-08-18 02:27:19 +0000686# to define test programs we use verbatim variables, which get exported
687# to environment variables and are referenced with $$<varname> later
688
689define COMPILER_TEST
690int main(int argc, char **argv)
691{
692 (void) argc;
693 (void) argv;
694 return 0;
695}
696endef
697export COMPILER_TEST
698
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +0000699compiler: featuresavailable
Paul Fox05dfbe62009-06-16 21:08:06 +0000700 @printf "Checking for a C compiler... "
Stefan Tauner56787082011-08-18 02:27:19 +0000701 @echo "$$COMPILER_TEST" > .test.c
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000702 @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .test.c -o .test$(EXEC_SUFFIX) >/dev/null && \
Carl-Daniel Hailfinger4cb7a962009-06-16 09:31:51 +0000703 echo "found." || ( echo "not found."; \
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000704 rm -f .test.c .test$(EXEC_SUFFIX); exit 1)
705 @rm -f .test.c .test$(EXEC_SUFFIX)
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000706 @printf "Target arch is "
Carl-Daniel Hailfinger91199a12011-07-07 06:59:18 +0000707 @# FreeBSD wc will output extraneous whitespace.
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000708 @echo $(ARCH)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \
Carl-Daniel Hailfinger91199a12011-07-07 06:59:18 +0000709 ( echo "unknown. Aborting."; exit 1)
710 @printf "%s\n" '$(ARCH)'
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000711 @printf "Target OS is "
712 @# FreeBSD wc will output extraneous whitespace.
713 @echo $(TARGET_OS)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \
714 ( echo "unknown. Aborting."; exit 1)
715 @printf "%s\n" '$(TARGET_OS)'
Carl-Daniel Hailfinger4cb7a962009-06-16 09:31:51 +0000716
Stefan Tauner56787082011-08-18 02:27:19 +0000717define LIBPCI_TEST
718/* Avoid a failing test due to libpci header symbol shadowing breakage */
719#define index shadow_workaround_index
720#include <pci/pci.h>
721struct pci_access *pacc;
722int main(int argc, char **argv)
723{
724 (void) argc;
725 (void) argv;
726 pacc = pci_alloc();
727 return 0;
728}
729endef
730export LIBPCI_TEST
731
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000732define LIBUSB0_TEST
733#include <usb.h>
734int main(int argc, char **argv)
735{
736 (void) argc;
737 (void) argv;
738 usb_init();
739 return 0;
740}
741endef
742export LIBUSB0_TEST
743
744hwlibs: compiler
745 @printf "" > .libdeps
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000746ifeq ($(CHECK_LIBPCI), yes)
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000747 @printf "Checking for libpci headers... "
Stefan Tauner56787082011-08-18 02:27:19 +0000748 @echo "$$LIBPCI_TEST" > .test.c
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000749 @$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >/dev/null && \
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000750 echo "found." || ( echo "not found."; echo; \
751 echo "Please install libpci headers (package pciutils-devel)."; \
752 echo "See README for more information."; echo; \
753 rm -f .test.c .test.o; exit 1)
Carl-Daniel Hailfinger9979eac2010-03-22 12:29:45 +0000754 @printf "Checking if libpci is present and sufficient... "
Carl-Daniel Hailfinger26148ae2012-11-29 22:22:04 +0000755 @$(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS) >/dev/null && \
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000756 echo "yes." || ( echo "no."; \
Carl-Daniel Hailfinger9979eac2010-03-22 12:29:45 +0000757 printf "Checking if libz+libpci are present and sufficient..."; \
Carl-Daniel Hailfinger26148ae2012-11-29 22:22:04 +0000758 $(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS) -lz >/dev/null && \
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000759 ( echo "yes."; echo "NEEDLIBZ := yes" > .libdeps ) || ( echo "no."; echo; \
Carl-Daniel Hailfinger9979eac2010-03-22 12:29:45 +0000760 echo "Please install libpci (package pciutils) and/or libz."; \
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000761 echo "See README for more information."; echo; \
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000762 rm -f .test.c .test.o .test$(EXEC_SUFFIX); exit 1) )
763 @rm -f .test.c .test.o .test$(EXEC_SUFFIX)
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000764endif
765ifeq ($(CHECK_LIBUSB0), yes)
766 @printf "Checking for libusb-0.1/libusb-compat headers... "
767 @echo "$$LIBUSB0_TEST" > .test.c
768 @$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >/dev/null && \
769 echo "found." || ( echo "not found."; echo; \
770 echo "Please install libusb-0.1 headers or libusb-compat headers."; \
771 echo "See README for more information."; echo; \
772 rm -f .test.c .test.o; exit 1)
773 @printf "Checking if libusb-0.1 is usable... "
Carl-Daniel Hailfinger26148ae2012-11-29 22:22:04 +0000774 @$(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(USBLIBS) >/dev/null && \
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000775 echo "yes." || ( echo "no."; \
776 echo "Please install libusb-0.1 or libusb-compat."; \
777 echo "See README for more information."; echo; \
778 rm -f .test.c .test.o .test$(EXEC_SUFFIX); exit 1)
779 @rm -f .test.c .test.o .test$(EXEC_SUFFIX)
Carl-Daniel Hailfinger8a59ff02009-12-24 03:33:11 +0000780endif
Stefan Reinauer53e96252005-12-01 16:19:24 +0000781
Carl-Daniel Hailfingerb18ecbc2009-06-19 14:20:34 +0000782.features: features
783
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +0000784# If a user does not explicitly request a non-working feature, we should
785# silently disable it. However, if a non-working (does not compile) feature
786# is explicitly requested, we should bail out with a descriptive error message.
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000787# We also have to check that at least one programmer driver is enabled.
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +0000788featuresavailable:
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000789ifeq ($(PROGRAMMER_OBJS),)
790 @echo "You have to enable at least one programmer driver!"
791 @false
792endif
793ifneq ($(UNSUPPORTED_FEATURES), )
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +0000794 @echo "The following features are unavailable on your machine: $(UNSUPPORTED_FEATURES)"
795 @false
796endif
797
Stefan Tauner56787082011-08-18 02:27:19 +0000798define FTDI_TEST
799#include <ftdi.h>
800struct ftdi_context *ftdic = NULL;
801int main(int argc, char **argv)
802{
803 (void) argc;
804 (void) argv;
805 return ftdi_init(ftdic);
806}
807endef
808export FTDI_TEST
809
Ilya A. Volynets-Evenbakh2c714ab2012-09-26 00:47:09 +0000810define FTDI_232H_TEST
811#include <ftdi.h>
812enum ftdi_chip_type type = TYPE_232H;
813endef
814export FTDI_232H_TEST
815
Stefan Tauner56787082011-08-18 02:27:19 +0000816define UTSNAME_TEST
817#include <sys/utsname.h>
818struct utsname osinfo;
819int main(int argc, char **argv)
820{
821 (void) argc;
822 (void) argv;
823 uname (&osinfo);
824 return 0;
825}
826endef
827export UTSNAME_TEST
828
Stefan Tauner8868db32012-03-13 00:18:19 +0000829define LINUX_SPI_TEST
830#include <linux/types.h>
831#include <linux/spi/spidev.h>
832
833int main(int argc, char **argv)
834{
835 (void) argc;
836 (void) argv;
837 return 0;
838}
839endef
840export LINUX_SPI_TEST
841
Carl-Daniel Hailfingerb18ecbc2009-06-19 14:20:34 +0000842features: compiler
843 @echo "FEATURES := yes" > .features.tmp
James Lairdc60de0e2013-03-27 13:00:23 +0000844ifeq ($(NEED_FTDI), yes)
Paul Fox05dfbe62009-06-16 21:08:06 +0000845 @printf "Checking for FTDI support... "
Stefan Tauner56787082011-08-18 02:27:19 +0000846 @echo "$$FTDI_TEST" > .featuretest.c
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000847 @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) $(FTDILIBS) $(LIBS) >/dev/null 2>&1 && \
Carl-Daniel Hailfingerb18ecbc2009-06-19 14:20:34 +0000848 ( echo "found."; echo "FTDISUPPORT := yes" >> .features.tmp ) || \
849 ( echo "not found."; echo "FTDISUPPORT := no" >> .features.tmp )
Ilya A. Volynets-Evenbakh2c714ab2012-09-26 00:47:09 +0000850 @printf "Checking for FT232H support in libftdi... "
851 @echo "$$FTDI_232H_TEST" >> .featuretest.c
852 @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) $(FTDILIBS) $(LIBS) >/dev/null 2>&1 && \
853 ( echo "found."; echo "FT232H := yes" >> .features.tmp ) || \
854 ( echo "not found."; echo "FT232H := no" >> .features.tmp )
Carl-Daniel Hailfinger8a59ff02009-12-24 03:33:11 +0000855endif
Stefan Tauner8868db32012-03-13 00:18:19 +0000856ifeq ($(CONFIG_LINUX_SPI), yes)
857 @printf "Checking if Linux SPI headers are present... "
858 @echo "$$LINUX_SPI_TEST" > .featuretest.c
859 @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \
860 ( echo "yes."; echo "LINUX_SPI_SUPPORT := yes" >> .features.tmp ) || \
861 ( echo "no."; echo "LINUX_SPI_SUPPORT := no" >> .features.tmp )
862endif
Stefan Tauner56787082011-08-18 02:27:19 +0000863 @printf "Checking for utsname support... "
864 @echo "$$UTSNAME_TEST" > .featuretest.c
865 @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \
866 ( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) || \
867 ( echo "not found."; echo "UTSNAME := no" >> .features.tmp )
868 @$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features
869 @rm -f .featuretest.c .featuretest$(EXEC_SUFFIX)
Paul Fox05dfbe62009-06-16 21:08:06 +0000870
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000871install: $(PROGRAM)$(EXEC_SUFFIX)
Uwe Hermannc2a9c9c2009-05-14 14:51:14 +0000872 mkdir -p $(DESTDIR)$(PREFIX)/sbin
Uwe Hermann56b2cb02009-05-21 15:59:58 +0000873 mkdir -p $(DESTDIR)$(MANDIR)/man8
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000874 $(INSTALL) -m 0755 $(PROGRAM)$(EXEC_SUFFIX) $(DESTDIR)$(PREFIX)/sbin
Uwe Hermann56b2cb02009-05-21 15:59:58 +0000875 $(INSTALL) -m 0644 $(PROGRAM).8 $(DESTDIR)$(MANDIR)/man8
Uwe Hermannc113b572006-12-14 00:59:41 +0000876
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +0000877export:
Carl-Daniel Hailfinger48e5e092009-08-31 16:25:08 +0000878 @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
879 @svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
880 @sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile >$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
881 @LC_ALL=C svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
882 @echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +0000883
884tarball: export
Carl-Daniel Hailfinger48e5e092009-08-31 16:25:08 +0000885 @tar cjf $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.bz2 -C $(EXPORTDIR)/ $(TAROPTIONS) flashrom-$(RELEASENAME)/
886 @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
887 @echo Created $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.bz2
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +0000888
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000889djgpp-dos: clean
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000890 make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip
891libpayload: clean
892 make CC="CC=i386-elf-gcc lpgcc" AR=i386-elf-ar RANLIB=i386-elf-ranlib
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000893
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000894.PHONY: all clean distclean compiler hwlibs features export tarball dos featuresavailable
Ollie Lho184a4042005-11-26 21:55:36 +0000895
Stefan Reinauere2f01582010-06-07 11:08:07 +0000896-include $(OBJS:.o=.d)