Does anyone here know how to write a makefile for ffmpeg's test code?
Is the makefile maked by automake?
I found the demo's makefile, but not the makefile.in, so I cannot write the makefile.in.
Do you have the makefile.in?
I have searched for the answer for a week, but have not solved the problem.
this is the makefile from ffmpeg examples directory:
# use pkg-config for getting CFLAGS and LDLIBS
FFMPEG_LIBS= libavdevice \
libavformat \
libavfilter \
libavcodec \
libswresample \
libswscale \
libavutil \
CFLAGS += -Wall -O2 -g
CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS)
LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
EXAMPLES= decoding_encoding \
demuxing \
filtering_video \
filtering_audio \
metadata \
muxing \
scaling_video \
OBJS=$(addsuffix .o,$(EXAMPLES))
# the following examples make explicit use of the math library
decoding_encoding: LDLIBS += -lm
muxing: LDLIBS += -lm
.phony: all clean-test clean
all: $(OBJS) $(EXAMPLES)
clean-test:
$(RM) test*.pgm test.h264 test.mp2 test.sw test.mpg
clean: clean-test
$(RM) $(EXAMPLES) $(OBJS)
as you can see it's a plain handwritten Makefile so there's no autotools stuff, and you can change it easily
Related
I downloaded libopencm3 (https://github.com/libopencm3/libopencm3) library and compiled it. It worked. I found a small project that uses this library and copied the instructions from its makefile.
all:
arm-none-eabi-gcc \
-Os \
-ggdb3 \
-mthumb \
-mcpu=cortex-m0 \
-msoft-float \
-Wall \
-Wextra \
-Wundef \
-Wshadow \
-Wredundant-decls \
-fno-common \
-ffunction-sections \
-fdata-sections \
-std=c11 \
-MD \
-DSTM32F0 \
-I./libopencm3/include \
-o main.o \
-c main.c
arm-none-eabi-gcc \
--static \
-nostartfiles \
-Tstm32f0.ld \
-mthumb \
-mcpu=cortex-m0 \
-msoft-float \
-ggdb3 \
-Wl,-Map=main.map \
-Wl,--cref \
-Wl,--gc-sections \
-L./libopencm3/lib \
main.o \
-lopencm3_stm32f0 \
-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
-o main.elf
I created a folder for the project, pasted libopencm3 folder inside it and compiled. It's working, but I don't understand how this part works:
-L./libopencm3/lib main.o -lopencm3_stm32f0
If I am right, it is instructing to find opencm3_stm32f0 library inside /libopencm3/lib, but inside that folder I found libopencm3_stm32f0.a instead.
I want to know why they changed the name and omitted the extension and it still worked.
This isn't related to makefiles or to any specific library, or to embedded systems, so those tags on your question are not needed.
If you look up the -l option in the documentation of the linker, you'll understand how it works.
I'm trying to put together a simple makefile example like so:
FLAGS = -std=c++14
INC= -I/usr/local/include
LI = -L/usr/local/lib
LIB = /usr/local/lib/
LIBS = $(LIB)libboost_filesystem-mt.a \
$(LIB)libboost_filesystem-mt.dylib \
$(LIB)libboost_filesystem.a \
$(LIB)libboost_filesystem.dylib \
$(LIB)libboost_system-mt.a \
$(LIB)libboost_system-mt.dylib \
$(LIB)libboost_system.a \
$(LIB)libboost_system.dylib
default:
g++ main.cpp $(FLAGS) $(INC) $(LI) $(LIBS) -o assemble
./assemble
clean:
rm assemble
Is there a way to not have to prepend $(LIB) so many times? That's the only way I can get this to work right now (the above doesn't).
If you want the linker to search the path you have to add libraries using the -l flag. So instead of adding libboost_system-mt.a to your link line, you have to add -lboost_system-mt to your link line. Then the linker will search the paths provided by -L.
I'm not sure about the dylib stuff; I don't do much with OS X.
In any event, if you're using GNU make you can do this:
LIBNAMES := filesystem-mt filesystem system-mt system
LIBS := $(foreach N,$(LIBNAMES),$(LIB)libboost_$N.a $(LIB)libboost_$N.dylib)
Given the following makefile for GNU make:
# TODOs so I don't forget:
# - make debugging an option
# - make 64 below an actual option
# - figure out why make test seems to rebuild the DLL
# - __declspec(dllimport)
ifeq ($(MAKECMDGOALS),64)
CC = x86_64-w64-mingw32-gcc
RC = x86_64-w64-mingw32-windres
mflag = -m64
else
CC = i686-w64-mingw32-gcc
RC = i686-w64-mingw32-windres
mflag = -m32
endif
OBJDIR = .objs
OUTDIR = out
BASENAME = wintable
DLLFILE = $(OUTDIR)/$(BASENAME).dll
LIBFILE = $(OUTDIR)/$(BASENAME).lib
TESTEXEFILE = $(OUTDIR)/$(BASENAME).exe
CFILES = \
alloc.c \
api.c \
checkboxdraw.c \
checkboxevents.c \
children.c \
coord.c \
debug.c \
draw.c \
events.c \
header.c \
hscroll.c \
main.c \
metrics.c \
modelhelpers.c \
nullmodel.c \
resize.c \
scroll.c \
select.c \
update.c \
util.c \
visibility.c \
vscroll.c
HFILES = \
table.h \
tablepriv.h
TESTCFILES = \
test.c
OFILES = $(CFILES:%.c=$(OBJDIR)/%.o)
TESTOFILES = $(TESTCFILES:%.c=$(OBJDIR)/%.o)
xCFLAGS = \
--std=c99 \
-Wall \
-Wextra \
-Wno-unused-parameter \
$(mflag) \
$(CFLAGS)
xLDFLAGS = \
-static-libgcc \
-luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lole32 -loleaut32 -loleacc -luuid -lmsimg32 \
$(mflag) \
$(LDFLAGS)
default:
$(MAKE) clean
$(MAKE) it
$(MAKE) test
it: $(DLLFILE)
$(DLLFILE): $(OFILES)
$(CC) -g -o $(DLLFILE) -shared -Wl,--out-implib,$(LIBFILE) $(OFILES) $(xLDFLAGS)
test: $(TESTEXEFILE)
$(TESTEXEFILE): $(DLLFILE) $(TESTOFILES)
$(CC) -g -o $(TESTEXEFILE) $(TESTOFILES) $(LIBFILE) $(xLDFLAGS)
$(OBJDIR)/%.o: %.c $(HFILES) dirs
$(CC) -g -o $# -c $< $(xCFLAGS)
dirs:
mkdir -p $(OBJDIR) $(OUTDIR)
clean:
rm -rf $(OBJDIR) $(OUTDIR)
make -n test produces
mkdir -p .objs out
i686-w64-mingw32-gcc -g -o .objs/alloc.o -c alloc.c --std=c99 -Wall -Wextra -Wno-unused-parameter -m32
i686-w64-mingw32-gcc -g -o .objs/api.o -c api.c --std=c99 -Wall -Wextra -Wno-unused-parameter -m32
(and so on for all the other C files)
i686-w64-mingw32-gcc -g -o out/wintable.dll -shared -Wl,--out-implib,out/wintable.lib .objs/alloc.o .objs/api.o .objs/checkboxdraw.o .objs/checkboxevents.o .objs/children.o .objs/coord.o .objs/debug.o .objs/draw.o .objs/events.o .objs/header.o .objs/hscroll.o .objs/main.o .objs/metrics.o .objs/modelhelpers.o .objs/nullmodel.o .objs/resize.o .objs/scroll.o .objs/select.o .objs/update.o .objs/util.o .objs/visibility.o .objs/vscroll.o -static-libgcc -luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lole32 -loleaut32 -loleacc -luuid -lmsimg32 -m32
i686-w64-mingw32-gcc -g -o .objs/test.o -c test.c --std=c99 -Wall -Wextra -Wno-unused-parameter -m32
i686-w64-mingw32-gcc -g -o out/wintable.exe .objs/test.o out/wintable.lib -static-libgcc -luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lole32 -loleaut32 -loleacc -luuid -lmsimg32 -m32
i686-w64-mingw32-gcc test.c out/wintable.exe -o test
Notice how the last step that GNU make decides to do tries to recompile my test.c with the correct output executable file built before that into a new test executable, which (predictably) fails spectacularly:
out/wintable.exe: In function `WinMainCRTStartup':
/build/buildd/mingw-w64-3.1.0/build/i686-w64-mingw32-i686-w64-mingw32-crt/../../mingw-w64-crt/crt/crtexe.c:171: multiple definition of `WinMainCRTStartup'
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/lib/../lib/crt2.o:/build/buildd/mingw-w64-3.1.0/build/i686-w64-mingw32-i686-w64-mingw32-crt/../../mingw-w64-crt/crt/crtexe.c:171: first defined here
out/wintable.exe: In function `mainCRTStartup':
/build/buildd/mingw-w64-3.1.0/build/i686-w64-mingw32-i686-w64-mingw32-crt/../../mingw-w64-crt/crt/crtexe.c:199: multiple definition of `mainCRTStartup'
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/lib/../lib/crt2.o:/build/buildd/mingw-w64-3.1.0/build/i686-w64-mingw32-i686-w64-mingw32-crt/../../mingw-w64-crt/crt/crtexe.c:199: first defined here
out/wintable.exe:cygming-crtbegin.c:(.text+0x500): multiple definition of `__gcc_register_frame'
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
out/wintable.exe:cygming-crtbegin.c:(.text+0x550): multiple definition of `__gcc_deregister_frame'
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/crtbegin.o:cygming-crtbegin.c:(.text+0x50): first defined here
out/wintable.exe: In function `mainwinCreate':
/home/pietro/src/github.com/andlabs/wintable/test.c:20: multiple definition of `mainwinCreate'
/tmp/cc50VrIz.o:test.c:(.text+0x0): first defined here
out/wintable.exe: In function `mainwinDestroy':
/home/pietro/src/github.com/andlabs/wintable/test.c:66: multiple definition of `mainwinDestroy'
/tmp/cc50VrIz.o:test.c:(.text+0x2ba): first defined here
(and so on for virtually every symbol in my test.c)
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/crtbegin.o:cygming-crtbegin.c:(.text+0x22): undefined reference to `_Jv_RegisterClasses'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'test' failed
make: *** [test] Error 1
Where is this last step coming from? It's nowhere in my makefile, as far as I can tell. (Notice the lack of compiler flags.) Googling the problem was also ineffective here. This only started to happen today, with all the same rules as before (the only change is the addition of modelhelpers.c and nullmodel.c to CFILES), so I'm not sure what's going on.
Does it have to do with the rule being test? If so, why did it work before?
This is GNU make 4.0 on Ubuntu GNOME 14.10.
Thanks.
Make has various built-in implicit rules, and one of them is the pattern rule % : %.c, which tells make how to create an executable (in UNIX systems, executables don't have any extension like .exe etc., they're just words like test, mkdir, etc.) if it has a source file with the same extension.
Your makefile has:
test: $(TESTEXEFILE)
and you provide no recipe for building the target test, so make looks at its built-in rules and finds % : %.c, and then make looks and sees that you DO have a test.c file, so make applies that default recipe to build the target test, which you asked it to do.
If you don't want this to happen you should tell make that test is not a real target: that you're only using it as a handle to build other things, using the .PHONY special target:
.PHONY: test
From the manual:
The implicit rule search is skipped for .PHONY targets.
I am trying to run a makefile with gfortran in my mac. It compiles without problem in Fedora 18, but I can't make it work in Mac OS 10.8.4 with the last gfortran from HPC.
I am newbie on fortran, so some light would be appreciated.
Here is the Make file:
# Makefile made to work with GNU Make
.DEFAULT:
BIN=bin
OBJ=obj
vpath= %$(OBJ)/.o $(OBJ)
vpath= %.mod $(OBJ)
EXES= pasos \
pasosng \
pasosm \
trans \
cost \
lcal \
fluj \
loc \
eval \
impas \
imptra \
mats \
imploc \
matesp \
dimen
FC=gfortran
LN=gfortran
FCFLAGS=$(USER_FCFLAGS) -g3 -B $(OBJ) -J $(OBJ) #fc_options #fc_warnings
LFLAGS=$(USER_LFLAGS)
ifdef SystemRoot
dotexe=.exe
endif
ifdef F_PROFILE
FCFLAGS:=$(FCFLAGS) -pg
LFLAGS:=$(LFLAGS) -pg
endif
ifdef F_TEST
FCFLAGS:=-O0 -fbounds-check $(FCFLAGS)
else
FCFLAGS:=-O3 $(FCFLAGS)
endif
COMPILE=$(FC) $(FCFLAGS) -o $# -c $<
LINK=$(LN) $(LFLAGS) -o $# -Wl,-Map=$#.map $^
%.o : %.f90
$(COMPILE)
all: prepare $(EXES)
$(OBJ)/%.o : %.f90
$(COMPILE)
clean:
rm -rf $(OBJ) $(BIN)
prepare: $(BIN) $(OBJ)
$(BIN):
mkdir $(BIN)
$(OBJ):
mkdir $(OBJ)
pasos: prepare $(BIN)/pasos$(dotexe)
#echo $#
$(BIN)/pasos$(dotexe) : $(OBJ)/pasos.o \
$(OBJ)/nodes.o \
$(OBJ)/io_list.o \
$(OBJ)/rcomm.o \
$(OBJ)/tparc.o \
$(OBJ)/zcomm.o \
$(OBJ)/rcomm.o \
$(OBJ)/pcomm.o \
$(OBJ)/getoptm.o \
$(OBJ)/control.o \
$(OBJ)/heap.o \
$(OBJ)/gener.o \
$(OBJ)/param.o \
$(OBJ)/ascii.o \
$(OBJ)/pcomm.o \
$(OBJ)/mensamod.o \
$(OBJ)/optionsm.o \
$(OBJ)/debugm.o
$(LINK)
The file is longer, but I dont know if it is needed to understand the error. The error I get when I run make over the directory is:
tcapelle$ gnumake
gfortran -o bin/pasos -Wl,-Map=bin/pasos.map obj/pasos.o obj/nodes.o obj/io_list.o obj/rcomm.o obj/tparc.o obj/zcomm.o obj/pcomm.o obj/getoptm.o obj/control.o obj/heap.o obj/gener.o obj/param.o obj/ascii.o obj/mensamod.o obj/optionsm.o obj/debugm.o
ld: unknown option: -Map=bin/pasos.map
collect2: error: ld returned 1 exit status
gnumake: *** [bin/pasos] Error 1
Edit:
I changed in the makefile
LINK=$(LN) $(LFLAGS) -o $# -Wl,-Map=$#.map $^
to
LINK=$(LN) $(LFLAGS) -o $# $^
and it compiles with some errors, but it worked.
What does this -Wl,-Map= thing do?
The problem is that the BSD linker (in contrast to the GNU linker) does not recognize options, if they are separated from the corresponding value by an equal sign (instead of a whitespace). So
ld -Map test.map
is fine, while
ld -Map=test.map
is not. Therefore, you must make sure, the compiler passes the linker options to the linker in the latter form. For that you need
gfortran -Wl,-Map,test.map ...
which you can achieve by changing the definition of the LINK variable to:
LINK=$(LN) $(LFLAGS) -o $# -Wl,-Map,$#.map $^
The makefile is included below. It's just a long list of object files and two targets. The problem seems to be that the $(INC) is being ignored for the first target. For example, the output starts with "g++ -c -o main.o main.cpp" instead of "g++ -I/usr/home/jrm/tmp/proteus_beta -c -o main.o main.cpp".
TIA
PROG = proteus
# list of object files
OBJS = main.o \
dataset.o \
genetic_codes.o \
likelihood_engine.o \
options.o \
parsimony.o \
parsimony_engine.o \
seq.o \
site_collection.o \
site_pattern.o \
tools.o \
optare/crs.o \
optare/point.o \
optare/newton_1d.o \
optare/golden_section.o \
models/model.o \
models/DNA/DNA_model.o \
models/DNA/DNA_ssm.o \
models/CODON/CODON_model.o \
models/CODON/CODON_modelA.o \
models/CODON/CODON_modelB.o \
models/CODON/CODON_modelC.o \
models/CODON/CODON_modelD.o \
models/CODON/CODON_M0.o \
models/CODON/CODON_M1.o \
models/CODON/CODON_M2.o \
models/CODON/CODON_M3.o \
models/CODON/CODON_M0gtr.o \
models/CODON/CODON_FEBC1.o \
models/CODON/CODON_FEBC1b.o \
models/CODON/FESC/CODON_FESC1.o \
models/CODON/CODON_nh/CODON_M0nh1.0 \
models/CODON/CODON_nh/CODON_M1nh1.0 \
models/CODON/CODON_nh/CODON_M1nh1.0 \
models/CODON/CODON_nh/CODON_M3nh1.0 \
models/CODON/CODON_nh/CODON_M0nh2.0 \
models/CODON/CODON_nh/CODON_MmodelAnh2.0 \
matrices/matrix.o \
matrices/DNA_matrix.o \
matrices/CODON_matrix.o \
matrices/AA_matrix.o \
matrices/int_matrix.o \
matrices/str_matrix.o \
matrices/eigen.o \
incidere/slice_sampler.o \
dendrology/forestry.o \
dendrology/node.o \
dendrology/DNA_node.o \
dendrology/tree.o \
alphabetia/alphabet.o \
alphabetia/DNA_alphabet.o \
alphabetia/CODON_alphabet.o \
alphabetia/AA_alphabet.o
CC = g++
INC=-I/home/jrm/tmp/proteus_beta
.C.o:
$(CC) $< -c $(INC)
$(PROG): $(OBJS)
$(CC) -o $# $(OBJS) -lm
According to your post, you have a file named main.cpp, not a file named main.C. But you provide an implicit rule for converting .C files to .o. Make will compile main.cpp using its built-in rule for .cpp to .o compilation. You have two options to do what you want:
(1) Change your implicit rule to .cpp.o (and consider using new-style rules, i.e. %.cpp: %.o)
(2) Declare a CXXFLAGS variable (which is automatically included in Make's C++ compilation implicit rule) such as the following:
CXXFLAGS = $(INC)
and then remove your .C.o implicit rule.
The second option will simplify your makefile, and it will work with C++ files, regardless of the extension.
Do your source files end with .C or .cpp?
The compilation rule for .C.o lists $(INC) after the other parts of the rule, not where you expect the output to come:
CC = g++
INC = -I/home/jrm/tmp/proteus_beta
.C.o:
$(CC) $< -c $(INC)
You should see:
g++ file.C -c -I/home/jrm/tmp/proteus_beta
But it appears to be ignoring your rule altogether. You mention main.cpp; that will never be compiled by your rule.
So, is .C a recognized suffix? Are your source files .C files? Are you running on a case-insensitive file-system? Why are you setting the C compiler (CC) -- you've probably got case problems with your source.