xref: /illumos-kvm-cmd/rules.mak (revision 1e9a8703)
1#
2# Copyright (c) 2019, Joyent, Inc.
3#
4
5# Don't use implicit rules or variables
6# we have explicit rules for everything
7MAKEFLAGS += -rR
8
9# Files with this suffixes are final, don't try to generate them
10# using implicit rules
11%.d:
12%.h:
13%.c:
14%.m:
15%.mak:
16
17# Flags for dependency generation
18QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
19
20%.o: %.c
21	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  CC    $(TARGET_DIR)$@")
22
23%.o: %.S
24	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  AS    $(TARGET_DIR)$@")
25
26%.o: %.m
27	$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  OBJC  $(TARGET_DIR)$@")
28
29LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(1) $(LIBS),"  LINK  $(TARGET_DIR)$@")
30
31#
32# Quite a few components are empty files or not compiled with CTF (such as
33# libpng).
34#
35CTFCONVERT_CMD = $(call quiet-command, $(CTFCONVERT) -m -L VERSION $@," CTFCONVERT  $(TARGET_DIR)$@")
36
37ifeq ($(TRACE_BACKEND),dtrace)
38ifneq ($(strip $(CONFIG_SOLARIS)),)
39%$(EXESUF): %.o
40	$(call quiet-command, dtrace $(CONFIG_DTRACE_FLAGS) -o trace-dtrace.o -s trace-dtrace.dtrace  -G $^,"  LINK  $(TARGET_DIR)$@.dtrace")
41	$(call LINK,$^ trace-dtrace.o)
42else
43%$(EXESUF): %.o
44	$(call LINK,$^)
45endif
46else
47%$(EXESUF): %.o
48	$(call LINK,$^)
49endif
50
51%.a:
52	$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^,"  AR    $(TARGET_DIR)$@")
53
54quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
55
56# cc-option
57# Usage: CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
58
59cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
60              >/dev/null 2>&1 && echo OK), $2, $3)
61
62VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.texi
63set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
64
65# find-in-path
66# Usage: $(call find-in-path, prog)
67# Looks in the PATH if the argument contains no slash, else only considers one
68# specific directory.  Returns an # empty string if the program doesn't exist
69# there.
70find-in-path = $(if $(find-string /, $1), \
71        $(wildcard $1), \
72        $(wildcard $(patsubst %, %/$1, $(subst :, ,$(PATH)))))
73
74# Generate timestamp files for .h include files
75
76%.h: %.h-timestamp
77	@test -f $@ || cp $< $@
78
79%.h-timestamp: %.mak
80	$(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, "  GEN   $*.h")
81	@cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h
82
83# will delete the target of a rule if commands exit with a nonzero exit status
84.DELETE_ON_ERROR:
85