Skip to content

Commit d3d038c

Browse files
jameshilliardapritzel
authored andcommitted
sunxi-fel: find libfdt with pkg-config when available
sunxi-fel uses libfdt to parse FIT images, but the Makefile only passed -lfdt when linking. That works when libfdt headers and libraries are installed in default compiler search paths, but fails when a package installs them elsewhere. Use pkg-config to obtain the libfdt compiler and linker flags when a libfdt.pc file is available. Keep the old empty CFLAGS and -lfdt fallback for systems where libfdt is installed in default search paths or packages do not provide pkg-config metadata. Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
1 parent 4f144b3 commit d3d038c

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ ZLIB = zlib
134134
ZLIB_CFLAGS ?= `$(PKG_CONFIG) --cflags $(ZLIB)`
135135
ZLIB_LIBS ?= `$(PKG_CONFIG) --libs $(ZLIB)`
136136

137+
LIBFDT = libfdt
138+
LIBFDT_PKGCONFIG := $(shell $(PKG_CONFIG) --exists $(LIBFDT) 2>/dev/null && echo y)
139+
ifeq ($(LIBFDT_PKGCONFIG),y)
140+
LIBFDT_CFLAGS ?= `$(PKG_CONFIG) --cflags $(LIBFDT)`
141+
LIBFDT_LIBS ?= `$(PKG_CONFIG) --libs $(LIBFDT)`
142+
else
143+
LIBFDT_CFLAGS ?=
144+
LIBFDT_LIBS ?= -lfdt
145+
endif
146+
137147
ifeq ($(OS),Windows_NT)
138148
# Windows lacks mman.h / mmap()
139149
DEFAULT_CFLAGS += -DNO_MMAP
@@ -149,8 +159,8 @@ FEL_LIB := fel_lib.c fel_lib.h
149159
SPI_FLASH:= fel-spiflash.c fel-spiflash.h fel-remotefunc-spi-data-transfer.h
150160

151161
sunxi-fel: fel.c fit_image.c thunks/fel-to-spl-thunk.h $(PROGRESS) $(SOC_INFO) $(FEL_LIB) $(SPI_FLASH)
152-
$(CC) $(HOST_CFLAGS) $(LIBUSB_CFLAGS) $(ZLIB_CFLAGS) $(LDFLAGS) -o $@ \
153-
$(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS) $(ZLIB_LIBS) -lfdt
162+
$(CC) $(HOST_CFLAGS) $(LIBUSB_CFLAGS) $(ZLIB_CFLAGS) $(LIBFDT_CFLAGS) $(LDFLAGS) -o $@ \
163+
$(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS) $(ZLIB_LIBS) $(LIBFDT_LIBS)
154164

155165
sunxi-nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h
156166
$(CC) $(HOST_CFLAGS) -c -o nand-part-main.o nand-part-main.c

0 commit comments

Comments
 (0)