gnu-make

Functions in Makefile

拜拜、爱过 提交于 2019-12-03 02:27:26
问题 I am writing a Makefile with a lot of repetitive stuff, e.g. debug_ifort_Linux: if [ $(UNAME) = Linux ]; then \ $(MAKE) FC=ifort FFLAGS=$(difort) PETSC_FFLAGS="..." \ TARGET=$@ LEXT="ifort_$(UNAME)" -e syst; \ else \ echo $(err_arch); \ exit 1; \ fi where the target 'syst' is defined, the variable 'UNAME' is defined (and is usually Linux, but might also by Cygwin or OSF1) and the variables 'difort' and 'err_arch' are also defined. This block of code is used very many times for different

Implementing `make check` or `make test`

我的梦境 提交于 2019-12-03 02:22:13
问题 How can I implement a simple regression test framework with Make? (I’m using GNU Make, if that matters.) My current makefile looks something like this (edited for simplicity): OBJS = jscheme.o utility.o model.o read.o eval.o print.o %.o : %.c jscheme.h gcc -c -o $@ $< jscheme : $(OBJS) gcc -o $@ $(OBJS) .PHONY : clean clean : -rm -f jscheme $(OBJS) I’d like to have a set of regression tests, e.g. , expr.in testing a “good” expression & unrecognized.in testing a “bad” one, with expr.cmp &

gmake compile all files in a directory

若如初见. 提交于 2019-12-03 02:20:41
we have some C++ code that we need to create a make file in. Each .h and .C pair create an object and then some objects are linked together to form a executable. Pretty standard stuff. This non-gnu make command just builds all the files into object in a directory %.o:%.C $(CC) $(CPFLAGS) -c $< What this does is for each %.C file (ie every .C file) build a corresponding .o file. Does anybody know how to do this with gmake? Cheers Mark The syntax you've shown is called a pattern rule in GNU make parlance, and it forms the corner stone of your solution. All you need is to add a way to get the

Can GNU make execute a rule whenever an error occurs?

筅森魡賤 提交于 2019-12-03 01:44:35
This is slightly different from Can a Makefile execute code ONLY when an error has occurred? . I'd like a rule or special target that is made whenever an error occurs (independent of the given target; without changing the rule for every target as the other answer seems to imply with the || operator). In dmake there is special target .ERROR that is executed whenever an error condition is detected . Is there a similar thing with GNU make? (I'm still using GNU make 3.81, but I didn't find anything in the documentation of the new GNU make 4.0 either) Gnu doesn't support it explicitly, but there's

telling 'make' to ignore dependencies when the top target has been created

随声附和 提交于 2019-12-03 01:22:43
I'm running the following kind of pipeline: digestA: hugefileB hugefileC cat $^ > $@ rm $^ hugefileB: touch $@ hugefileC: touch $@ The targets hugefileB and hugefileC are very big and take a long time to compute (and need the power of Make). But once digestA has been created, there is no need to keep its dependencies: it deletes those dependencies to free up disk space. Now, if I invoke 'make' again, hugefileB and hugefileC will be rebuilt, whereas digestA is already ok. Is there any way to tell 'make' to avoid to re-comile the dependencies ? NOTE: I don't want to build the two dependencies

How do I split a string in make?

流过昼夜 提交于 2019-12-03 01:13:10
I need to take a parameter in my Makefile that consists of a host identifier in the form host[:port] where the colon and port are optional. So all of the following are valid: foo.example.com ssl.example.com:443 localhost:5000 etc. I want to split the string on the optional colon and assign the values to variables, so that HOST contains foo.example.com , ssl.example.com , localhost , etc., and PORT contains 80 (the default port), 443, and 500 respectively. # Retrieves a host part of the given string (without port). # Param: # 1. String to parse in form 'host[:port]'. host = $(firstword $(subst

Debugging GNU make

拥有回忆 提交于 2019-12-03 00:20:24
问题 Is there a command line way in make to find out which of the prerequisites of a target is not updated? 回答1: make -d should give you more than enough information to debug your makefile. Be warned: it will take some time and effort to analyze the output but loading the output into your favorite editor and doing searches will assist a lot. You can greatly reduce the amount of debugging output if you specify the specific target you're interested in. So if you're only interested in the dodgy

Parallel makefile requires dependency ordering

流过昼夜 提交于 2019-12-02 23:47:15
I have the following piece of makefile: CXXFLAGS = -std=c++0x -Wall SRCS = test1.cpp test2.cpp OBJDIR = object OBJS = $(SRCS:%.cpp=$(OBJDIR)/%.o) all: test1 release: clean test1 test1: $(OBJS) $(CXX) -o $@ $(OBJS) $(OBJDIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -MD -c -o $@ $< -include $(SRCS:.cpp=.d) clean: rm -rf $(OBJDIR)/* .PHONY: all clean release Now if I try to invoke "make -j4 release" the clean target often gets execute in the middle of building files which causes compilation to fail. My question is how to ensure that the clean target has completed before starting the release build. My

Convert Cygwin path to Windows path in a makefile

我的未来我决定 提交于 2019-12-02 22:07:14
How can I convert a Cygwin style path ( /cygdrive/c/foo/bar ) to Windows style ( C:/foo/bar ) (yes, with / going forward) in a GNU makefile? I have the situation of using Cygwin's make with a GCC that does not understand Cygwin style paths, so paths relative to the makefiles location that are produced by make are not accepted by the compiler. Use the shell function to execute the cygpath utility with the -w flag. Example: BAR := /cygdrive/c/foo/bar WIN_BAR := $(shell cygpath -w ${BAR}) cygpath accepts a lot of additional options. See the man page for details. 来源: https://stackoverflow.com

How do I build into a specified directory using the “prefix” option of configure?

岁酱吖の 提交于 2019-12-02 21:54:21
问题 I am trying to build glibc 2.27 on Clear Linux, obtained here: https://www.gnu.org/software/libc/sources.html According to the help, I should build into a directory outside of the source folder using the prefix command. As far as I can tell, I am doing what is described in the installation help: Configuring and compiling the GNU C Library The GNU C Library cannot be compiled in the source directory. You must build it in a separate build directory. For example, if you have unpacked the GNU C