common.mak 4.01 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
%.o: %.m
	$(COMPILE_C)

57 58 59
%.s: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -S -o $@ $<

60
%.o: %.S
61
	$(COMPILE_S)
62

63 64 65
%_host.o: %.c
	$(COMPILE_HOSTC)

66
%.o: %.rc
67
	$(WINDRES) $(IFLAGS) --preprocessor "$(DEPWINDRES) -E -xc-header -DRC_INVOKED $(CC_DEPFLAGS)" -o $@ $<
68

69 70 71
%.i: %.c
	$(CC) $(CCFLAGS) $(CC_E) $<

72 73
%.h.c:
	$(Q)echo '#include "$*.h"' >$@
74 75 76 77 78 79

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

%.c %.h: TAG = GEN

80 81 82 83 84 85 86 87 88 89
# 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):
90 91
endif

92
include $(SRC_PATH)/arch.mak
93

Diego Biurrun's avatar
Diego Biurrun committed
94
OBJS      += $(OBJS-yes)
95
SLIBOBJS  += $(SLIBOBJS-yes)
96
FFLIBS    := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS)
Diego Biurrun's avatar
Diego Biurrun committed
97
TESTPROGS += $(TESTPROGS-yes)
98

99 100
LDLIBS       = $(FFLIBS:%=%$(BUILDSUF))
FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(EXTRALIBS)
101

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

113 114
PATH_LIBNAME = $(foreach NAME,$(1),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME))
DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib)))
115

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

124 125
alltools: $(TOOLS)

126
$(HOSTOBJS): %.o: %.c
127
	$(COMPILE_HOSTC)
128 129

$(HOSTPROGS): %$(HOSTEXESUF): %.o
130
	$(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $^ $(HOSTLIBS)
131

132
$(OBJS):     | $(sort $(dir $(OBJS)))
133
$(HOBJS):    | $(sort $(dir $(HOBJS)))
134
$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
135
$(SLIBOBJS): | $(sort $(dir $(SLIBOBJS)))
136 137
$(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
$(TOOLOBJS): | tools
138

139
OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(TESTOBJS))
140

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

Mans Rullgard's avatar
Mans Rullgard committed
145
define RULES
146 147
clean::
	$(RM) $(OBJS) $(OBJS:.o=.d)
Mans Rullgard's avatar
Mans Rullgard committed
148 149 150 151 152
	$(RM) $(HOSTPROGS)
	$(RM) $(TOOLS)
endef

$(eval $(RULES))
153

James Almer's avatar
James Almer committed
154
-include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d) $(SLIBOBJS:.o=.d))