tools lib lk: Fix for cross build
[platform/adaptation/renesas_rcar/renesas_kernel.git] / tools / lib / lk / Makefile
1 include ../../scripts/Makefile.include
2
3 CC = $(CROSS_COMPILE)gcc
4 AR = $(CROSS_COMPILE)ar
5
6 # Makefiles suck: This macro sets a default value of $(2) for the
7 # variable named by $(1), unless the variable has been set by
8 # environment or command line. This is necessary for CC and AR
9 # because make sets default values, so the simpler ?= approach
10 # won't work as expected.
11 define allow-override
12   $(if $(or $(findstring environment,$(origin $(1))),\
13             $(findstring command line,$(origin $(1)))),,\
14     $(eval $(1) = $(2)))
15 endef
16
17 # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
18 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
19 $(call allow-override,AR,$(CROSS_COMPILE)ar)
20
21 # guard against environment variables
22 LIB_H=
23 LIB_OBJS=
24
25 LIB_H += debugfs.h
26
27 LIB_OBJS += $(OUTPUT)debugfs.o
28
29 LIBFILE = liblk.a
30
31 CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
32 EXTLIBS = -lpthread -lrt -lelf -lm
33 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
34 ALL_LDFLAGS = $(LDFLAGS)
35
36 RM = rm -f
37
38 $(LIBFILE): $(LIB_OBJS)
39         $(QUIET_AR)$(RM) $@ && $(AR) rcs $(OUTPUT)$@ $(LIB_OBJS)
40
41 $(LIB_OBJS): $(LIB_H)
42
43 $(OUTPUT)%.o: %.c
44         $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
45 $(OUTPUT)%.s: %.c
46         $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
47 $(OUTPUT)%.o: %.S
48         $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
49
50 clean:
51         $(RM) $(LIB_OBJS) $(LIBFILE)
52
53 .PHONY: clean