common.mak 3.97 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 WINDRES
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) $(HOSTCPPFLAGS) $(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
COMPILE_S = $(call COMPILE,AS)
46
COMPILE_HOSTC = $(call COMPILE,HOSTCC)
47

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

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

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

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

60 61 62
%_host.o: %.c
	$(COMPILE_HOSTC)

63
%.o: %.rc
64
	$(WINDRES) $(IFLAGS) --preprocessor "$(DEPWINDRES) -E -xc-header -DRC_INVOKED $(CC_DEPFLAGS)" -o $@ $<
65

66 67 68
%.i: %.c
	$(CC) $(CCFLAGS) $(CC_E) $<

69 70
%.h.c:
	$(Q)echo '#include "$*.h"' >$@
71 72 73 74 75 76

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

%.c %.h: TAG = GEN

77 78 79 80 81 82 83 84 85 86
# 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):
87 88
endif

89
include $(SRC_PATH)/arch.mak
90

Diego Biurrun's avatar
Diego Biurrun committed
91
OBJS      += $(OBJS-yes)
92
SLIBOBJS  += $(SLIBOBJS-yes)
Diego Biurrun's avatar
Diego Biurrun committed
93 94
FFLIBS    := $(FFLIBS-yes) $(FFLIBS)
TESTPROGS += $(TESTPROGS-yes)
95

96 97
LDLIBS       = $(FFLIBS:%=%$(BUILDSUF))
FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(EXTRALIBS)
98

99
OBJS      := $(sort $(OBJS:%=$(SUBDIR)%))
100
SLIBOBJS  := $(sort $(SLIBOBJS:%=$(SUBDIR)%))
101 102 103 104
TESTOBJS  := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o)
TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF))
HOSTOBJS  := $(HOSTPROGS:%=$(SUBDIR)%.o)
HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF))
105 106 107
TOOLS     += $(TOOLS-yes)
TOOLOBJS  := $(TOOLS:%=tools/%.o)
TOOLS     := $(TOOLS:%=tools/%$(EXESUF))
108
HEADERS   += $(HEADERS-yes)
109

110 111
PATH_LIBNAME = $(foreach NAME,$(1),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME))
DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib)))
112

113
SRC_DIR    := $(SRC_PATH)/lib$(NAME)
114
ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
115 116
SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
117 118 119
HOBJS        = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o))
checkheaders: $(HOBJS)
.SECONDARY:   $(HOBJS:.o=.c)
120

121 122
alltools: $(TOOLS)

123
$(HOSTOBJS): %.o: %.c
124
	$(COMPILE_HOSTC)
125 126

$(HOSTPROGS): %$(HOSTEXESUF): %.o
127
	$(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $^ $(HOSTLIBS)
128

129
$(OBJS):     | $(sort $(dir $(OBJS)))
130
$(HOBJS):    | $(sort $(dir $(HOBJS)))
131
$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
132
$(SLIBOBJS): | $(sort $(dir $(SLIBOBJS)))
133 134
$(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
$(TOOLOBJS): | tools
135

136
OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(TESTOBJS))
137

138
CLEANSUFFIXES     = *.d *.o *~ *.h.c *.map *.ver *.ho *.gcno *.gcda
139
DISTCLEANSUFFIXES = *.pc
140
LIBSUFFIXES       = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
141

142
define RULES
143 144
clean::
	$(RM) $(OBJS) $(OBJS:.o=.d)
145 146 147 148 149
	$(RM) $(HOSTPROGS)
	$(RM) $(TOOLS)
endef

$(eval $(RULES))
150

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