common.mak 3.15 KB
Newer Older
1 2 3 4
#
# common bits used by all libraries
#

5 6
# first so "all" becomes default target
all: all-yes
7

8
ifndef SUBDIR
Diego Biurrun's avatar
Diego Biurrun committed
9 10 11
vpath %.c   $(SRC_DIR)
vpath %.h   $(SRC_DIR)
vpath %.S   $(SRC_DIR)
Loren Merritt's avatar
Loren Merritt committed
12
vpath %.asm $(SRC_DIR)
13
vpath %.v   $(SRC_DIR)
14

15 16 17 18 19 20
ifeq ($(SRC_DIR),$(SRC_PATH_BARE))
BUILD_ROOT_REL = .
else
BUILD_ROOT_REL = ..
endif

Måns Rullgård's avatar
Måns Rullgård committed
21 22 23
ifndef V
Q      = @
ECHO   = printf "$(1)\t%s\n" $(2)
24
BRIEF  = CC AS YASM AR LD HOSTCC
25
SILENT = DEPCC YASMDEP RM RANLIB
Måns Rullgård's avatar
Måns Rullgård committed
26
MSG    = $@
27
M      = @$(call ECHO,$(TAG),$@);
Måns Rullgård's avatar
Måns Rullgård committed
28
$(foreach VAR,$(BRIEF), \
29 30
    $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
Måns Rullgård's avatar
Måns Rullgård committed
31 32 33
$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_DIR)/%=%)); $(INSTALL))
endif

34
ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale
35

36 37
IFLAGS   := -I$(BUILD_ROOT_REL) -I$(SRC_PATH)
CPPFLAGS := $(IFLAGS) $(CPPFLAGS)
38
CFLAGS   += $(ECFLAGS)
39
YASMFLAGS += $(IFLAGS) -Pconfig.asm
40

41 42
HOSTCFLAGS += $(IFLAGS)

43
%.o: %.c
44
	$(CCDEP)
45
	$(CC) $(CPPFLAGS) $(CFLAGS) $(CC_DEPFLAGS) -c $(CC_O) $<
46 47

%.o: %.S
48
	$(ASDEP)
49
	$(AS) $(CPPFLAGS) $(ASFLAGS) $(AS_DEPFLAGS) -c -o $@ $<
50

51
%.ho: %.h
52
	$(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused -c -o $@ -x c $<
53

54 55
%$(EXESUF): %.c

56
%.ver: %.v
Måns Rullgård's avatar
Måns Rullgård committed
57
	$(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
58

59
%.c %.h: TAG = GEN
60

61 62 63 64
# Dummy rule to stop make trying to rebuild removed or renamed headers
%.h:
	@:

65
install: install-libs install-headers
66
install-libs: install-libs-yes
67

68 69 70
uninstall: uninstall-libs uninstall-headers

.PHONY: all depend dep *clean install* uninstall* examples testprogs
Måns Rullgård's avatar
Måns Rullgård committed
71 72 73 74

# Disable suffix rules.  Most of the builtin rules are suffix rules,
# so this saves some time on slow systems.
.SUFFIXES:
75 76

# Do not delete intermediate files from chains of implicit rules
77
$(OBJS):
78
endif
79

80 81
OBJS-$(HAVE_MMX) +=  $(MMX-OBJS-yes)

82
CFLAGS    += $(CFLAGS-yes)
Diego Biurrun's avatar
Diego Biurrun committed
83 84 85
OBJS      += $(OBJS-yes)
FFLIBS    := $(FFLIBS-yes) $(FFLIBS)
TESTPROGS += $(TESTPROGS-yes)
86

87
FFEXTRALIBS := $(addprefix -l,$(addsuffix $(BUILDSUF),$(FFLIBS))) $(EXTRALIBS)
88
FFLDFLAGS   := $(addprefix -L$(BUILD_ROOT)/lib,$(ALLFFLIBS)) $(LDFLAGS)
89

90
EXAMPLES  := $(addprefix $(SUBDIR),$(addsuffix -example$(EXESUF),$(EXAMPLES)))
91
OBJS      := $(addprefix $(SUBDIR),$(sort $(OBJS)))
92
TESTOBJS  := $(addprefix $(SUBDIR),$(TESTOBJS) $(TESTPROGS:%=%-test.o))
93
TESTPROGS := $(addprefix $(SUBDIR),$(addsuffix -test$(EXESUF),$(TESTPROGS)))
94 95
HOSTOBJS  := $(addprefix $(SUBDIR),$(addsuffix .o,$(HOSTPROGS)))
HOSTPROGS := $(addprefix $(SUBDIR),$(addsuffix $(HOSTEXESUF),$(HOSTPROGS)))
96

97
DEP_LIBS := $(foreach NAME,$(FFLIBS),$(BUILD_ROOT_REL)/lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME))
98

99
ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
100
SKIPHEADERS += $(addprefix $(ARCH)/,$(ARCH_HEADERS))
101
SKIPHEADERS := $(addprefix $(SUBDIR),$(SKIPHEADERS-) $(SKIPHEADERS))
102
checkheaders: $(filter-out $(SKIPHEADERS:.h=.ho),$(ALLHEADERS:.h=.ho))
103

104 105 106 107 108 109
$(HOSTOBJS): %.o: %.c
	$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<

$(HOSTPROGS): %$(HOSTEXESUF): %.o
	$(HOSTCC) $(HOSTLDFLAGS) -o $@ $< $(HOSTLIBS)

110
CLEANSUFFIXES     = *.d *.o *~ *.ho *.map *.ver
111
DISTCLEANSUFFIXES = *.pc
112
LIBSUFFIXES       = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp
113

114
-include $(wildcard $(OBJS:.o=.d) $(TESTOBJS:.o=.d))