So I have this code:
CELLMECH=../cellmech
ALL: \
png/01.png \
png/02.png \
png/03.png \
png/04.png \
png/05.png \
png/06.png \
png/07.png \
png/08.png \
png/09.png \
png/10.png pickles/cellMech.10.pickle.gz
include ${CELLMECH}/png.make
pickles/modLink.01.pickle.gz : stretched-plane.pickle.gz
mkdir -p pickles
${CELLMECH}/modLink.py -i $< -o $# -c conf
pickles/cellMech.01.pickle.gz : pickles/modLink.01.pickle.gz
${CELLMECH}/cellMech.py -dt 0.001 -nmax 10000 -i $< -o $# > /dev/null
.
.
.
This is a .make extension file that I exceute with: "make -f 10.make"
Then I get an error:
modLink.py -i stretched-plane.pickle.gz -o pickles/modLink.01.pickle.gz -c conf
make: modLink.py: No such file or directory
make: *** [10.make:19: pickles/modLink.01.pickle.gz] Error 127
I have tried everything, direct path to files, changing names, remaking the files, nothing worked. The make program can find the files with .make extension, but no matter what I do, it somehow cannot see the .py extension files.
Any help would be greatly appreciated.
Okay, after some consultation I found a solution: inserting "python" before the files, so they are given to the python interpeter directly. So the code runs in this form:
.
.
.
pickles/modLink.01.pickle.gz : stretched-plane.pickle.gz
mkdir -p pickles
python ${CELLMECH}/modLink.py -i $< -o $# -c conf
pickles/cellMech.01.pickle.gz : pickles/modLink.01.pickle.gz
python ${CELLMECH}/cellMech.py -dt 0.001 -nmax 10000 -i $< -o $# > /dev/null
.
.
.
Related
I'm trying to make a library for my project but I am very very new to Makefiles. I tried several configurations and adding -I but none worked.
I have the following three:
libft/
../includes/
....libft.h
../lst
....ft_lstnew.c
....ft_lstadd_front.c
....ft_lstadd_back.c
.... [...]
../src
....ft_isalpha.c
....ft_isalnum.c
.... [...]
And the following makefile:
NAME=libft.a
LIBSO=libft.so
CC=gcc
CFLAGS=-Wall -Wextra -Werror
SRC_DIR=src/
BONUS_DIR=lst/
OBJ_DIR=obj/
SRC_FILES= ft_bzero.c \
ft_isalmun.c \
ft_isalpha.c \
ft_isascii.c \
ft_isdigit.c \
ft_isprint.c \
ft_memchr.c \
ft_memcpy.c \
ft_memmove.c \
ft_memset.c \
ft_strchr.c \
ft_strlcat.c \
ft_strlcpy.c \
ft_strlen.c \
ft_strncmp.c \
ft_strrchr.c \
ft_tolower.c \
ft_toupper.c
BONUS_FILES=ft_lstadd_back.c \
ft_lstadd_front.c \
ft_lstdelone.c \
ft_lstclear.c \
ft_lstiter.c \
ft_lstlast.c \
ft_lstmap.c \
ft_lstnew.c \
ft_lstsize.c
SRC_PATH=$(addprefix $(SRC_DIR), $(SRC_FILES))
BONUS_PATH=$(addprefix $(BONUS_DIR), $(BONUS_FILES))
SRC_NAMES=$(SRC_FILES:.c=.o)
BONUS_NAMES=$(BONUS_FILES:.c=.o)
SRC_PATH_O=$(addprefix $(SRC_DIR), $(SRC_NAMES))
BONUS_PATH_O=$(addprefix $(BONUS_DIR), $(BONUS_NAMES))
HDR_NAME=libft.h
HDR_DIR=includes/
HDR= $(addprefix $(HDR_DIR),$(HDR_NAME))
all: $(NAME)
$(NAME): $(SRC_PATH_O)
ar rc $# $<
ranlib $#
$(OBJ_DIR):
mkdir $#
$(OBJ_DIR)%.o: $(SRC_DIR)%.c $(HDR_NAME)
$(CC) $(CFLAGS) -c $< -o $# -I $(HDR)
clean:
rm -rf $(OBJ_DIR)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: all clean fclean re
And I keep getting this each time I type make on the terminal:
gcc -Wall -Wextra -Werror -c -o src/ft_bzero.o src/ft_bzero.c
src/ft_bzero.c:1:10: fatal error: libft.h: No such file or directory
1 | #include "libft.h"
| ^~~~~~~~~
compilation terminated.
make: *** [<builtin>: src/ft_bzero.o] Error 1
Am I missing something? It's literally my first time.
Yes, you're missing some things.
First, look at the command line make shows:
gcc -Wall -Wextra -Werror -c -o src/ft_bzero.o src/ft_bzero.c
Note that the output here is not right for the recipe of the pattern rule you created: there's no -I option, and the object file is being written to src/ not obj/.
From this you should realize that your pattern rule is not being used at all, and instead make is using its built-in rule for building object files.
Why isn't your pattern rule being used? Let's look at it:
$(OBJ_DIR)%.o: $(SRC_DIR)%.c $(HDR_NAME)
what is this after variable expansion?
obj/%.o: src/%.c libft.h
This pattern (like all patterns) can only match if ALL the prerequisites either already exist or can be built. The src/%.c exists, after the pattern substitution. What about libft.h? No, that doesn't exist. What does exist is includes/libft.h but that's not the same thing.
So, this rule fails to match and make goes back to using its default rules.
If you want to say that every object file depends on that header, you have to use the correct path to the header file when you write the pattern.
Next, this is wrong:
$(CC) $(CFLAGS) -c $< -o $# -I $(HDR)
What is $(HDR)? It's the name of the file: include/libft.h. You don't include header file names with -I; you include directories that headers are looked for in. So you need $(HDR_DIR) here instead.
I write a ugly copy/paste way created Makefile:
all: download install
install: \
${EXTERNAL_MODELS_LOCAL}/squeezenet_weights_tf_dim_ordering_tf_kernels.h5 \
${EXTERNAL_MODELS_LOCAL}/resnet50_weights_tf_dim_ordering_tf_kernels.h5 \
${EXTERNAL_MODELS_LOCAL}/inception_v3_weights_tf_dim_ordering_tf_kernels.h5 \
${EXTERNAL_MODELS_LOCAL}/squeezenet_weights_tf_dim_ordering_tf_kernels.h5:
ln -s ${EXTERNAL_MODELS_ROOT}/squeezenet_weights_tf_dim_ordering_tf_kernels.h5 $#
${EXTERNAL_MODELS_LOCAL}/resnet50_weights_tf_dim_ordering_tf_kernels.h5:
ln -s ${EXTERNAL_MODELS_ROOT}/resnet50_weights_tf_dim_ordering_tf_kernels.h5 $#
${EXTERNAL_MODELS_LOCAL}/inception_v3_weights_tf_dim_ordering_tf_kernels.h5:
ln -s ${EXTERNAL_MODELS_ROOT}/inception_v3_weights_tf_dim_ordering_tf_kernels.h5 $#
download: $(EXTERNAL_MODELS_ROOT)/ \
$(EXTERNAL_MODELS_ROOT)/squeezenet_weights_tf_dim_ordering_tf_kernels.h5 \
$(EXTERNAL_MODELS_ROOT)/resnet50_weights_tf_dim_ordering_tf_kernels.h5 \
$(EXTERNAL_MODELS_ROOT)/inception_v3_weights_tf_dim_ordering_tf_kernels.h5 \
$(EXTERNAL_MODELS_ROOT)/squeezenet_weights_tf_dim_ordering_tf_kernels.h5:
wget https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/squeezenet_weights_tf_dim_ordering_tf_kernels.h5 \
-O $#
$(EXTERNAL_MODELS_ROOT)/resnet50_weights_tf_dim_ordering_tf_kernels.h5:
wget https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/resnet50_weights_tf_dim_ordering_tf_kernels.h5 \
-O $#
$(EXTERNAL_MODELS_ROOT)/inception_v3_weights_tf_dim_ordering_tf_kernels.h5:
wget https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/inception_v3_weights_tf_dim_ordering_tf_kernels.h5 \
-O $#
Biggest part skipped ,but looks the same. Is it possible to optimize this boilerplate?
A mixture of make variables, make automatic variables (e.g. $<, $#), make functions (e.g. addsuffix, addprefix) and pattern rules, maybe:
RHOST := https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/
H5STEM := squeezenet resnet50 inception_v3
H5 := $(addsuffix _weights_tf_dim_ordering_tf_kernels.h5,$(H5STEM))
H5LOCAL := $(addprefix $(EXTERNAL_MODELS_LOCAL)/,$(H5))
H5ROOT := $(addprefix $(EXTERNAL_MODELS_ROOT)/,$(H5))
.PHONY: install download
install: $(H5LOCAL)
download: $(H5ROOT)
$(EXTERNAL_MODELS_LOCAL)/%.h5: $(EXTERNAL_MODELS_ROOT)/%.h5
ln -s $< $#
$(EXTERNAL_MODELS_ROOT)/%.h5:
wget $(RHOST)/$*.h5 -O $#
And of course, if there was a way to automatically discover the list of remote *.h5 files, it would be even better. But some more information is needed to imagine how to do it (ssh, curl, wget... ?). The make shell function would be the starting point, of course:
H5 := $(shell <the-command-that-lists-the-remote-h5-files>)
I am trying to run trimesh2 on my 64-bit debian,
but whenever I try to run mesh_view or any other mesh command, it says
cannot execute binary file
What should I do to run the mesh? The Makefile looks like this:
all win32 linux32 linux64 darwin32 darwin64 clean:
$(MAKE) -C libsrc $#
$(MAKE) -C gluit $#
$(MAKE) -C utilsrc $#
debug:
$(MAKE) -C libsrc DEBUG=y
$(MAKE) -C gluit DEBUG=y
$(MAKE) -C utilsrc DEBUG=y
FINDCMD = find trimesh2 -name 'OBJ*' -prune -o -name CVS -prune -o -type f -print
tar:
cd .. && tar zcvf trimesh2.tar.gz `$(FINDCMD) | sort`
zip:
cd .. && $(FINDCMD) | sort | zip -9 trimesh2 -#
.PHONY : all clean debug default tar win32 zip
I'm new to using libtool. However, this problem seems to be weird. Everything is there but the libtool said "libtool: link: 'cuda_transfer.lo' is not a valid libtool object". However, the rule for generating this lo file is right there in the Makefile. Besides, the two header files are also right in where they are supposed to be and do work. Any idea about what is going wrong?
cuda_transfer.lo: particles_cuda.h ../../include/psc_particles_cuda.h
The other two places in Makefile where cuda_transfer.lo appeared are followed
libsubdir_la_DEPENDENCIES = cuda_transfer.lo \
libsubdir_la_LIBADD = \
cuda_transfer.lo \
The .c.lo: segment is following:
.c.lo:
$(AM_V_CC)depbase=`echo $# | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
$(LTCOMPILE) -MT $# -MD -MP -MF $$depbase.Tpo -c -o $# $< &&\
$(am__mv) $$depbase.Tpo $$depbase.Plo
# $(AM_V_CC)source='$<' object='$#' libtool=yes \
# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \
# $(AM_V_CC_no)$(LTCOMPILE) -c -o $# $<
How to interpret this human-unfriendly code. = =
Below is the code segment suggested by Brett.
noinst_LTLIBRARIES = libsubdir.la
libsubdir_la_SOURCES = \
psc_fields_cuda.c \
psc_particles_cuda.c \
psc_push_particles_cuda.c \
psc_push_fields_cuda.c \
psc_bnd_cuda.c \
psc_bnd_particles_cuda.c \
psc_bnd_fields_cuda.c \
b40c/kernel_utils.h \
b40c/radixsort_kernel_common.h \
b40c/radixsort_key_conversion.h \
b40c/radixsort_reduction_kernel.h \
b40c/radixsort_scanscatter_kernel.h \
b40c/radixsort_scanscatter_kernel3.h \
b40c/radixsort_scanscatter_kernel4.h \
b40c/radixsort_spine_kernel.h \
b40c/vector_types.h \
cuda_common.h \
cuda_sort2.h \
cuda_sort2_spine.h \
particles_cuda.h \
psc_bnd_cuda.h \
psc_bnd_cuda_fields.h \
psc_cuda.h
libsubdir_la_LIBADD = \
cuda_transfer.lo \
cuda_spine.lo \
cuda_sort2.lo \
cuda_sort3.lo \
cuda_exchange_particles.lo \
cuda_exclusive_scan_2.lo \
cuda_push_part_yz_1vb.lo
The only thing that looks like a generating rule about cuda_transfer.lo is
cuda_transfer.lo: particles_cuda.h ../../include/psc_particles_cuda.h
try this:
yum -y install libtool*
then make clean and restart again
Well, it's better not to read configure.ac ever :-) But if you still wish, configure.ac is a combination of m4 preprocessor code and ordinary (bourne) shell snippets. You may check info m4 and info autoconf, the docs are pretty decent.
The hard part of your question, regarding the .lo file. It seems that your makefile contains dependency chain for it, but no explicit build-rules. You may try to locate a common rule for compiling .c -> .lo, like this:
.c.lo:
$(AM_V_CC)$(LTCOMPILE) -MT $# -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $# $<
$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
...
Install latest libtool. Delete the .lo file and use 'make' again.
I have just discovered that a LaTeX compilation could be launched from a makefile. I came to this from the need to generate a series of targets with some alterations of parameters.
I have the file at the bottom. How can I add other compilation jobs, with different optional parameters say. Said otherwise, how to change the name of the target file(s) when there is more than one?
MyFileNew.pdf : MyFile.tex
pdflatex "\def\UseOption{nonumber,nographics,e} \input{MyFile.tex}"
#makefile
MyFile.pdf : MyFile.tex
pdflatex "\def\UseOption{number,graphics,ef} \input{MyFile.tex}"\
pdflatex "\def\UseOption{number,graphics,ef} \input{MyFile.tex}"
#echo «Removing auxilliary LaTeX files resulting from compilation»
#rm -f *.log *.aux *.dvi *.toc *.lot *.lof
#end of makefile
Are you perhaps looking for something like this?
pdflatex := pdflatex "\def\UseOption{$(options_$*)} \input{$<}"
cleanup := rm -f *.log *.aux *.dvi *.toc *.lot *.lof
options_MyFileNew := nonumber,nographics,e
options_MyFile := number,graphics,ef
MyFileNew.pdf MyFile.pdf: %.pdf: MyFile.tex
$(pdflatex)
$(pdflatex)
$(cleanup)
This is basically just a refactoring of what you already have.
The following works finally as expected (except for cleaning the auxilliary files).
Makefile
.PHONY: all clean clean-all
all : TargetFile1.pdf TargetFile2.pdf
TargetFile1.pdf : MyFile.tex
pdflatex --jobname=$(#:.pdf=) "\def\UseOption{number,nographics,e} \input{MyFile.tex}"
TargetFile2.pdf : MyFile.tex
pdflatex --jobname=$(#:.pdf=) "\def\UseOption{number,nographics,ef} \input{MyFile.tex}"
clean :
rm -f *.log *.aux *.dvi *.toc *.lof
clean-all : clean
rm -fr *.pdf
# Makefile
Simple make file
all: main.o module.o \\ The dependencies of the target all \
gcc main.o module.o -o target_bin \\ The action to make the target all \
main.o: main.c module.h \\ The dependencies fo the target main.o \
gcc -I . -c main.c \\ The action to make the target main.o ,\
module.o: module.c module.h \
gcc -I . -c module.c \\ -I tells the compiler header file locations \
clean: \\ This target has no dependencies \
rm -rf *.o \
rm target_bin
Answering this question requires a relatively long explanation and a multi files for demonstration, I included a HERE a link to a github repo that answers this question in a compact (with enough details).