Statistics
| Branch: | Revision:

root / rules.mak @ f141ccfa

History | View | Annotate | Download (3.8 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

    
23
ifeq ($(LIBTOOL),)
24
%.lo: %.c
25
	@echo "missing libtool. please install and rerun configure"; exit 1
26
else
27
LIBTOOL += $(if $(V),,--quiet)
28
%.lo: %.c
29
	$(call quiet-command,$(LIBTOOL) --mode=compile --tag=CC $(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  lt CC $@")
30
endif
31

    
32
%.asm: %.S
33
	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -o $@ $<,"  CPP   $(TARGET_DIR)$@")
34

    
35
%.o: %.asm
36
	$(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<,"  AS    $(TARGET_DIR)$@")
37

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

    
41
LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(LIBS),"  LINK  $(TARGET_DIR)$@")
42

    
43
%$(EXESUF): %.o
44
	$(call LINK,$^)
45

    
46
%.a:
47
	$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR    $(TARGET_DIR)$@")
48

    
49
quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
50

    
51
# cc-option
52
# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
53

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

    
57
VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi %.sh
58
set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
59

    
60
# find-in-path
61
# Usage: $(call find-in-path, prog)
62
# Looks in the PATH if the argument contains no slash, else only considers one
63
# specific directory.  Returns an # empty string if the program doesn't exist
64
# there.
65
find-in-path = $(if $(find-string /, $1), \
66
        $(wildcard $1), \
67
        $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
68

    
69
# Generate files with tracetool
70
TRACETOOL=$(PYTHON) $(SRC_PATH)/scripts/tracetool.py
71

    
72
# Generate timestamp files for .h include files
73

    
74
%.h: %.h-timestamp
75
	@test -f $@ || cp $< $@
76

    
77
%.h-timestamp: %.mak
78
	$(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, "  GEN   $(TARGET_DIR)$*.h")
79
	@cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h
80

    
81
# will delete the target of a rule if commands exit with a nonzero exit status
82
.DELETE_ON_ERROR:
83

    
84
# magic to descend into other directories
85

    
86
obj := .
87
old-nested-dirs :=
88

    
89
define push-var
90
$(eval save-$2-$1 = $(value $1))
91
$(eval $1 :=)
92
endef
93

    
94
define pop-var
95
$(eval subdir-$2-$1 := $(if $(filter $2,$(save-$2-$1)),$(addprefix $2,$($1))))
96
$(eval $1 = $(value save-$2-$1) $$(subdir-$2-$1))
97
$(eval save-$2-$1 :=)
98
endef
99

    
100
define unnest-dir
101
$(foreach var,$(nested-vars),$(call push-var,$(var),$1/))
102
$(eval obj := $(obj)/$1)
103
$(eval include $(SRC_PATH)/$1/Makefile.objs)
104
$(eval obj := $(patsubst %/$1,%,$(obj)))
105
$(foreach var,$(nested-vars),$(call pop-var,$(var),$1/))
106
endef
107

    
108
define unnest-vars-1
109
$(eval nested-dirs := $(filter-out \
110
    $(old-nested-dirs), \
111
    $(sort $(foreach var,$(nested-vars), $(filter %/, $($(var)))))))
112
$(if $(nested-dirs),
113
  $(foreach dir,$(nested-dirs),$(call unnest-dir,$(patsubst %/,%,$(dir))))
114
  $(eval old-nested-dirs := $(old-nested-dirs) $(nested-dirs))
115
  $(call unnest-vars-1))
116
endef
117

    
118
define unnest-vars
119
$(call unnest-vars-1)
120
$(foreach var,$(nested-vars),$(eval $(var) := $(filter-out %/, $($(var)))))
121
$(shell mkdir -p $(sort $(foreach var,$(nested-vars),$(dir $($(var))))))
122
$(foreach var,$(nested-vars), $(eval \
123
  -include $(addsuffix *.d, $(sort $(dir $($(var)))))))
124
endef