-
Notifications
You must be signed in to change notification settings - Fork 161
/
Makefile
128 lines (99 loc) · 4.34 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Configure file directories
BIN_DIR=bin
SRC_DIR=src
INCLUDE_DIR=include
EXAMPLES_DIR=examples
EXAMPLES_FFMPEG_DIR=$(EXAMPLES_DIR)/ffmpeg
BIN_EXAMPLES_DIR=$(BIN_DIR)/$(EXAMPLES_DIR)
BIN_EXAMPLES_FFMPEG_DIR=$(BIN_EXAMPLES_DIR)/ffmpeg
# use pkg-config for getting CFLAGS and LDLIBS
FFMPEG_LIBS=libavcodec \
libavformat \
libavutil \
libswscale \
libswresample
CFLAGS += -Wall -g -I$(INCLUDE_DIR)/
CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
COMPILE=$(CC) $(CFLAGS) -c $^ -o $@
LINK_EXE=$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)
# Create lists of src and object files for src dir
SRC_FILES=$(wildcard $(SRC_DIR)/*.c) # Get .c files in source
SRC_OBJS=$(patsubst $(SRC_DIR)/%.c,$(BIN_DIR)/%.o, $(SRC_FILES)) # Get name of .o files in source
EXAMPLES_FILES=$(wildcard $(EXAMPLES_DIR)/*.c)
EXAMPLES_OBJS=$(patsubst $(EXAMPLES_DIR)/%.c,$(BIN_EXAMPLES_DIR)/%.o, $(EXAMPLES_FILES))
EXAMPLES_EXES=$(patsubst %.o,%, $(EXAMPLES_OBJS))
EXAMPLES_TARGETS=$(patsubst $(EXAMPLES_DIR)/%.c,$(BIN_EXAMPLES_DIR)/%, $(EXAMPLES_FILES))
# Create lists of src, object and exe files for examples dir
EXAMPLES_FFMPEG_FILES=$(wildcard $(EXAMPLES_FFMPEG_DIR)/*.c)
EXAMPLES_FFMPEG_OBJS=$(patsubst $(EXAMPLES_FFMPEG_DIR)/%.c,$(BIN_EXAMPLES_FFMPEG_DIR)/%.o, $(EXAMPLES_FFMPEG_FILES))
EXAMPLES_FFMPEG_EXES=$(patsubst $(EXAMPLES_FFMPEG_DIR)/%.c,$(BIN_EXAMPLES_FFMPEG_DIR)/%, $(EXAMPLES_FFMPEG_FILES))
# Create bin directories if they dont exist
$(shell if [ ! -d "${BIN_EXAMPLES_FFMPEG_DIR}" ]; then mkdir -p ${BIN_EXAMPLES_FFMPEG_DIR}; fi;)
# Create src object files
$(BIN_DIR)/%.o: $(SRC_DIR)/%.c
$(COMPILE)
# Create examples object files
$(BIN_EXAMPLES_DIR)/%.o: $(EXAMPLES_DIR)/%.c
$(COMPILE)
# Create examples-ffmpeg object files
$(BIN_EXAMPLES_FFMPEG_DIR)/%.o: $(EXAMPLES_FFMPEG_DIR)/%.c
$(COMPILE)
# A phony target is one that is not really the name of a file;
# rather it is just a name for a recipe to be executed when you make an explicit request
# All targets that generate files should have target name = name of file
# so that make can correctly track if we need to rebuild the target
.phony: all src examples clean clean-src clean-examples-ffmpeg clean-examples
all: src examples-ffmpeg examples
src: $(SRC_OBJS)
examples: $(EXAMPLES_TARGETS)
# The only reason we can automatically create executables is that we are
# linking ffmpeg libs.. which contain all necessary object files.
# Maybe I'll do this in the future for my own examples once I have my own library
examples-ffmpeg: $(EXAMPLES_FFMPEG_OBJS) $(EXAMPLES_FFMPEG_EXES)
clean-examples:
$(RM) $(EXAMPLES_EXES) $(EXAMPLES_OBJS)
clean-examples-ffmpeg:
$(RM) $(EXAMPLES_FFMPEG_EXES) $(EXAMPLES_FFMPEG_OBJS)
clean-src:
$(RM) $(SRC_OBJS)
clean:
rm -rf $(BIN_DIR)/*
# Create executables!
# For new exe's follow this format:
# OBJS_BASE are the object files that the executable needs to run
# Must change target name to $(DBE){name of exe}
DBE=$(BIN_EXAMPLES_DIR)/
.SECONDEXPANSION:
OBJS_BASE=VideoContext Timebase Clip
$(DBE)test-clip: $$(call EXE_OBJS,$$@,$(OBJS_BASE))
$(LINK_EXE)
OBJS_BASE=Sequence Clip LinkedListAPI VideoContext Timebase OutputContext \
SequenceEncode SequenceDecode ClipDecode Util
$(DBE)test-sequence: $$(call EXE_OBJS,$$@,$(OBJS_BASE))
$(LINK_EXE)
OBJS_BASE=VideoContext Timebase Clip ClipDecode
$(DBE)test-clip-decode: $$(call EXE_OBJS,$$@,$(OBJS_BASE))
$(LINK_EXE)
OBJS_BASE=VideoContext Timebase Clip ClipDecode Sequence LinkedListAPI \
SequenceDecode Util
$(DBE)test-sequence-decode: $$(call EXE_OBJS,$$@,$(OBJS_BASE))
$(LINK_EXE)
OBJS_BASE=VideoContext Clip ClipDecode ClipEncode OutputContext Timebase \
Sequence LinkedListAPI SequenceEncode SequenceDecode Util
$(DBE)test-clip-encode: $$(call EXE_OBJS,$$@,$(OBJS_BASE))
$(LINK_EXE)
OBJS_BASE= VideoContext Clip ClipDecode OutputContext Timebase \
Sequence LinkedListAPI SequenceEncode SequenceDecode \
Util
$(DBE)test-sequence-encode: $$(call EXE_OBJS,$$@,$(OBJS_BASE))
$(LINK_EXE)
OBJS_BASE=Sequence LinkedListAPI Clip Util VideoContext Timebase \
OutputContext SequenceEncode SequenceDecode ClipDecode
$(DBE)random-splice: $$(call EXE_OBJS,$$@,$(OBJS_BASE))
$(LINK_EXE)
# $(1) = name of exe
# $(2) = the list of basename object files that the executable needs to run, without .o
define EXE_OBJS
$(patsubst %, %.o, $(1)) $(patsubst %, $(BIN_DIR)/%.o, $(2))
endef