xref: /openbmc/linux/tools/objtool/Makefile (revision 2e51f262)
1442f04c3SJosh Poimboeufinclude ../scripts/Makefile.include
2442f04c3SJosh Poimboeuf
3442f04c3SJosh Poimboeufifndef ($(ARCH))
4442f04c3SJosh PoimboeufARCH ?= $(shell uname -m)
5442f04c3SJosh Poimboeufifeq ($(ARCH),x86_64)
6442f04c3SJosh PoimboeufARCH := x86
7442f04c3SJosh Poimboeufendif
8442f04c3SJosh Poimboeufendif
9442f04c3SJosh Poimboeuf
10c1d45c3aSJosh Poimboeuf# always use the host compiler
11c1d45c3aSJosh PoimboeufCC = gcc
12c1d45c3aSJosh PoimboeufLD = ld
13c1d45c3aSJosh PoimboeufAR = ar
14c1d45c3aSJosh Poimboeuf
15442f04c3SJosh Poimboeufifeq ($(srctree),)
16442f04c3SJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(shell pwd)))
17442f04c3SJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree)))
18442f04c3SJosh Poimboeufendif
19442f04c3SJosh Poimboeuf
20442f04c3SJosh PoimboeufSUBCMD_SRCDIR		= $(srctree)/tools/lib/subcmd/
21c1d45c3aSJosh PoimboeufLIBSUBCMD_OUTPUT	= $(if $(OUTPUT),$(OUTPUT),$(PWD)/)
22c1d45c3aSJosh PoimboeufLIBSUBCMD		= $(LIBSUBCMD_OUTPUT)libsubcmd.a
23442f04c3SJosh Poimboeuf
24442f04c3SJosh PoimboeufOBJTOOL    := $(OUTPUT)objtool
25442f04c3SJosh PoimboeufOBJTOOL_IN := $(OBJTOOL)-in.o
26442f04c3SJosh Poimboeuf
27442f04c3SJosh Poimboeufall: $(OBJTOOL)
28442f04c3SJosh Poimboeuf
29442f04c3SJosh PoimboeufINCLUDES := -I$(srctree)/tools/include
30d435fb5eSJosh PoimboeufCFLAGS   += -Wall -Werror $(EXTRA_WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
31442f04c3SJosh PoimboeufLDFLAGS  += -lelf $(LIBSUBCMD)
32442f04c3SJosh Poimboeuf
332e51f262SJan Beulich# Allow old libelf to be used:
342e51f262SJan Beulichelfshdr := $(shell echo '\#include <libelf.h>' | $(CC) $(CFLAGS) -x c -E - | grep elf_getshdr)
352e51f262SJan BeulichCFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
362e51f262SJan Beulich
37442f04c3SJosh PoimboeufAWK = awk
38442f04c3SJosh Poimboeufexport srctree OUTPUT CFLAGS ARCH AWK
39442f04c3SJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include
40442f04c3SJosh Poimboeuf
41442f04c3SJosh Poimboeuf$(OBJTOOL_IN): fixdep FORCE
42442f04c3SJosh Poimboeuf	@$(MAKE) $(build)=objtool
43442f04c3SJosh Poimboeuf
44442f04c3SJosh Poimboeuf$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
45442f04c3SJosh Poimboeuf	@(test -d ../../kernel -a -d ../../tools -a -d ../objtool && (( \
46442f04c3SJosh Poimboeuf	diff -I'^#include' arch/x86/insn/insn.c ../../arch/x86/lib/insn.c >/dev/null && \
47442f04c3SJosh Poimboeuf	diff -I'^#include' arch/x86/insn/inat.c ../../arch/x86/lib/inat.c >/dev/null && \
48442f04c3SJosh Poimboeuf	diff arch/x86/insn/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \
49442f04c3SJosh Poimboeuf	diff arch/x86/insn/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \
50442f04c3SJosh Poimboeuf	diff -I'^#include' arch/x86/insn/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \
51442f04c3SJosh Poimboeuf	diff -I'^#include' arch/x86/insn/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \
52442f04c3SJosh Poimboeuf	diff -I'^#include' arch/x86/insn/inat_types.h ../../arch/x86/include/asm/inat_types.h >/dev/null) \
53442f04c3SJosh Poimboeuf	|| echo "Warning: objtool: x86 instruction decoder differs from kernel" >&2 )) || true
54442f04c3SJosh Poimboeuf	$(QUIET_LINK)$(CC) $(OBJTOOL_IN) $(LDFLAGS) -o $@
55442f04c3SJosh Poimboeuf
56442f04c3SJosh Poimboeuf
57442f04c3SJosh Poimboeuf$(LIBSUBCMD): fixdep FORCE
58c1d45c3aSJosh Poimboeuf	$(Q)$(MAKE) -C $(SUBCMD_SRCDIR) OUTPUT=$(LIBSUBCMD_OUTPUT)
59442f04c3SJosh Poimboeuf
60c1d45c3aSJosh Poimboeufclean:
61442f04c3SJosh Poimboeuf	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
62442f04c3SJosh Poimboeuf	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
63442f04c3SJosh Poimboeuf	$(Q)$(RM) $(OUTPUT)arch/x86/insn/inat-tables.c $(OUTPUT)fixdep
64442f04c3SJosh Poimboeuf
65442f04c3SJosh PoimboeufFORCE:
66442f04c3SJosh Poimboeuf
67442f04c3SJosh Poimboeuf.PHONY: clean FORCE
68