common.mak 2.69 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)
11

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

18 19
ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale

20 21
CFLAGS := -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
          -D_ISOC9X_SOURCE -I$(BUILD_ROOT_REL) -I$(SRC_PATH) $(OPTFLAGS)
22 23 24 25 26 27 28

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

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

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 50 51 52
SVN_ENTRIES = $(SRC_PATH_BARE)/.svn/entries
ifeq ($(wildcard $(SVN_ENTRIES)),$(SVN_ENTRIES))
$(BUILD_ROOT_REL)/version.h: $(SVN_ENTRIES)
endif

$(BUILD_ROOT_REL)/version.h:
	$(SRC_PATH)/version.sh $(SRC_PATH) $@

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

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

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

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

Måns Rullgård's avatar
Måns Rullgård committed
70 71
SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPP_OBJS:.o=.cpp)
OBJS := $(OBJS) $(ASM_OBJS) $(CPP_OBJS)
72

Måns Rullgård's avatar
Måns Rullgård committed
73 74 75
SRCS  := $(addprefix $(SUBDIR),$(SRCS))
OBJS  := $(addprefix $(SUBDIR),$(OBJS))
TESTS := $(addprefix $(SUBDIR),$(TESTS))
76

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

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

82 83
DEPS := $(OBJS:.o=.d)
depend dep: $(DEPS)
84

85
CLEANSUFFIXES = *.o *~ *.ho
86
LIBSUFFIXES   = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp *.map
87
DISTCLEANSUFFIXES = *.d *.pc
88

Måns Rullgård's avatar
Måns Rullgård committed
89
define RULES
90 91
$(SUBDIR)%$(EXESUF): $(SUBDIR)%.o
	$(CC) $(FFLDFLAGS) -o $$@ $$^ $(SUBDIR)$(LIBNAME) $(FFEXTRALIBS)
92

93 94 95 96 97
$(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
98

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

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

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

Måns Rullgård's avatar
Måns Rullgård committed
110
tests: $(TESTS)
111

112
-include $(DEPS)