Statistics
| Branch: | Revision:

root / rules.mak @ 6821cdc7

History | View | Annotate | Download (4.7 kB)

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
%.o: %.rc
23
	$(call quiet-command,$(WINDRES) -I. -o $@ $<,"  RC    $(TARGET_DIR)$@")
24

    
25
ifeq ($(LIBTOOL),)
26
LIBTOOL = /bin/false
27
LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
28
       $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
29
       $(LIBS),"  LINK  $(TARGET_DIR)$@")
30
else
31
LIBTOOL += $(if $(V),,--quiet)
32
%.lo: %.c
33
	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  lt CC $@")
34
%.lo: %.rc
35
	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. -o $@ $<,"lt RC   $(TARGET_DIR)$@")
36
%.lo: %.dtrace
37
	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC dtrace -o $@ -G -s $<, " lt GEN $(TARGET_DIR)$@")
38

    
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
       $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
44
       $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
45
       $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", "  LINK  ")"$(TARGET_DIR)$@")
46
endif
47

    
48
%.asm: %.S
49
	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<,"  CPP   $(TARGET_DIR)$@")
50

    
51
%.o: %.asm
52
	$(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<,"  AS    $(TARGET_DIR)$@")
53

    
54
%.o: %.m
55
	$(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  OBJC  $(TARGET_DIR)$@")
56

    
57
%.o: %.dtrace
58
	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN   $(TARGET_DIR)$@")
59

    
60
%$(EXESUF): %.o
61
	$(call LINK,$^)
62

    
63
%.a:
64
	$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR    $(TARGET_DIR)$@")
65

    
66
quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
67

    
68
# cc-option
69
# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
70

    
71
cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
72
              >/dev/null 2>&1 && echo OK), $2, $3)
73

    
74
VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
75
set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
76

    
77
# find-in-path
78
# Usage: $(call find-in-path, prog)
79
# Looks in the PATH if the argument contains no slash, else only considers one
80
# specific directory.  Returns an # empty string if the program doesn't exist
81
# there.
82
find-in-path = $(if $(find-string /, $1), \
83
        $(wildcard $1), \
84
        $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
85

    
86
# Generate files with tracetool
87
TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
88

    
89
# Generate timestamp files for .h include files
90

    
91
config-%.h: config-%.h-timestamp
92
	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
93

    
94
config-%.h-timestamp: config-%.mak
95
	$(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, "  GEN   $(TARGET_DIR)config-$*.h")
96

    
97
.PHONY: clean-timestamp
98
clean-timestamp:
99
	rm -f *.timestamp
100
clean: clean-timestamp
101

    
102
# will delete the target of a rule if commands exit with a nonzero exit status
103
.DELETE_ON_ERROR:
104

    
105
# magic to descend into other directories
106

    
107
obj := .
108
old-nested-dirs :=
109

    
110
define push-var
111
$(eval save-$2-$1 = $(value $1))
112
$(eval $1 :=)
113
endef
114

    
115
define pop-var
116
$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
117
$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
118
$(eval save-$2-$1 :=)
119
endef
120

    
121
define unnest-dir
122
$(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
123
$(eval obj := $(obj)/$1)
124
$(eval include $(SRC_PATH)/$1/Makefile.objs)
125
$(eval obj := $(patsubst %/$1,%,$(obj)))
126
$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
127
endef
128

    
129
define unnest-vars-1
130
$(eval nested-dirs := $(filter-out \
131
    $(old-nested-dirs), \
132
    $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
133
$(if $(nested-dirs),
134
  $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
135
  $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
136
  $(call unnest-vars-1))
137
endef
138

    
139
define unnest-vars
140
$(call unnest-vars-1)
141
$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
142
$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
143
$(foreach var,$(nested-vars), $(eval \
144
  -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
145
endef