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

Måns Rullgård's avatar
Måns Rullgård committed
5
all: # make "all" default target
6

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

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

19 20
ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale

21
CFLAGS := -DHAVE_AV_CONFIG_H -I$(BUILD_ROOT_REL) -I$(SRC_PATH) $(OPTFLAGS)
22 23 24 25 26

%.o: %.c
	$(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<

%.o: %.S
27
	$(AS) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
28

Måns Rullgård's avatar
Måns Rullgård committed
29 30 31
%.ho: %.h
	$(CC) $(CFLAGS) $(LIBOBJFLAGS) -Wno-unused -c -o $@ -x c $<

32 33 34 35 36 37 38 39 40
%.d: %.c
	$(DEPEND_CMD) > $@

%.d: %.S
	$(DEPEND_CMD) > $@

%.d: %.cpp
	$(DEPEND_CMD) > $@

41 42
%.o: %.d

Måns Rullgård's avatar
Måns Rullgård committed
43 44
%$(EXESUF): %.c

45 46 47 48 49
SVN_ENTRIES = $(SRC_PATH_BARE)/.svn/entries
ifeq ($(wildcard $(SVN_ENTRIES)),$(SVN_ENTRIES))
$(BUILD_ROOT_REL)/version.h: $(SVN_ENTRIES)
endif

50
$(BUILD_ROOT_REL)/version.h: $(SRC_PATH_BARE)/version.sh config.mak
51
	$< $(SRC_PATH) $@ $(EXTRA_VERSION)
52

Måns Rullgård's avatar
Måns Rullgård committed
53
install: install-libs install-headers
54

Måns Rullgård's avatar
Måns Rullgård committed
55
uninstall: uninstall-libs uninstall-headers
56

57
.PHONY: all depend dep *clean install* uninstall* examples testprogs
Måns Rullgård's avatar
Måns Rullgård committed
58
endif
59

Måns Rullgård's avatar
Måns Rullgård committed
60 61 62
CFLAGS   += $(CFLAGS-yes)
OBJS     += $(OBJS-yes)
FFLIBS   := $(FFLIBS-yes) $(FFLIBS)
63
TESTPROGS    += $(TESTPROGS-yes)
64

Måns Rullgård's avatar
Måns Rullgård committed
65 66
FFEXTRALIBS := $(addprefix -l,$(addsuffix $(BUILDSUF),$(FFLIBS))) $(EXTRALIBS)
FFLDFLAGS   := $(addprefix -L$(BUILD_ROOT)/lib,$(FFLIBS)) $(LDFLAGS)
67

68
EXAMPLES := $(addprefix $(SUBDIR),$(EXAMPLES))
Måns Rullgård's avatar
Måns Rullgård committed
69
OBJS  := $(addprefix $(SUBDIR),$(OBJS))
70
TESTPROGS := $(addprefix $(SUBDIR),$(TESTPROGS))
71

Måns Rullgård's avatar
Måns Rullgård committed
72 73
DEP_LIBS:=$(foreach NAME,$(FFLIBS),lib$(NAME)/$($(BUILD_SHARED:yes=S)LIBNAME))

74
ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
Måns Rullgård's avatar
Måns Rullgård committed
75
checkheaders: $(filter-out %_template.ho,$(ALLHEADERS:.h=.ho))
76

77 78
DEPS := $(OBJS:.o=.d)
depend dep: $(DEPS)
79

80
CLEANSUFFIXES = *.o *~ *.ho
81
LIBSUFFIXES   = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp *.map
82
DISTCLEANSUFFIXES = *.d *.pc
83

Måns Rullgård's avatar
Måns Rullgård committed
84
define RULES
85 86
$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
	$(CC) $(FFLDFLAGS) -o $$@ $$^ $(SUBDIR)$(LIBNAME) $(FFEXTRALIBS)
87

88 89 90 91 92
$(SUBDIR)%-test.o: $(SUBDIR)%.c
	$(CC) $(CFLAGS) -DTEST -c -o $$@ $$^

$(SUBDIR)%-test.o: $(SUBDIR)%-test.c
	$(CC) $(CFLAGS) -DTEST -c -o $$@ $$^
Diego Biurrun's avatar
Diego Biurrun committed
93

94
$(SUBDIR)x86/%.o: $(SUBDIR)x86/%.asm
Loren Merritt's avatar
Loren Merritt committed
95 96
	$(YASM) $(YASMFLAGS) -I $$(<D)/ -o $$@ $$<

97
$(SUBDIR)x86/%.d: $(SUBDIR)x86/%.asm
Loren Merritt's avatar
Loren Merritt committed
98 99
	$(YASM) $(YASMFLAGS) -I $$(<D)/ -M -o $$(@:%.d=%.o) $$< > $$@

Måns Rullgård's avatar
Måns Rullgård committed
100
clean::
101
	rm -f $(EXAMPLES) $(TESTPROGS) $(addprefix $(SUBDIR),$(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
102
	    $(addprefix $(SUBDIR), $(foreach suffix,$(CLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
Diego Biurrun's avatar
Diego Biurrun committed
103

Måns Rullgård's avatar
Måns Rullgård committed
104
distclean:: clean
105 106
	rm -f  $(addprefix $(SUBDIR),$(DISTCLEANSUFFIXES)) \
            $(addprefix $(SUBDIR), $(foreach suffix,$(DISTCLEANSUFFIXES),$(addsuffix /$(suffix),$(DIRS))))
Måns Rullgård's avatar
Måns Rullgård committed
107
endef
108

Måns Rullgård's avatar
Måns Rullgård committed
109
$(eval $(RULES))
110

111
examples: $(EXAMPLES)
112
testprogs: $(TESTPROGS)
113

114
-include $(DEPS)