]> git.proxmox.com Git - mirror_qemu.git/blob - rules.mak
build: support linking with libtool objects/libraries
[mirror_qemu.git] / rules.mak
1
2 # Don't use implicit rules or variables
3 # we have explicit rules for everything
4 MAKEFLAGS += -rR
5
6 # Files with this suffixes are final, don't try to generate them
7 # using implicit rules
8 %.d:
9 %.h:
10 %.c:
11 %.m:
12 %.mak:
13
14 # Flags for dependency generation
15 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
16
17 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
18 QEMU_CFLAGS += -I$(<D) -I$(@D)
19
20 %.o: %.c
21 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
22
23 ifeq ($(LIBTOOL),)
24 %.lo: %.c
25 @echo "missing libtool. please install and rerun configure"; exit 1
26 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
27 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
28 $(LIBS)," LINK $(TARGET_DIR)$@")
29 else
30 LIBTOOL += $(if $(V),,--quiet)
31 %.lo: %.c
32 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
33 LINK = $(call quiet-command,\
34 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
35 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
36 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
37 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
38 endif
39
40 %.asm: %.S
41 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
42
43 %.o: %.asm
44 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
45
46 %.o: %.m
47 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
48
49 %$(EXESUF): %.o
50 $(call LINK,$^)
51
52 %.a:
53 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
54
55 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
56
57 # cc-option
58 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
59
60 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
61 >/dev/null 2>&1 && echo OK), $2, $3)
62
63 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
64 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
65
66 # find-in-path
67 # Usage: $(call find-in-path, prog)
68 # Looks in the PATH if the argument contains no slash, else only considers one
69 # specific directory. Returns an # empty string if the program doesn't exist
70 # there.
71 find-in-path = $(if $(find-string /, $1), \
72 $(wildcard $1), \
73 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
74
75 # Generate files with tracetool
76 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
77
78 # Generate timestamp files for .h include files
79
80 %.h: %.h-timestamp
81 @test -f $@ || cp $< $@
82
83 %.h-timestamp: %.mak
84 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)$*.h")
85 @cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h
86
87 # will delete the target of a rule if commands exit with a nonzero exit status
88 .DELETE_ON_ERROR:
89
90 # magic to descend into other directories
91
92 obj := .
93 old-nested-dirs :=
94
95 define push-var
96 $(eval save-$2-$1 = $(value $1))
97 $(eval $1 :=)
98 endef
99
100 define pop-var
101 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
102 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
103 $(eval save-$2-$1 :=)
104 endef
105
106 define unnest-dir
107 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
108 $(eval obj := $(obj)/$1)
109 $(eval include $(SRC_PATH)/$1/Makefile.objs)
110 $(eval obj := $(patsubst %/$1,%,$(obj)))
111 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
112 endef
113
114 define unnest-vars-1
115 $(eval nested-dirs := $(filter-out \
116 $(old-nested-dirs), \
117 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
118 $(if $(nested-dirs),
119 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
120 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
121 $(call unnest-vars-1))
122 endef
123
124 define unnest-vars
125 $(call unnest-vars-1)
126 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
127 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
128 $(foreach var,$(nested-vars), $(eval \
129 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
130 endef