app cleanups
[sparrow.git] / Makefile
blob6d4191cf32e8cf79a5c65039feeb4843a138b618
1 all::
3 #CFLAGS =
4 #LDFLAGS =
5 DEFINES = -DDSFMT_MEXP=19937
6 WARNINGS = -Wall -Wextra -Wno-unused-parameter
8 ARCH = $(shell arch)
9 ifeq "$(ARCH)" "x86_64"
10 ARCH_CFLAGS = -fPIC -DPIC -m64
11 JPEG_LIBRARY_PATH=/opt/libjpeg-turbo/lib
12 JPEG_STATIC=
13 JPEG_LINKS = -ljpeg
14 else
15 ARCH_CFLAGS = -m32 -msse2
16 JPEG_LIBRARY_PATH=/opt/libjpeg-turbo/lib32
17 JPEG_STATIC=$(JPEG_LIBRARY_PATH)/libjpeg.a
18 JPEG_LINKS = -L$(JPEG_LIBRARY_PATH) -Wl,-Bstatic -ljpeg -Wl,-Bdynamic
19 endif
20 JPEG_CPATH = /opt/libjpeg-turbo/include
21 CPATH = $(JPEG_CPATH)
22 LD_LIBRARY_PATH = $(JPEG_LIBRARY_PATH):$(LD_LIBRARY_PATH)
25 ALL_CFLAGS = -march=native -pthread $(VECTOR_FLAGS) -O3 $(WARNINGS) -pipe -D_GNU_SOURCE -DDSFMT_MEXP=19937 -std=gnu99 $(INCLUDES) $(ARCH_CFLAGS) $(CFLAGS)
26 ALL_LDFLAGS = $(LDFLAGS)
29 DSFMT_FLAGS = -finline-functions -fomit-frame-pointer -DNDEBUG -fno-strict-aliasing --param max-inline-insns-single=1800 -Wmissing-prototypes -std=c99
31 VECTOR_FLAGS = -msse2 -DHAVE_SSE2 -D__SSE2__ -floop-strip-mine -floop-block
33 # these *might* do something useful
34 # -fvisibility=hidden
35 #POSSIBLE_OPTIMISING_CFLAGS = -fmodulo-sched -fmodulo-sched-allow-regmoves -fgcse-sm -fgcse-las \
36 # -funsafe-loop-optimizations -Wunsafe-loop-optimizations -fsee -funsafe-math-optimizations and more
37 # "-combine -fwhole-program" with __attribute__((externally_visible))
38 # -fprofile-arcs and -fbranch-probabilities
39 #POSSIBLE_PESSIMISING_CFLAGS -fmudflap -fmudflapth -fmudflapir
41 SPARROW_SRC = gstsparrow.c dSFMT/dSFMT.c sparrow.c
43 CC = gcc
44 AR = ar
45 INSTALL = install
47 export GST_DEBUG = sparrow:4
48 #export GST_PLUGIN_PATH = .
50 OPENCV_PREFIX = $(shell test -d /usr/local/include/opencv && echo /usr/local || echo /usr )
52 #OPENCV_INCLUDE = -I/usr/include/opencv/
53 OPENCV_INCLUDE = -isystem $(OPENCV_PREFIX)/include/opencv/
55 GTK_INCLUDES = -I/usr/include/gtk-2.0/ -I/usr/include/cairo/ -I/usr/include/pango-1.0/ -I/usr/lib/gtk-2.0/include/ -I/usr/include/atk-1.0/
57 #GST_PLUGIN_LDFLAGS = -module -avoid-version -export-symbols-regex '_*\(gst_\|Gst\|GST_\).*'
58 GST_INCLUDES = -I/usr/include/gstreamer-0.10 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libxml2
59 INCLUDES = -I. $(GST_INCLUDES) -I/usr/include/liboil-0.3 $(OPENCV_INCLUDE) -I$(JPEG_CPATH)
62 # -L$(JPEG_LIBRARY_PATH) -Wl,-Bstatic -ljpeg -Wl,-Bdynamic
63 #or, to use dynamic linking, allegedly, -R $(JPEG_LIBRARY_PATH)
64 # or just put in the list of linkees $(JPEG_LIBRARY_PATH)/libjpeg.a
65 # or symlink /usr/lib/libjpeg* to /opt/..
68 LINKS = -L/usr/local/lib -lgstbase-0.10 -lgstreamer-0.10 -lgobject-2.0 \
69 -lglib-2.0 -lgstvideo-0.10 -lcxcore -lcv $(JPEG_LINKS)
70 # -lgstcontroller-0.10 -lgmodule-2.0 -lgthread-2.0 -lrt -lxml2 -lcv -lcvaux -lhighgui
72 SOURCES = gstsparrow.c sparrow.c calibrate.c play.c floodfill.c edges.c dSFMT/dSFMT.c jpeg_src.c load_images.c
73 OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
75 all:: libgstsparrow.so
77 libgstsparrow.so: $(OBJECTS) $(JPEG_STATIC)
78 $(CC) -shared -Wl,-O1 $+ $(GST_PLUGIN_LDFLAGS) $(INCLUDES) $(DEFINES) $(LINKS) -Wl,-soname -Wl,$@ \
79 -o $@
81 clean:
82 rm -f *.so *.o *.a *.d *.s
83 cd dSFMT && rm -f *.o *.s
84 rm -f sparrow_false_colour_lut.h
86 dSFMT/dSFMT.o: dSFMT/dSFMT.c
87 $(CC) $(DSFMT_FLAGS) -MD $(ALL_CFLAGS) -fvisibility=hidden $(CPPFLAGS) -c -o $@ $<
89 .c.o:
90 # @echo $(CPATH)
91 # @echo $(LIBRARY_PATH)
92 $(CC) -c -MD $(ALL_CFLAGS) $(CPPFLAGS) -o $@ $<
93 # $(CC) -c $(ALL_CFLAGS) $(CPPFLAGS) -MD $<
95 %.s: %.c
96 $(CC) -S $(ALL_CFLAGS) $(CPPFLAGS) -o $@ $<
98 %.i: %.c
99 $(CC) -E $(ALL_CFLAGS) $(CPPFLAGS) -o $@ $<
101 sparrow_false_colour_lut.h: false_colour.py
102 python $< > $@
104 gstsparrow.c: gstsparrow.h sparrow_false_colour_lut.h sparrow.h
106 sparrow.c: gstsparrow.h sparrow_false_colour_lut.h sparrow.h
108 GST_LAUNCH = gst-launch-0.10
109 DEBUG_LEVEL = 5
110 TEST_GST_ARGS = --gst-plugin-path=. --gst-debug=sparrow:$(DEBUG_LEVEL)
111 #TEST_INPUT_SIZE = width=320,height=240
112 #TEST_OUTPUT_SIZE = width=320,height=240
113 TEST_FPS=20
114 TEST_INPUT_SIZE = width=800,height=600
115 TEST_OUTPUT_SIZE = width=800,height=600
117 TEST_V4L2_SHAPE = 'video/x-raw-yuv,format=(fourcc)YUY2,$(TEST_INPUT_SIZE),framerate=$(TEST_FPS)/1'
118 TEST_OUTPUT_SHAPE = 'video/x-raw-rgb,$(TEST_OUTPUT_SIZE),framerate=$(TEST_FPS)/1'
119 TEST_SINK = ximagesink
120 #TEST_SINK = fbdevsink
121 TEST_PIPE_TAIL = ffmpegcolorspace ! sparrow $(TEST_OPTIONS) ! $(TEST_OUTPUT_SHAPE) ! $(TEST_SINK)
122 TEST_V4L2_PIPE_TAIL = $(TEST_V4L2_SHAPE) ! $(TEST_PIPE_TAIL)
124 test: all
125 $(GST_LAUNCH) $(TEST_GST_ARGS) v4l2src ! $(TEST_V4L2_PIPE_TAIL)
127 test-capture: all
128 $(GST_LAUNCH) $(TEST_GST_ARGS) v4l2src ! ffmpegcolorspace ! tee name=vid2 \
129 ! queue ! sparrow $(TEST_OPTIONS) ! $(TEST_OUTPUT_SHAPE) ! $(TEST_SINK) \
130 vid2. ! queue ! ffmpegcolorspace ! theoraenc ! oggmux ! filesink location='/tmp/sparrow.ogv'
131 # ! jpegenc ! avimux ! filesink location=mjpeg.avi
132 #jpegenc quality=85
134 test-gtk: all
135 GST_DEBUG=sparrow:$(DEBUG_LEVEL) ./gtk-app 2> /tmp/gst.log || less -R /tmp/gst.log
137 test-valgrind: debug
138 valgrind --log-file=valgrind.log --trace-children=yes --suppressions=valgrind-python.supp \
139 $(GST_LAUNCH) $(TEST_GST_ARGS) v4l2src ! $(TEST_V4L2_PIPE_TAIL) 2> gst.log
141 test-gdb: debug
142 echo "set args $(TEST_GST_ARGS) v4l2src ! $(TEST_V4L2_PIPE_TAIL)" > /tmp/gdb-args.txt
143 gdb -x /tmp/gdb-args.txt $(GST_LAUNCH)
145 test-times: all
146 timeout -3 20 time -v $(GST_LAUNCH) $(TEST_GST_ARGS) v4l2src ! $(TEST_V4L2_PIPE_TAIL)
148 test-cam:
149 $(GST_LAUNCH) $(TEST_GST_ARGS) v4l2src ! $(TEST_V4L2_PIPE_TAIL)
151 test-pattern: all
152 GST_DEBUG=sparrow:5 \
153 $(GST_LAUNCH) $(TEST_GST_ARGS) videotestsrc ! $(TEST_V4L2_PIPE_TAIL)
155 TEST_VIDEO_FILE=/home/douglas/media/video/rochester-pal.avi
156 #TEST_VIDEO_FILE=/home/douglas/tv/newartland_2008_ep2_ps6313_part3.flv
158 test-file: all
159 $(GST_LAUNCH) $(TEST_GST_ARGS) \
160 filesrc location=$(TEST_VIDEO_FILE) ! decodebin2 ! $(TEST_PIPE_TAIL)
162 inspect: all
163 gst-inspect $(TEST_GST_ARGS) sparrow $(TEST_OPTIONS)
166 #show filtered and unfiltered video side by side
167 test-tee: all
168 $(GST_LAUNCH) $(TEST_GST_ARGS) v4l2src ! ffmpegcolorspace ! tee name=vid2 \
169 ! queue ! sparrow $(TEST_OPTIONS) ! $(TEST_OUTPUT_SHAPE) ! $(TEST_SINK) \
170 vid2. ! queue ! sparrow $(TEST_OPTIONS) ! $(TEST_OUTPUT_SHAPE) ! $(TEST_SINK)
173 TAGS:
174 $(RM) TAGS
175 # find -name "*.[ch]" | xargs etags -a
176 etags -R --exclude=junk --exclude=.git --exclude=prof
178 cscope:
179 $(RM) cscope.out
180 cscope -b $(shell echo "$(INCLUDES)" | sed s/-isystem/-I/)
183 CPROTO_INCLUDES = $(shell echo "$(INCLUDES)" | sed s/-isystem/-I/)
185 cproto:
186 # cproto $(INCLUDES) -DUNUSED='' -S -i -X 0 *.c
187 cproto $(CPROTO_INCLUDES) -DUNUSED='' $(DEFINES) -S -X 0 *.c
189 cproto-nonstatic:
190 cproto $(CPROTO_INCLUDES) -DUNUSED='' $(DEFINES) -X 0 *.c
193 #oprofile: all
194 # sudo opcontrol --no-vmlinux $(OP_OPTS) && sudo opcontrol $(OP_OPTS) --start --verbose
195 # timeout -3 10 $(GST_LAUNCH) $(TEST_GST_ARGS) v4l2src ! $(TEST_V4L2_SHAPE) ! ffmpegcolorspace \
196 # ! sparrow $(TEST_OPTIONS) ! $(TEST_OUTPUT_SHAPE) ! $(TEST_SINK)
197 # opreport $(OP_OPTS)
199 sysprof: debug
200 lsmod | grep -q 'sysprof_module' || sudo modprobe sysprof-module || \
201 echo "try again after 'sudo m-a a-i sysprof-module-source'"
202 sysprof &
203 @echo "click the start button!"
205 splint:
206 splint $(INCLUDES) sparrow.c
207 flawfinder $(PWD)
210 unittest:
211 $(CC) -MD $(ALL_CFLAGS) $(CPPFLAGS) -o test test.c
212 ./test
214 unittest-shifts:
215 $(CC) -MD $(ALL_CFLAGS) $(CPPFLAGS) -o test shift_test.c
216 ./test
218 CV_LINKS = -lcv -lcvaux -lhighgui
220 unittest-edges:
221 $(CC) -MD $(ALL_CFLAGS) $(CPPFLAGS) $(CV_LINKS) -o test test-find-edge.c
222 ./test
224 unittest-median:
225 $(CC) -MD $(ALL_CFLAGS) $(CPPFLAGS) $(CV_LINKS) -o test test-median.c
226 ./test
228 unittest-jpeg: gstsparrow.o sparrow.o calibrate.o play.o floodfill.o edges.o dSFMT/dSFMT.o jpeg_src.o
229 $(CC) -MD $(ALL_CFLAGS) $(CPPFLAGS) $(LINKS) -o test $^ $(JPEG_STATIC) test-jpeg.c
231 # ./test
233 debug:
234 make -B CFLAGS='-g -fno-inline -fno-inline-functions -fno-omit-frame-pointer'
236 #ccmalloc
237 ccmalloc:
238 make -B CFLAGS='-lccmalloc -g' CC='ccmalloc --nowrapper gcc'
240 rsync:
241 rsync -t $(shell git ls-tree -r --name-only HEAD) 10.42.43.10:sparrow
244 .PHONY: TAGS all cproto cproto-nonstatic sysprof splint unittest unittest-shifts unittest-edges \
245 debug ccmalloc rsync app-clean
247 GTK_APP = gtk-app.c
248 GTK_LINKS = -lglib-2.0 $(LINKS) -lgstinterfaces-0.10
249 CLUTTER_INCLUDES = -I/usr/include/clutter-1.0/ -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/ -I/usr/include/pango-1.0/ -I/usr/include/cairo/ -I/usr/include/gstreamer-0.10/ -I/usr/include/libxml2/
250 CLUTTER_SRC = clutter-app.c
251 CLUTTER_LINKS = -lclutter-gst-0.10 -lglib-2.0
252 GTK_CLUTTER_LINKS = $(LINKS) -lgstinterfaces-0.10 -lclutter-gst-0.10 -lglib-2.0 -lclutter-gtk-0.10
253 GTK_CLUTTER_INCLUDES = $(GTK_INCLUDES) $(CLUTTER_INCLUDES)
255 gtk-app::
256 $(CC) -g $(ALL_CFLAGS) $(CPPFLAGS) $(CV_LINKS) $(INCLUDES) $(GTK_INCLUDES)\
257 $(GTK_LINKS) -o $@ $(GTK_APP)
259 gtk-clutter-app::
260 $(CC) $(ALL_CFLAGS) $(CPPFLAGS) $(GTK_CLUTTER_LINKS) $(INCLUDES) $(GTK_CLUTTER_INCLUDES) \
261 -o $@ gtk-clutter-app.c
263 sparrow.xml::
264 $(GST_LAUNCH) -o sparrow.xml $(TEST_GST_ARGS) v4l2src ! $(TEST_V4L2_PIPE_TAIL)
266 clutter-app:
267 $(CC) $(ALL_CFLAGS) $(CPPFLAGS) $(CLUTTER_LINKS) $(CLUTTER_INCLUDES)\
268 $(LINKS) -o $@ $(CLUTTER_SRC)
270 app-clean:
271 $(RM) gtk-app clutter-app