common.mak 3.58 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 9 10 11 12
ifndef SUBDIR

ifndef V
Q      = @
ECHO   = printf "$(1)\t%s\n" $(2)
13
BRIEF  = CC CXX HOSTCC HOSTLD AS YASM AR LD STRIP CP
14 15
SILENT = DEPCC DEPHOSTCC DEPAS DEPYASM RANLIB RM

16 17 18 19 20 21 22 23
MSG    = $@
M      = @$(call ECHO,$(TAG),$@);
$(foreach VAR,$(BRIEF), \
    $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_DIR)/%=%)); $(INSTALL))
endif

24
ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil postproc swscale swresample
25

26
# NASM requires -I path terminated with /
27 28 29
IFLAGS     := -I. -I$(SRC_PATH)/
CPPFLAGS   := $(IFLAGS) $(CPPFLAGS)
CFLAGS     += $(ECFLAGS)
30 31
CCFLAGS     = $(CPPFLAGS) $(CFLAGS)
ASFLAGS    := $(CPPFLAGS) $(ASFLAGS)
32
CXXFLAGS   += $(CPPFLAGS) $(CFLAGS)
33
YASMFLAGS  += $(IFLAGS:%=%/) -Pconfig.asm
34

35
HOSTCCFLAGS = $(IFLAGS) $(HOSTCFLAGS)
36
LDFLAGS    := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS)
37

38
define COMPILE
39
       $(call $(1)DEP,$(1))
40
       $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $<
41 42 43
endef

COMPILE_C = $(call COMPILE,CC)
44
COMPILE_CXX = $(call COMPILE,CXX)
45 46
COMPILE_S = $(call COMPILE,AS)

47
%.o: %.c
48
	$(COMPILE_C)
49

50 51 52
%.o: %.cpp
	$(COMPILE_CXX)

53 54 55
%.s: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -S -o $@ $<

56
%.o: %.S
57
	$(COMPILE_S)
58

59 60 61
%.i: %.c
	$(CC) $(CCFLAGS) $(CC_E) $<

62 63
%.h.c:
	$(Q)echo '#include "$*.h"' >$@
64 65 66 67 68 69

%.ver: %.v
	$(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@

%.c %.h: TAG = GEN

70 71 72 73 74 75 76 77 78 79
# Dummy rule to stop make trying to rebuild removed or renamed headers
%.h:
	@:

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

# Do not delete intermediate files from chains of implicit rules
$(OBJS):
80 81
endif

82
include $(SRC_PATH)/arch.mak
83

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

88 89
LDLIBS       = $(FFLIBS:%=%$(BUILDSUF))
FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(EXTRALIBS)
90

91 92 93 94 95 96
EXAMPLES  := $(EXAMPLES:%=$(SUBDIR)%-example$(EXESUF))
OBJS      := $(sort $(OBJS:%=$(SUBDIR)%))
TESTOBJS  := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o)
TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF))
HOSTOBJS  := $(HOSTPROGS:%=$(SUBDIR)%.o)
HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF))
97 98 99
TOOLS     += $(TOOLS-yes)
TOOLOBJS  := $(TOOLS:%=tools/%.o)
TOOLS     := $(TOOLS:%=tools/%$(EXESUF))
100
HEADERS   += $(HEADERS-yes)
101

102
DEP_LIBS := $(foreach NAME,$(FFLIBS),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME))
103

104
ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
105 106
SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
107 108 109
HOBJS        = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o))
checkheaders: $(HOBJS)
.SECONDARY:   $(HOBJS:.o=.c)
110

111 112
alltools: $(TOOLS)

113
$(HOSTOBJS): %.o: %.c
114
	$(call COMPILE,HOSTCC)
115 116

$(HOSTPROGS): %$(HOSTEXESUF): %.o
117
	$(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $< $(HOSTLIBS)
118

119 120 121 122 123
$(OBJS):     | $(sort $(dir $(OBJS)))
$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
$(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
$(HOBJS):    | $(sort $(dir $(HOBJS)))
$(TOOLOBJS): | tools
124

125
OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS) $(HOBJS))
126

127
CLEANSUFFIXES     = *.d *.o *~ *.h.c *.map *.ver *.ho *.gcno *.gcda
128
DISTCLEANSUFFIXES = *.pc
129
LIBSUFFIXES       = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
130

131
define RULES
132 133
clean::
	$(RM) $(OBJS) $(OBJS:.o=.d)
134 135 136 137 138
	$(RM) $(HOSTPROGS)
	$(RM) $(TOOLS)
endef

$(eval $(RULES))
139

140
-include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d))