Makefile 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. #
  2. # This file is part of the flashrom project.
  3. #
  4. # Copyright (C) 2005 coresystems GmbH <stepan@coresystems.de>
  5. # Copyright (C) 2009,2010 Carl-Daniel Hailfinger
  6. #
  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
  19. #
  20. PROGRAM = flashrom
  21. CC ?= gcc
  22. STRIP ?= strip
  23. INSTALL = install
  24. DIFF = diff
  25. PREFIX ?= /usr/local
  26. MANDIR ?= $(PREFIX)/share/man
  27. CFLAGS ?= -Os -Wall -Wshadow
  28. EXPORTDIR ?= .
  29. AR ?= ar
  30. RANLIB ?= ranlib
  31. PKG_CONFIG ?= pkg-config
  32. WARNERROR ?= yes
  33. ifneq ($(NOWARNERROR),yes)
  34. CFLAGS +=
  35. endif
  36. ifeq ($(CONFIG_STATIC),yes)
  37. PKG_CONFIG += --static
  38. endif
  39. # HOST_OS is only used to work around local toolchain issues.
  40. HOST_OS ?= $(shell uname)
  41. ifeq ($(HOST_OS), MINGW32_NT-5.1)
  42. # Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found".
  43. CC = gcc
  44. endif
  45. ifneq ($(HOST_OS), SunOS)
  46. STRIP_ARGS = -s
  47. endif
  48. # Determine the destination processor architecture.
  49. # IMPORTANT: The following line must be placed before TARGET_OS is ever used
  50. # (of course), but should come after any lines setting CC because the line
  51. # below uses CC itself.
  52. override TARGET_OS := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E os.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
  53. ifeq ($(TARGET_OS), Darwin)
  54. CPPFLAGS += -I/opt/local/include -I/usr/local/include
  55. # DirectHW framework can be found in the DirectHW library.
  56. LDFLAGS += -framework IOKit -framework DirectHW -L/opt/local/lib -L/usr/local/lib
  57. endif
  58. ifeq ($(TARGET_OS), FreeBSD)
  59. CPPFLAGS += -I/usr/local/include
  60. LDFLAGS += -L/usr/local/lib
  61. endif
  62. ifeq ($(TARGET_OS), OpenBSD)
  63. CPPFLAGS += -I/usr/local/include
  64. LDFLAGS += -L/usr/local/lib
  65. endif
  66. ifeq ($(TARGET_OS), DOS)
  67. EXEC_SUFFIX := .exe
  68. CPPFLAGS += -I../libgetopt -I../libpci/include
  69. # DJGPP has odd uint*_t definitions which cause lots of format string warnings.
  70. CPPFLAGS += -Wno-format
  71. # FIXME Check if we can achieve the same effect with -L../libgetopt -lgetopt
  72. LIBS += ../libgetopt/libgetopt.a
  73. # Bus Pirate and Serprog are not supported under DOS (missing serial support).
  74. ifeq ($(CONFIG_BUSPIRATE_SPI), yes)
  75. UNSUPPORTED_FEATURES += CONFIG_BUSPIRATE_SPI=yes
  76. else
  77. override CONFIG_BUSPIRATE_SPI = no
  78. endif
  79. ifeq ($(CONFIG_SERPROG), yes)
  80. UNSUPPORTED_FEATURES += CONFIG_SERPROG=yes
  81. else
  82. override CONFIG_SERPROG = no
  83. endif
  84. # Dediprog and FT2232 are not supported under DOS (missing USB support).
  85. ifeq ($(CONFIG_DEDIPROG), yes)
  86. UNSUPPORTED_FEATURES += CONFIG_DEDIPROG=yes
  87. else
  88. override CONFIG_DEDIPROG = no
  89. endif
  90. ifeq ($(CONFIG_FT2232_SPI), yes)
  91. UNSUPPORTED_FEATURES += CONFIG_FT2232_SPI=yes
  92. else
  93. override CONFIG_FT2232_SPI = no
  94. endif
  95. endif
  96. # FIXME: Should we check for Cygwin/MSVC as well?
  97. ifeq ($(TARGET_OS), MinGW)
  98. EXEC_SUFFIX := .exe
  99. # MinGW doesn't have the ffs() function, but we can use gcc's __builtin_ffs().
  100. CFLAGS += -Dffs=__builtin_ffs
  101. # libusb-win32/libftdi stuff is usually installed in /usr/local.
  102. CPPFLAGS += -I/usr/local/include
  103. LDFLAGS += -L/usr/local/lib
  104. # Serprog is not supported under Windows/MinGW (missing sockets support).
  105. ifeq ($(CONFIG_SERPROG), yes)
  106. UNSUPPORTED_FEATURES += CONFIG_SERPROG=yes
  107. else
  108. override CONFIG_SERPROG = no
  109. endif
  110. # For now we disable all PCI-based programmers on Windows/MinGW (no libpci).
  111. ifeq ($(CONFIG_INTERNAL), yes)
  112. UNSUPPORTED_FEATURES += CONFIG_INTERNAL=yes
  113. else
  114. override CONFIG_INTERNAL = no
  115. endif
  116. ifeq ($(CONFIG_RAYER_SPI), yes)
  117. UNSUPPORTED_FEATURES += CONFIG_RAYER_SPI=yes
  118. else
  119. override CONFIG_RAYER_SPI = no
  120. endif
  121. ifeq ($(CONFIG_NIC3COM), yes)
  122. UNSUPPORTED_FEATURES += CONFIG_NIC3COM=yes
  123. else
  124. override CONFIG_NIC3COM = no
  125. endif
  126. ifeq ($(CONFIG_GFXNVIDIA), yes)
  127. UNSUPPORTED_FEATURES += CONFIG_GFXNVIDIA=yes
  128. else
  129. override CONFIG_GFXNVIDIA = no
  130. endif
  131. ifeq ($(CONFIG_SATASII), yes)
  132. UNSUPPORTED_FEATURES += CONFIG_SATASII=yes
  133. else
  134. override CONFIG_SATASII = no
  135. endif
  136. ifeq ($(CONFIG_ATAHPT), yes)
  137. UNSUPPORTED_FEATURES += CONFIG_ATAHPT=yes
  138. else
  139. override CONFIG_ATAHPT = no
  140. endif
  141. ifeq ($(CONFIG_DRKAISER), yes)
  142. UNSUPPORTED_FEATURES += CONFIG_DRKAISER=yes
  143. else
  144. override CONFIG_DRKAISER = no
  145. endif
  146. ifeq ($(CONFIG_NICREALTEK), yes)
  147. UNSUPPORTED_FEATURES += CONFIG_NICREALTEK=yes
  148. else
  149. override CONFIG_NICREALTEK = no
  150. endif
  151. ifeq ($(CONFIG_NICNATSEMI), yes)
  152. UNSUPPORTED_FEATURES += CONFIG_NICNATSEMI=yes
  153. else
  154. override CONFIG_NICNATSEMI = no
  155. endif
  156. ifeq ($(CONFIG_NICINTEL), yes)
  157. UNSUPPORTED_FEATURES += CONFIG_NICINTEL=yes
  158. else
  159. override CONFIG_NICINTEL = no
  160. endif
  161. ifeq ($(CONFIG_NICINTEL_SPI), yes)
  162. UNSUPPORTED_FEATURES += CONFIG_NICINTEL_SPI=yes
  163. else
  164. override CONFIG_NICINTEL_SPI = no
  165. endif
  166. ifeq ($(CONFIG_OGP_SPI), yes)
  167. UNSUPPORTED_FEATURES += CONFIG_OGP_SPI=yes
  168. else
  169. override CONFIG_OGP_SPI = no
  170. endif
  171. ifeq ($(CONFIG_SATAMV), yes)
  172. UNSUPPORTED_FEATURES += CONFIG_SATAMV=yes
  173. else
  174. override CONFIG_SATAMV = no
  175. endif
  176. endif
  177. ifeq ($(TARGET_OS), libpayload)
  178. CPPFLAGS += -DSTANDALONE
  179. ifeq ($(CONFIG_DUMMY), yes)
  180. UNSUPPORTED_FEATURES += CONFIG_DUMMY=yes
  181. else
  182. override CONFIG_DUMMY = no
  183. endif
  184. ifeq ($(CONFIG_BUSPIRATE_SPI), yes)
  185. UNSUPPORTED_FEATURES += CONFIG_BUSPIRATE_SPI=yes
  186. else
  187. override CONFIG_BUSPIRATE_SPI = no
  188. endif
  189. ifeq ($(CONFIG_SERPROG), yes)
  190. UNSUPPORTED_FEATURES += CONFIG_SERPROG=yes
  191. else
  192. override CONFIG_SERPROG = no
  193. endif
  194. # Dediprog and FT2232 are not supported with libpayload (missing libusb support)
  195. ifeq ($(CONFIG_DEDIPROG), yes)
  196. UNSUPPORTED_FEATURES += CONFIG_DEDIPROG=yes
  197. else
  198. override CONFIG_DEDIPROG = no
  199. endif
  200. ifeq ($(CONFIG_FT2232_SPI), yes)
  201. UNSUPPORTED_FEATURES += CONFIG_FT2232_SPI=yes
  202. else
  203. override CONFIG_FT2232_SPI = no
  204. endif
  205. endif
  206. ifneq ($(TARGET_OS), Linux)
  207. ifeq ($(CONFIG_LINUX_SPI), yes)
  208. UNSUPPORTED_FEATURES += CONFIG_LINUX_SPI=yes
  209. else
  210. override CONFIG_LINUX_SPI = no
  211. endif
  212. endif
  213. # Determine the destination processor architecture.
  214. # IMPORTANT: The following line must be placed before ARCH is ever used
  215. # (of course), but should come after any lines setting CC because the line
  216. # below uses CC itself.
  217. override ARCH := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E arch.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
  218. ifeq ($(ARCH), ppc)
  219. # There's no PCI port I/O support on PPC/PowerPC, yet.
  220. ifeq ($(CONFIG_NIC3COM), yes)
  221. UNSUPPORTED_FEATURES += CONFIG_NIC3COM=yes
  222. else
  223. override CONFIG_NIC3COM = no
  224. endif
  225. ifeq ($(CONFIG_NICREALTEK), yes)
  226. UNSUPPORTED_FEATURES += CONFIG_NICREALTEK=yes
  227. else
  228. override CONFIG_NICREALTEK = no
  229. endif
  230. ifeq ($(CONFIG_NICNATSEMI), yes)
  231. UNSUPPORTED_FEATURES += CONFIG_NICNATSEMI=yes
  232. else
  233. override CONFIG_NICNATSEMI = no
  234. endif
  235. ifeq ($(CONFIG_RAYER_SPI), yes)
  236. UNSUPPORTED_FEATURES += CONFIG_RAYER_SPI=yes
  237. else
  238. override CONFIG_RAYER_SPI = no
  239. endif
  240. ifeq ($(CONFIG_ATAHPT), yes)
  241. UNSUPPORTED_FEATURES += CONFIG_ATAHPT=yes
  242. else
  243. override CONFIG_ATAHPT = no
  244. endif
  245. ifeq ($(CONFIG_SATAMV), yes)
  246. UNSUPPORTED_FEATURES += CONFIG_SATAMV=yes
  247. else
  248. override CONFIG_SATAMV = no
  249. endif
  250. endif
  251. CHIP_OBJS = jedec.o stm50flw0x0x.o w39.o w29ee011.o \
  252. sst28sf040.o m29f400bt.o 82802ab.o pm49fl00x.o \
  253. sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o sharplhf00l04.o \
  254. a25.o at25.o s25f.o opaque.o writeprotect.o
  255. LIB_OBJS = android.o layout.o file.o fmap.o power.o search.o
  256. ifeq ($(CONFIG_FDTMAP), yes)
  257. FEATURE_CFLAGS += -D'CONFIG_FDTMAP=1'
  258. LIB_OBJS += fdtmap.o
  259. ifeq ($(CONFIG_STATIC), yes)
  260. LIBS += -static -lfdt -lz
  261. else
  262. LIBS += -lfdt -lz
  263. endif
  264. endif
  265. LOCK_OBJS = big_lock.o file_lock.o cros_ec_lock.o
  266. LIB_OBJS += $(LOCK_OBJS)
  267. FEATURE_CFLAGS += -D'USE_BIG_LOCK=1' -D'USE_CROS_EC_LOCK=1'
  268. CLI_OBJS = flashrom.o cli_mfg.o cli_output.o print.o
  269. PROGRAMMER_OBJS = udelay.o programmer.o
  270. all: pciutils features $(PROGRAM)$(EXEC_SUFFIX)
  271. # Set the flashrom version string from the highest revision number
  272. # of the checked out flashrom files.
  273. # Note to packagers: Any tree exported with "make export" or "make tarball"
  274. # will not require subversion. The downloadable snapshots are already exported.
  275. SVNVERSION := $(shell ./util/getversion.sh)
  276. RELEASE := 0.9.4
  277. VERSION := $(RELEASE) $(SVNVERSION)
  278. RELEASENAME ?= $(VERSION)
  279. SVNDEF := -D'FLASHROM_VERSION="$(VERSION)"'
  280. # Always enable internal/onboard support for now.
  281. CONFIG_INTERNAL ?= yes
  282. # Always enable serprog for now. Needs to be disabled on Windows.
  283. CONFIG_SERPROG ?= no
  284. # RayeR SPIPGM hardware support
  285. CONFIG_RAYER_SPI ?= no
  286. # Always enable 3Com NICs for now.
  287. CONFIG_NIC3COM ?= no
  288. # Enable NVIDIA graphics cards. Note: write and erase do not work properly.
  289. CONFIG_GFXNVIDIA ?= no
  290. # Always enable SiI SATA controllers for now.
  291. CONFIG_SATASII ?= no
  292. # Highpoint (HPT) ATA/RAID controller support.
  293. # IMPORTANT: This code is not yet working!
  294. CONFIG_ATAHPT ?= no
  295. # Always enable FT2232 SPI dongles for now.
  296. CONFIG_FT2232_SPI ?= yes
  297. # Always enable dummy tracing for now.
  298. CONFIG_DUMMY ?= yes
  299. # Always enable Dr. Kaiser for now.
  300. CONFIG_DRKAISER ?= no
  301. # Always enable Realtek NICs for now.
  302. CONFIG_NICREALTEK ?= no
  303. # Disable National Semiconductor NICs until support is complete and tested.
  304. CONFIG_NICNATSEMI ?= no
  305. # Always enable Intel NICs for now.
  306. CONFIG_NICINTEL ?= no
  307. # Always enable SPI on Intel NICs for now.
  308. CONFIG_NICINTEL_SPI ?= no
  309. # Always enable SPI on OGP cards for now.
  310. CONFIG_OGP_SPI ?= no
  311. # Always enable Bus Pirate SPI for now.
  312. CONFIG_BUSPIRATE_SPI ?= no
  313. # Raiden Debug SPI-over-USB support.
  314. CONFIG_RAIDEN_DEBUG_SPI ?= no
  315. # Enable Linux I2C for ChromeOS EC
  316. CONFIG_LINUX_I2C ?= yes
  317. CONFIG_LINUX_MTD ?= no
  318. # Always enable Dediprog SF100 for now.
  319. CONFIG_DEDIPROG ?= yes
  320. # Always enable Marvell SATA controllers for now.
  321. CONFIG_SATAMV ?= yes
  322. # Enable Linux spidev interface by default. We disable it on non-Linux targets.
  323. CONFIG_LINUX_SPI ?= yes
  324. # Disable wiki printing by default. It is only useful if you have wiki access.
  325. CONFIG_PRINT_WIKI ?= no
  326. # Support for reading a flashmap from a device tree in the image
  327. CONFIG_FDTMAP ?= no
  328. # Bitbanging SPI infrastructure, default off unless needed.
  329. ifeq ($(CONFIG_RAYER_SPI), yes)
  330. override CONFIG_BITBANG_SPI = yes
  331. else
  332. ifeq ($(CONFIG_INTERNAL), yes)
  333. override CONFIG_BITBANG_SPI = yes
  334. else
  335. ifeq ($(CONFIG_NICINTEL_SPI), yes)
  336. override CONFIG_BITBANG_SPI = yes
  337. else
  338. ifeq ($(CONFIG_OGP_SPI), yes)
  339. override CONFIG_BITBANG_SPI = yes
  340. else
  341. CONFIG_BITBANG_SPI ?= no
  342. endif
  343. endif
  344. endif
  345. endif
  346. ifeq ($(CONFIG_INTERNAL), yes)
  347. FEATURE_CFLAGS += -D'CONFIG_INTERNAL=1'
  348. PROGRAMMER_OBJS += processor_enable.o chipset_enable.o board_enable.o cbtable.o dmi.o internal.o cros_ec.o
  349. ifeq ($(ARCH),x86)
  350. PROGRAMMER_OBJS += cros_ec_lpc.o it87spi.o it85spi.o mec1308.o sb600spi.o wbsio_spi.o mcp6x_spi.o wpce775x.o ene_lpc.o
  351. PROGRAMMER_OBJS += ichspi.o ich_descriptors.o
  352. else
  353. ifeq ($(ARCH),arm)
  354. PROGRAMMER_OBJS += cros_ec_i2c.o
  355. CONFIG_SATAMV := no
  356. endif
  357. NEED_PCI := yes
  358. endif
  359. endif
  360. PROGRAMMER_OBJS += cros_ec_dev.o
  361. ifeq ($(CONFIG_SERPROG), yes)
  362. FEATURE_CFLAGS += -D'CONFIG_SERPROG=1'
  363. PROGRAMMER_OBJS += serprog.o
  364. NEED_SERIAL := yes
  365. NEED_NET := yes
  366. endif
  367. ifeq ($(CONFIG_RAYER_SPI), yes)
  368. FEATURE_CFLAGS += -D'CONFIG_RAYER_SPI=1'
  369. PROGRAMMER_OBJS += rayer_spi.o
  370. # Actually, NEED_PCI is wrong. NEED_IOPORT_ACCESS would be more correct.
  371. NEED_PCI := yes
  372. endif
  373. ifeq ($(CONFIG_BITBANG_SPI), yes)
  374. FEATURE_CFLAGS += -D'CONFIG_BITBANG_SPI=1'
  375. PROGRAMMER_OBJS += bitbang_spi.o
  376. endif
  377. ifeq ($(CONFIG_NIC3COM), yes)
  378. FEATURE_CFLAGS += -D'CONFIG_NIC3COM=1'
  379. PROGRAMMER_OBJS += nic3com.o
  380. NEED_PCI := yes
  381. endif
  382. ifeq ($(CONFIG_GFXNVIDIA), yes)
  383. FEATURE_CFLAGS += -D'CONFIG_GFXNVIDIA=1'
  384. PROGRAMMER_OBJS += gfxnvidia.o
  385. NEED_PCI := yes
  386. endif
  387. ifeq ($(CONFIG_SATASII), yes)
  388. FEATURE_CFLAGS += -D'CONFIG_SATASII=1'
  389. PROGRAMMER_OBJS += satasii.o
  390. NEED_PCI := yes
  391. endif
  392. ifeq ($(CONFIG_ATAHPT), yes)
  393. FEATURE_CFLAGS += -D'CONFIG_ATAHPT=1'
  394. PROGRAMMER_OBJS += atahpt.o
  395. NEED_PCI := yes
  396. endif
  397. ifeq ($(CONFIG_FT2232_SPI), yes)
  398. FTDILIBS := $(shell $(PKG_CONFIG) --libs libftdi1 2>/dev/null || \
  399. $(PKG_CONFIG) --libs libftdi 2>/dev/null || echo "-lftdi -lusb-1.0")
  400. FTDICFLAGS := $(shell $(PKG_CONFIG) --cflags libftdi1 2>/dev/null || \
  401. $(PKG_CONFIG) --cflags libftdi 2>/dev/null)
  402. # This is a totally ugly hack.
  403. FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "FTDISUPPORT := yes" .features && echo "$(FTDICFLAGS) -D'CONFIG_FT2232_SPI=1'")
  404. FEATURE_LIBS += $(shell LC_ALL=C grep -q "FTDISUPPORT := yes" .features && echo "$(FTDILIBS)")
  405. PROGRAMMER_OBJS += ft2232_spi.o
  406. NEED_USB := yes
  407. endif
  408. ifeq ($(CONFIG_DUMMY), yes)
  409. FEATURE_CFLAGS += -D'CONFIG_DUMMY=1'
  410. PROGRAMMER_OBJS += dummyflasher.o
  411. endif
  412. ifeq ($(CONFIG_DRKAISER), yes)
  413. FEATURE_CFLAGS += -D'CONFIG_DRKAISER=1'
  414. PROGRAMMER_OBJS += drkaiser.o
  415. NEED_PCI := yes
  416. endif
  417. ifeq ($(CONFIG_NICREALTEK), yes)
  418. FEATURE_CFLAGS += -D'CONFIG_NICREALTEK=1'
  419. PROGRAMMER_OBJS += nicrealtek.o
  420. NEED_PCI := yes
  421. endif
  422. ifeq ($(CONFIG_NICNATSEMI), yes)
  423. FEATURE_CFLAGS += -D'CONFIG_NICNATSEMI=1'
  424. PROGRAMMER_OBJS += nicnatsemi.o
  425. NEED_PCI := yes
  426. endif
  427. ifeq ($(CONFIG_NICINTEL), yes)
  428. FEATURE_CFLAGS += -D'CONFIG_NICINTEL=1'
  429. PROGRAMMER_OBJS += nicintel.o
  430. NEED_PCI := yes
  431. endif
  432. ifeq ($(CONFIG_NICINTEL_SPI), yes)
  433. FEATURE_CFLAGS += -D'CONFIG_NICINTEL_SPI=1'
  434. PROGRAMMER_OBJS += nicintel_spi.o
  435. NEED_PCI := yes
  436. endif
  437. ifeq ($(CONFIG_OGP_SPI), yes)
  438. FEATURE_CFLAGS += -D'CONFIG_OGP_SPI=1'
  439. PROGRAMMER_OBJS += ogp_spi.o
  440. NEED_PCI := yes
  441. endif
  442. ifeq ($(CONFIG_BUSPIRATE_SPI), yes)
  443. FEATURE_CFLAGS += -D'CONFIG_BUSPIRATE_SPI=1'
  444. PROGRAMMER_OBJS += buspirate_spi.o
  445. NEED_SERIAL := yes
  446. endif
  447. ifeq ($(CONFIG_RAIDEN_DEBUG_SPI), yes)
  448. FEATURE_CFLAGS += -D'CONFIG_RAIDEN_DEBUG_SPI=1'
  449. PROGRAMMER_OBJS += raiden_debug_spi.o usb_device.o
  450. NEED_USB := yes
  451. endif
  452. ifeq ($(CONFIG_LINUX_I2C), yes)
  453. FEATURE_CFLAGS += -D'CONFIG_LINUX_I2C=1'
  454. PROGRAMMER_OBJS += linux_i2c.o
  455. endif
  456. ifeq ($(CONFIG_LINUX_MTD), yes)
  457. FEATURE_CFLAGS += -D'CONFIG_LINUX_MTD=1'
  458. PROGRAMMER_OBJS += linux_mtd.o
  459. endif
  460. ifeq ($(CONFIG_DEDIPROG), yes)
  461. FEATURE_CFLAGS += -D'CONFIG_DEDIPROG=1'
  462. FEATURE_LIBS += -lusb-1.0
  463. PROGRAMMER_OBJS += dediprog.o
  464. endif
  465. ifeq ($(CONFIG_SATAMV), yes)
  466. FEATURE_CFLAGS += -D'CONFIG_SATAMV=1'
  467. PROGRAMMER_OBJS += satamv.o
  468. NEED_PCI := yes
  469. endif
  470. ifeq ($(CONFIG_LINUX_SPI), yes)
  471. FEATURE_CFLAGS += -D'CONFIG_LINUX_SPI=1'
  472. PROGRAMMER_OBJS += linux_spi.o
  473. endif
  474. ifeq ($(NEED_SERIAL), yes)
  475. LIB_OBJS += serial.o
  476. endif
  477. ifeq ($(NEED_NET), yes)
  478. ifeq ($(TARGET_OS), SunOS)
  479. LIBS += -lsocket
  480. endif
  481. endif
  482. ifeq ($(NEED_PCI), yes)
  483. CHECK_LIBPCI = yes
  484. FEATURE_CFLAGS += -D'NEED_PCI=1'
  485. PROGRAMMER_OBJS += pcidev.o physmap.o hwaccess.o
  486. ifeq ($(TARGET_OS), NetBSD)
  487. # The libpci we want is called libpciutils on NetBSD and needs NetBSD libpci.
  488. LIBS += -lpciutils -lpci
  489. # For (i386|x86_64)_iopl(2).
  490. LIBS += -l$(shell uname -p)
  491. else
  492. ifeq ($(TARGET_OS), DOS)
  493. # FIXME There needs to be a better way to do this
  494. LIBS += ../libpci/lib/libpci.a
  495. else
  496. ifeq ($(CONFIG_STATIC), yes)
  497. LIBS_PCI := $(shell $(PKG_CONFIG) --libs --static libpci)
  498. LIBS += -static $(LIBS_PCI)
  499. else
  500. LIBS += -lpci
  501. endif
  502. ifeq ($(TARGET_OS), OpenBSD)
  503. # For (i386|amd64)_iopl(2).
  504. LIBS += -l$(shell uname -m)
  505. endif
  506. endif
  507. endif
  508. endif
  509. ifeq ($(NEED_USB),yes)
  510. FEATURE_CFLAGS += $(shell $(PKG_CONFIG) --cflags libusb-1.0)
  511. FEATURE_LIBS += $(shell $(PKG_CONFIG) --libs libusb-1.0)
  512. endif
  513. ifeq ($(CONFIG_PRINT_WIKI), yes)
  514. FEATURE_CFLAGS += -D'CONFIG_PRINT_WIKI=1'
  515. CLI_OBJS += print_wiki.o
  516. endif
  517. ifeq ($(CONFIG_USE_OS_TIMER), yes)
  518. FEATURE_CFLAGS += -D'CONFIG_USE_OS_TIMER=1'
  519. else
  520. FEATURE_CFLAGS += -D'CONFIG_USE_OS_TIMER=0'
  521. endif
  522. FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "UTSNAME := yes" .features && printf "%s" "-D'HAVE_UTSNAME=1'")
  523. # We could use PULLED_IN_LIBS, but that would be ugly.
  524. FEATURE_LIBS += $(shell LC_ALL=C grep -q "NEEDLIBZ := yes" .libdeps && printf "%s" "-lz")
  525. LIBFLASHROM_OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS)
  526. OBJS = $(CLI_OBJS) $(LIBFLASHROM_OBJS)
  527. $(PROGRAM)$(EXEC_SUFFIX): $(OBJS)
  528. $(CC) $(LDFLAGS) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJS) $(FEATURE_LIBS) $(LIBS)
  529. libflashrom.a: $(LIBFLASHROM_OBJS)
  530. $(AR) rcs $@ $^
  531. $(RANLIB) $@
  532. # TAROPTIONS reduces information leakage from the packager's system.
  533. # If other tar programs support command line arguments for setting uid/gid of
  534. # stored files, they can be handled here as well.
  535. TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
  536. %.o: %.c .features
  537. $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FEATURE_CFLAGS) $(SVNDEF) -o $@ -c $<
  538. # Make sure to add all names of generated binaries here.
  539. # This includes all frontends and libflashrom.
  540. # We don't use EXEC_SUFFIX here because we want to clean everything.
  541. clean:
  542. rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a *.o *.d
  543. distclean: clean
  544. rm -f .features .libdeps
  545. strip: $(PROGRAM)$(EXEC_SUFFIX)
  546. $(STRIP) $(STRIP_ARGS) $(PROGRAM)$(EXEC_SUFFIX)
  547. # to define test programs we use verbatim variables, which get exported
  548. # to environment variables and are referenced with $$<varname> later
  549. define COMPILER_TEST
  550. int main(int argc, char **argv)
  551. {
  552. (void) argc;
  553. (void) argv;
  554. return 0;
  555. }
  556. endef
  557. export COMPILER_TEST
  558. compiler: featuresavailable
  559. @printf "Checking for a C compiler... "
  560. @echo "$$COMPILER_TEST" > .test.c
  561. @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .test.c -o .test$(EXEC_SUFFIX) >/dev/null 2>&1 && \
  562. echo "found." || ( echo "not found."; \
  563. rm -f .test.c .test$(EXEC_SUFFIX); exit 1)
  564. @rm -f .test.c .test$(EXEC_SUFFIX)
  565. @printf "Target arch is "
  566. @# FreeBSD wc will output extraneous whitespace.
  567. @echo $(ARCH)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \
  568. ( echo "unknown. Aborting."; exit 1)
  569. @printf "%s\n" '$(ARCH)'
  570. @printf "Target OS is "
  571. @# FreeBSD wc will output extraneous whitespace.
  572. @echo $(TARGET_OS)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \
  573. ( echo "unknown. Aborting."; exit 1)
  574. @printf "%s\n" '$(TARGET_OS)'
  575. define LIBPCI_TEST
  576. /* Avoid a failing test due to libpci header symbol shadowing breakage */
  577. #define index shadow_workaround_index
  578. #include <pci/pci.h>
  579. struct pci_access *pacc;
  580. int main(int argc, char **argv)
  581. {
  582. (void) argc;
  583. (void) argv;
  584. pacc = pci_alloc();
  585. return 0;
  586. }
  587. endef
  588. export LIBPCI_TEST
  589. ifeq ($(CHECK_LIBPCI), yes)
  590. pciutils: compiler
  591. @printf "Checking for libpci headers... "
  592. @echo "$$LIBPCI_TEST" > .test.c
  593. @$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >/dev/null 2>&1 && \
  594. echo "found." || ( echo "not found."; echo; \
  595. echo "Please install libpci headers (package pciutils-devel)."; \
  596. echo "See README for more information."; echo; \
  597. rm -f .test.c .test.o; exit 1)
  598. @printf "Checking if libpci is present and sufficient... "
  599. @printf "" > .libdeps
  600. @$(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) >/dev/null 2>&1 && \
  601. echo "yes." || ( echo "no."; \
  602. printf "Checking if libz+libpci are present and sufficient..."; \
  603. $(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) -lz >/dev/null 2>&1 && \
  604. ( echo "yes."; echo "NEEDLIBZ := yes" > .libdeps ) || ( echo "no."; echo; \
  605. echo "Please install libpci (package pciutils) and/or libz."; \
  606. echo "See README for more information."; echo; \
  607. rm -f .test.c .test.o .test$(EXEC_SUFFIX); exit 1) )
  608. @rm -f .test.c .test.o .test$(EXEC_SUFFIX)
  609. else
  610. pciutils: compiler
  611. @printf "" > .libdeps
  612. endif
  613. .features: features
  614. # If a user does not explicitly request a non-working feature, we should
  615. # silently disable it. However, if a non-working (does not compile) feature
  616. # is explicitly requested, we should bail out with a descriptive error message.
  617. ifeq ($(UNSUPPORTED_FEATURES), )
  618. featuresavailable:
  619. else
  620. featuresavailable:
  621. @echo "The following features are unavailable on your machine: $(UNSUPPORTED_FEATURES)"
  622. @false
  623. endif
  624. define FTDI_TEST
  625. #include <ftdi.h>
  626. struct ftdi_context *ftdic = (void *)0;
  627. int main(int argc, char **argv)
  628. {
  629. (void) argc;
  630. (void) argv;
  631. return ftdi_init(ftdic);
  632. }
  633. endef
  634. export FTDI_TEST
  635. define UTSNAME_TEST
  636. #include <sys/utsname.h>
  637. struct utsname osinfo;
  638. int main(int argc, char **argv)
  639. {
  640. (void) argc;
  641. (void) argv;
  642. uname (&osinfo);
  643. return 0;
  644. }
  645. endef
  646. export UTSNAME_TEST
  647. features: compiler
  648. @echo "FEATURES := yes" > .features.tmp
  649. ifeq ($(CONFIG_FT2232_SPI), yes)
  650. @printf "Checking for FTDI support... "
  651. @echo "$$FTDI_TEST" > .featuretest.c
  652. @$(CC) $(CPPFLAGS) $(CFLAGS) $(FTDICFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) $(FTDILIBS) $(LIBS) >/dev/null 2>&1 && \
  653. ( echo "found."; echo "FTDISUPPORT := yes" >> .features.tmp ) || \
  654. ( echo "not found."; echo "FTDISUPPORT := no" >> .features.tmp )
  655. endif
  656. @printf "Checking for utsname support... "
  657. @echo "$$UTSNAME_TEST" > .featuretest.c
  658. @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o .featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \
  659. ( echo "found."; echo "UTSNAME := yes" >> .features.tmp ) || \
  660. ( echo "not found."; echo "UTSNAME := no" >> .features.tmp )
  661. @$(DIFF) -q .features.tmp .features >/dev/null 2>&1 && rm .features.tmp || mv .features.tmp .features
  662. @rm -f .featuretest.c .featuretest$(EXEC_SUFFIX)
  663. install: $(PROGRAM)$(EXEC_SUFFIX)
  664. mkdir -p $(DESTDIR)$(PREFIX)/sbin
  665. mkdir -p $(DESTDIR)$(MANDIR)/man8
  666. $(INSTALL) -m 0755 $(PROGRAM)$(EXEC_SUFFIX) $(DESTDIR)$(PREFIX)/sbin
  667. $(INSTALL) -m 0644 $(PROGRAM).8 $(DESTDIR)$(MANDIR)/man8
  668. export:
  669. @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
  670. @svn export -r BASE . $(EXPORTDIR)/flashrom-$(RELEASENAME)
  671. @sed "s/^SVNVERSION.*/SVNVERSION := $(SVNVERSION)/" Makefile >$(EXPORTDIR)/flashrom-$(RELEASENAME)/Makefile
  672. @LC_ALL=C svn log >$(EXPORTDIR)/flashrom-$(RELEASENAME)/ChangeLog
  673. @echo Exported $(EXPORTDIR)/flashrom-$(RELEASENAME)/
  674. tarball: export
  675. @tar cjf $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.bz2 -C $(EXPORTDIR)/ $(TAROPTIONS) flashrom-$(RELEASENAME)/
  676. @rm -rf $(EXPORTDIR)/flashrom-$(RELEASENAME)
  677. @echo Created $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.bz2
  678. djgpp-dos: clean
  679. make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip
  680. libpayload: clean
  681. make CC="CC=i386-elf-gcc lpgcc" AR=i386-elf-ar RANLIB=i386-elf-ranlib
  682. .PHONY: all clean distclean compiler pciutils features export tarball dos featuresavailable
  683. -include $(OBJS:.o=.d)