build: move dtrace rules to rules.mak
[qemu/ar7.git] / rules.mak
blob5865e9ba93cd277104524b959f053b857b61d615
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 %.lo: %.c
25 @echo "missing libtool. please install and rerun configure"; exit 1
26 %.lo: %.dtrace
27 @echo "missing libtool. please install and rerun configure."; exit 1
29 LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
30 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
31 $(LIBS)," LINK $(TARGET_DIR)$@")
32 else
33 LIBTOOL += $(if $(V),,--quiet)
34 %.lo: %.c
35 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," lt CC $@")
36 %.lo: %.dtrace
37 $(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
39 LINK = $(call quiet-command,\
40 $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
41 )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
42 $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
43 $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", " LINK ")"$(TARGET_DIR)$@")
44 endif
46 %.asm: %.S
47 $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<," CPP $(TARGET_DIR)$@")
49 %.o: %.asm
50 $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@")
52 %.o: %.m
53 $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@")
55 %.o: %.dtrace
56 $(call quiet-command,dtrace -o $@ -G -s $<, " GEN $(TARGET_DIR)$@")
58 %$(EXESUF): %.o
59 $(call LINK,$^)
61 %.a:
62 $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@")
64 quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
66 # cc-option
67 # Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
69 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
70 >/dev/null 2>&1 && echo OK), $2, $3)
72 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
73 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
75 # find-in-path
76 # Usage: $(call find-in-path, prog)
77 # Looks in the PATH if the argument contains no slash, else only considers one
78 # specific directory. Returns an # empty string if the program doesn't exist
79 # there.
80 find-in-path = $(if $(find-string /, $1), \
81 $(wildcard $1), \
82 $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
84 # Generate files with tracetool
85 TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
87 # Generate timestamp files for .h include files
89 %.h: %.h-timestamp
90 @test -f $@ || cp $< $@
92 %.h-timestamp: %.mak
93 $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $(TARGET_DIR)$*.h")
94 @cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h
96 # will delete the target of a rule if commands exit with a nonzero exit status
97 .DELETE_ON_ERROR:
99 # magic to descend into other directories
101 obj := .
102 old-nested-dirs :=
104 define push-var
105 $(eval save-$2-$1 = $(value $1))
106 $(eval $1 :=)
107 endef
109 define pop-var
110 $(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
111 $(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
112 $(eval save-$2-$1 :=)
113 endef
115 define unnest-dir
116 $(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
117 $(eval obj := $(obj)/$1)
118 $(eval include $(SRC_PATH)/$1/Makefile.objs)
119 $(eval obj := $(patsubst %/$1,%,$(obj)))
120 $(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
121 endef
123 define unnest-vars-1
124 $(eval nested-dirs := $(filter-out \
125 $(old-nested-dirs), \
126 $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
127 $(if $(nested-dirs),
128 $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
129 $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
130 $(call unnest-vars-1))
131 endef
133 define unnest-vars
134 $(call unnest-vars-1)
135 $(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
136 $(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
137 $(foreach var,$(nested-vars), $(eval \
138 -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
139 endef