tmp105: Split out I2C message constants from header
[qemu/opensuse.git] / rules.mak
blob6d82c0d5a0a7332c076154b42678e96222c8d7b4
2 # Don't use implicit rules or variables
3 # we have explicit rules for everything
4 MAKEFLAGS += -rR
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:
14 # Flags for dependency generation
15 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
17 # Same as -I$(SRC_PATH) -I., but for the nested source/object directories
18 QEMU_CFLAGS += -I$(<D) -I$(@D)
20 %.o: %.c
21 $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CC $(TARGET_DIR)$@")
23 ifeq ($(LIBTOOL),)
24 LIBTOOL = /bin/false
25 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
26 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
27 $(LIBS)," LINK $(TARGET_DIR)$@")
28 else
29 LIBTOOL += $(if $(V),,--quiet)
30 %.lo: %.c
31 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
32 %.lo: %.dtrace
33 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
35 LINK = $(call quiet-command,\
36 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
37 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
38 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
39 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
40 endif
42 %.asm: %.S
43 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
45 %.o: %.asm
46 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
48 %.o: %.m
49 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
51 %.o: %.dtrace
52 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
54 %$(EXESUF): %.o
55 $(call LINK,$^)
57 %.a:
58 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
60 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
62 # cc-option
63 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
65 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
66 >/dev/null 2>&1 && echo OK), $2, $3)
68 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
69 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
71 # find-in-path
72 # Usage: $(call find-in-path, prog)
73 # Looks in the PATH if the argument contains no slash, else only considers one
74 # specific directory. Returns an # empty string if the program doesn't exist
75 # there.
76 find-in-path = $(if $(find-string /, $1), \
77 $(wildcard $1), \
78 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
80 # Generate files with tracetool
81 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
83 # Generate timestamp files for .h include files
85 %.h: %.h-timestamp
86 @test -f $@ || cp $< $@
88 %.h-timestamp: %.mak
89 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)$*.h")
90 @cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h
92 # will delete the target of a rule if commands exit with a nonzero exit status
93 .DELETE_ON_ERROR:
95 # magic to descend into other directories
97 obj := .
98 old-nested-dirs :=
100 define push-var
101 $(eval save-$2-$1 = $(value $1))
102 $(eval $1 :=)
103 endef
105 define pop-var
106 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
107 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
108 $(eval save-$2-$1 :=)
109 endef
111 define unnest-dir
112 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
113 $(eval obj := $(obj)/$1)
114 $(eval include $(SRC_PATH)/$1/Makefile.objs)
115 $(eval obj := $(patsubst %/$1,%,$(obj)))
116 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
117 endef
119 define unnest-vars-1
120 $(eval nested-dirs := $(filter-out \
121 $(old-nested-dirs), \
122 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
123 $(if $(nested-dirs),
124 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
125 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
126 $(call unnest-vars-1))
127 endef
129 define unnest-vars
130 $(call unnest-vars-1)
131 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
132 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
133 $(foreach var,$(nested-vars), $(eval \
134 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
135 endef