Skip to content

Commit 5f27e8c

Browse files
smvvliuliu
authored andcommitted
varies fixes for new build system via smvv
I cannot merge all @smvv's changes due the the fact that I cannot understand all the dependencies of these makefiles, and the newly changed tld.c file cannot pass my test video. Will do these merges later, but for now, only limited changes are merged to mainline. Fix C spec violation error due to missing -std=c99 Various build system and configure script improvements Move configure script to root directory Fix undeclared constants (previously included by png.h) The undeclared constants are defined in zlib.h. Previously, png.h included zlib.h, but recent versions of libpng (version >= 1.5) do not include zlib.h anymore. This commit will solve the following errors: lib/io/_ccv_io_libpng.c: In function ‘_ccv_write_png_fd’: lib/io/_ccv_io_libpng.c:55:23: error: ‘MAX_MEM_LEVEL’ undeclared (first use in this function) lib/io/_ccv_io_libpng.c:55:23: note: each undeclared identifier is reported only once for each function it appears in lib/io/_ccv_io_libpng.c:63:38: error: ‘Z_BEST_SPEED’ undeclared (first use in this function) lib/io/_ccv_io_libpng.c:65:40: error: ‘Z_HUFFMAN_ONLY’ undeclared (first use in this function) Rewrote build system for proper dependency tracking This commit makes it also possible to build all binaries and the ccv library in parallel using e.g. make -j4. Add build/lib to ld's library search path Cleanup and mark object files as precious (aka "do-not-remove") Use conditional assignment for CC, CFLAGS and LDFLAGS Integrate test/ in central build system (work in progress) Fix C spec violation error due to missing -std=c99 Add test/ directory to header include path
1 parent 27a9d8a commit 5f27e8c

File tree

12 files changed

+74
-104
lines changed

12 files changed

+74
-104
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ bin/*.diff
2828
bin/data/*
2929
data/*
3030
tool/*
31+
config.mk
32+
build

bin/makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
CC = `cat ../lib/.CC`# -faddress-sanitizer -fno-omit-frame-pointer
2-
LDFLAGS = -L"../lib" -lccv `cat ../lib/.LN`
3-
CFLAGS = -O3 -Wall -I"../lib" `cat ../lib/.DEF`
1+
include ../lib/config.mk
2+
3+
#CC += -faddress-sanitizer -fno-omit-frame-pointer
4+
LDFLAGS := -L"../lib" -lccv $(LDFLAGS)
5+
CFLAGS := -O3 -Wall -I"../lib" $(CFLAGS)
46

57
TARGETS = bbffmt msermatch siftmatch bbfcreate bbfdetect swtcreate swtdetect dpmcreate dpmdetect convert tld
68

@@ -10,12 +12,10 @@ clean:
1012
${MAKE} clean -C ../lib ; rm *.o $(TARGETS)
1113

1214
$(TARGETS): %: %.o libccv.a
13-
@echo "$(CC) -o $@ $< $(LDFLAGS)"
14-
@$(CC) -o $@ $< $(LDFLAGS)
15+
$(CC) -o $@ $< $(LDFLAGS)
1516

1617
libccv.a:
1718
${MAKE} -C ../lib
1819

1920
%.o: %.c ../lib/ccv.h
20-
@echo "$(CC) $< -o $@ -c $(CFLAGS)"
21-
@$(CC) $< -o $@ -c $(CFLAGS)
21+
$(CC) $< -o $@ -c $(CFLAGS)

bin/tld.c

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ int main(int argc, char** argv)
2424
AVFormatContext* ic = 0;
2525
int video_stream = -1;
2626
AVStream* video_st = 0;
27-
AVFrame* picture = avcodec_alloc_frame();
28-
AVFrame* rgb_picture = avcodec_alloc_frame();
29-
//avcodec_get_frame_defaults(&rgb_picture);
27+
AVFrame* picture = 0;
28+
AVFrame rgb_picture;
29+
memset(&rgb_picture, 0, sizeof(AVPicture));
3030
AVPacket packet;
3131
memset(&packet, 0, sizeof(AVPacket));
3232
av_init_packet(&packet);
@@ -47,77 +47,38 @@ int main(int argc, char** argv)
4747
continue;
4848
video_stream = i;
4949
video_st = ic->streams[i];
50-
avpicture_alloc((AVPicture*) rgb_picture, PIX_FMT_RGB24, enc->width, enc->height);
50+
picture = avcodec_alloc_frame();
51+
rgb_picture.data[0] = (uint8_t*)ccmalloc(avpicture_get_size(PIX_FMT_RGB24, enc->width, enc->height));
52+
avpicture_fill((AVPicture*)&rgb_picture, rgb_picture.data[0], PIX_FMT_RGB24, enc->width, enc->height);
5153
break;
5254
}
5355
}
5456
int got_picture = 0;
5557
while (!got_picture)
5658
{
57-
av_init_packet(&packet);
5859
int result = av_read_frame(ic, &packet);
59-
if (result == AVERROR(EAGAIN) || packet.stream_index != video_stream)
60-
{
61-
av_free_packet(&packet);
60+
if (result == AVERROR(EAGAIN))
6261
continue;
63-
}
64-
else if (result < 0)
65-
return 1;
66-
67-
if (avcodec_decode_video2(video_st->codec, picture, &got_picture,
68-
&packet) < 0)
69-
return 1;
70-
av_free_packet(&packet);
62+
avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
7163
}
72-
7364
ccv_enable_default_cache();
74-
75-
struct SwsContext* picture_ctx =
76-
sws_getCachedContext(0, video_st->codec->width,
77-
video_st->codec->height, video_st->codec->pix_fmt,
78-
video_st->codec->width, video_st->codec->height,
79-
PIX_FMT_RGB24, SWS_BICUBIC, 0, 0, 0);
80-
81-
sws_scale(picture_ctx, (const uint8_t* const*) picture->data,
82-
picture->linesize, 0, video_st->codec->height,
83-
rgb_picture->data, rgb_picture->linesize);
84-
65+
struct SwsContext* picture_ctx = sws_getCachedContext(0, video_st->codec->width, video_st->codec->height, video_st->codec->pix_fmt, video_st->codec->width, video_st->codec->height, PIX_FMT_RGB24, SWS_BICUBIC, 0, 0, 0);
66+
sws_scale(picture_ctx, (const uint8_t* const*)picture->data, picture->linesize, 0, video_st->codec->height, rgb_picture.data, rgb_picture.linesize);
8567
ccv_dense_matrix_t* x = 0;
86-
ccv_read(rgb_picture->data[0], &x, CCV_IO_RGB_RAW | CCV_IO_GRAY,
87-
video_st->codec->height, video_st->codec->width,
88-
rgb_picture->linesize[0]);
68+
ccv_read(rgb_picture.data[0], &x, CCV_IO_RGB_RAW | CCV_IO_GRAY, video_st->codec->height, video_st->codec->width, rgb_picture.linesize[0]);
8969
ccv_tld_t* tld = ccv_tld_new(x, box, ccv_tld_default_params);
90-
9170
ccv_dense_matrix_t* y = 0;
92-
9371
for (;;)
9472
{
9573
got_picture = 0;
96-
97-
av_init_packet(&packet);
9874
int result = av_read_frame(ic, &packet);
99-
100-
if (result == AVERROR(EAGAIN) || packet.stream_index != video_stream)
101-
{
102-
av_free_packet(&packet);
75+
if (result == AVERROR(EAGAIN))
10376
continue;
104-
}
105-
else if (result < 0)
106-
return 1;
107-
108-
if (avcodec_decode_video2(video_st->codec, picture, &got_picture,
109-
&packet) < 0)
110-
return 1;
111-
77+
avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
11278
if (!got_picture)
11379
break;
114-
115-
sws_scale(picture_ctx, (const uint8_t* const*)picture->data,
116-
picture->linesize, 0, video_st->codec->height,
117-
rgb_picture->data, rgb_picture->linesize);
118-
ccv_read(rgb_picture->data[0], &y, CCV_IO_RGB_RAW | CCV_IO_GRAY,
119-
video_st->codec->height, video_st->codec->width,
120-
rgb_picture->linesize[0]);
80+
sws_scale(picture_ctx, (const uint8_t* const*)picture->data, picture->linesize, 0, video_st->codec->height, rgb_picture.data, rgb_picture.linesize);
81+
ccv_read(rgb_picture.data[0], &y, CCV_IO_RGB_RAW | CCV_IO_GRAY, video_st->codec->height, video_st->codec->width, rgb_picture.linesize[0]);
12182
ccv_tld_info_t info;
12283
ccv_comp_t newbox = ccv_tld_track_object(tld, x, y, &info);
12384
/*
@@ -171,8 +132,7 @@ int main(int argc, char** argv)
171132
}
172133
ccv_matrix_free(x);
173134
ccv_tld_free(tld);
174-
avpicture_free((AVPicture *) rgb_picture);
175-
av_free(rgb_picture);
135+
ccfree(rgb_picture.data[0]);
176136
ccv_disable_cache();
177137
#endif
178138
#endif

lib/ccv_io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
// Unsupported platform
1515
#endif
1616
#else
17-
#include <libpng/png.h>
17+
#include <zlib.h>
18+
#include <png.h>
1819
#endif
1920
#include "io/_ccv_io_libpng.c"
2021
#endif

lib/ccv_tld.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ static ccv_rect_t _ccv_tld_short_term_track(ccv_dense_matrix_t* a, ccv_dense_mat
9090
ccv_array_t* point_a = ccv_array_new(sizeof(ccv_decimal_point_t), (TLD_GRID_SPARSITY - 1) * (TLD_GRID_SPARSITY - 1), 0);
9191
float gapx = (float)box.width / TLD_GRID_SPARSITY;
9292
float gapy = (float)box.height / TLD_GRID_SPARSITY;
93-
for (float x = gapx * 0.5; x < box.width; x += gapx)
94-
for (float y = gapy * 0.5; y < box.height; y += gapy)
93+
float x, y;
94+
for (x = gapx * 0.5; x < box.width; x += gapx)
95+
for (y = gapy * 0.5; y < box.height; y += gapy)
9596
{
9697
ccv_decimal_point_t point = ccv_decimal_point(box.x + x, box.y + y);
9798
ccv_array_push(point_a, &point);

lib/configure

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ if [ `uname` == "Darwin" ] ; then
55
fi
66

77
if [ "$1" = "force" ] ; then
8-
rm -f .CC .DEF .LN
8+
rm -f config.mk
99
fi
1010

11-
if [ ! -e .CC -o ! -e .DEF -o ! -e .LN ] ; then
12-
echo -e "\n There are a few questions for you:\n"
13-
fi
11+
contains_flag () {
12+
if [ -f config.mk ]; then
13+
grep -E "^$1 := " config.mk &>/dev/null;
14+
return $?;
15+
fi
16+
17+
return 1;
18+
}
1419

15-
if [ -e .CC ] ; then
16-
CC=`cat .CC`
20+
if contains_flag CC; then
21+
CC=`grep -oE 'CC := [^#]+' config.mk | cut -b7-`
1722
else
1823
echo -ne " Default compiler: \033[4mclang\033[m [Y/n] ? "
1924
read -n 1 yn ; if [ ! -z $yn ] ; then echo ; fi
@@ -23,12 +28,12 @@ else
2328
* ) CC='clang'
2429
;;
2530
esac
26-
echo $CC > .CC
31+
echo "CC := $CC" >> config.mk
2732
fi
2833

29-
if [ -e .DEF -a -e .LN ] ; then
30-
CFLAGS=`cat .DEF`
31-
LDFLAGS=`cat .LN`
34+
if contains_flag CFLAGS && contains_flag LDFLAGS; then
35+
CFLAGS=`grep -oE 'CFLAGS := [^#]+' config.mk | cut -b11-`
36+
LDFLAGS=`grep -oE 'LDFLAGS := [^#]+' config.mk | cut -b12-`
3237
else
3338
CFLAGS=" "
3439
LDFLAGS="-lm "
@@ -124,8 +129,8 @@ else
124129
;;
125130
* ) ;;
126131
esac
127-
echo $CFLAGS > .DEF
128-
echo $LDFLAGS > .LN
132+
echo "CFLAGS := $CFLAGS" >> config.mk
133+
echo "LDFLAGS := $LDFLAGS" >> config.mk
129134
fi
130135

131136
CFLAGS="${CFLAGS#"${CFLAGS%%[![:space:]]*}"}" # remove leading whitespaces

lib/makefile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
CC = `cat .CC`# -faddress-sanitizer -fno-omit-frame-pointer
2-
CFLAGS = -O3 -ffast-math -Wall `cat .DEF`# -fprofile-arcs -ftest-coverage
1+
include config.mk
32

4-
config:
5-
@./configure
6-
@make all
3+
#CC += -faddress-sanitizer -fno-omit-frame-pointer
4+
CFLAGS := -O3 -ffast-math -Wall $(CFLAGS)# -fprofile-arcs -ftest-coverage
75

8-
force: clean
9-
@./configure force
10-
@make all
6+
.PHONY: all clean
117

128
all: libccv.a
139

@@ -18,9 +14,7 @@ libccv.a: ccv_cache.o ccv_memory.o 3rdparty/sha1/sha1.o 3rdparty/kissfft/kiss_ff
1814
ar rcs $@ $^
1915

2016
ccv_io.o: ccv_io.c ccv.h ccv_internal.h io/*.c
21-
@echo "$(CC) $< -o $@ -c $(CFLAGS)"
22-
@$(CC) $< -o $@ -c $(CFLAGS)
17+
$(CC) $< -o $@ -c $(CFLAGS)
2318

2419
%.o: %.c ccv.h ccv_internal.h
25-
@echo "$(CC) $< -o $@ -c $(CFLAGS)"
26-
@$(CC) $< -o $@ -c $(CFLAGS)
20+
$(CC) $< -o $@ -c $(CFLAGS)

test/functional/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
CC = `cat ../../lib/.CC`# -fprofile-arcs -ftest-coverage
2-
LDFLAGS = -L"../../lib" -lccv `cat ../../lib/.LN`
3-
CFLAGS = -O3 -msse2 -Wall -I"../../lib" -I"../" `cat ../../lib/.DEF`
1+
include ../../lib/config.mk
2+
3+
#CC +=# -fprofile-arcs -ftest-coverage
4+
LDFLAGS := -L"../../lib" -lccv $(LDFLAGS)
5+
CFLAGS := -O3 -msse2 -Wall -I"../../lib" -I"../" $(CFLAGS)
46
TARGETS = algebra.tests util.tests numeric.tests basic.tests memory.tests io.tests transform.tests
57

68
test: all

test/functional/numeric.tests.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ void dt_min_helper(float *src, float *dst, int *ptr, int step,
224224
if (d2 >= d1) {
225225
int d = (d1+d2) >> 1;
226226
int s = s1;
227-
for (int p = s1+1; p <= s2; p++)
227+
int p;
228+
for (p = s1+1; p <= s2; p++)
228229
if (src[s*step] + a*square(d-s) + b*(d-s) >
229230
src[p*step] + a*square(d-p) + b*(d-p))
230231
s = p;
@@ -295,7 +296,8 @@ void dt_max_helper(float *src, float *dst, int *ptr, int step,
295296
if (d2 >= d1) {
296297
int d = (d1+d2) >> 1;
297298
int s = s1;
298-
for (int p = s1+1; p <= s2; p++)
299+
int p;
300+
for (p = s1+1; p <= s2; p++)
299301
if (src[s*step] - a*square(d-s) - b*(d-s) <
300302
src[p*step] - a*square(d-p) - b*(d-p))
301303
s = p;

test/opencv/filter_test.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ int main(int argc, char** argv)
1010
CvMat* gray = cvCreateMat(image->height, image->width, CV_32FC1);
1111
CvMat* x = cvCreateMat(image->height, image->width, CV_32FC1);
1212
CvMat* kernel = cvCreateMat(101, 101, CV_32FC1);
13-
for (int i = 0; i < image->height; i++)
14-
for (int j = 0; j < image->width; j++)
13+
int i, j;
14+
for (i = 0; i < image->height; i++)
15+
for (j = 0; j < image->width; j++)
1516
gray->data.fl[i * gray->cols + j] = image->imageData[i * image->widthStep + j * 3] * 0.1 + image->imageData[i * image->widthStep + j * 3 + 1] * 0.61 + image->imageData[i * image->widthStep + j * 3 + 2] * 0.29;
16-
for (int i = 0; i < kernel->rows; i++)
17-
for (int j = 0; j < kernel->cols; j++)
17+
for (i = 0; i < kernel->rows; i++)
18+
for (j = 0; j < kernel->cols; j++)
1819
kernel->data.fl[i * kernel->cols + j] = exp(-((i - kernel->rows / 2) * (i - kernel->rows / 2) + (j - kernel->cols / 2) * (j - kernel->cols / 2)) / 100);
1920
cvFilter2D(gray, x, kernel);
2021
cvSaveImage(argv[2], x);

0 commit comments

Comments
 (0)