我有以下GNU makefile:
.PHONY a b c d
a: b c
b: d
c: d
d:
echo HI
Run Code Online (Sandbox Code Playgroud)
我希望目标'd'能够运行两次 - 因为它被b&c指定为依赖项.不幸的是,目标'd'只会被执行一次.运行make的输出将只是'HI',而不是'HI HI'.
我怎样才能解决这个问题?
谢谢!
要澄清,目标是这样的:
subdirs = a b c
build: x y
x: target=build
x: $(subdirs)
y: target=prepare
y: $(subdirs)
$(subdirs):
$(make) -f $@/makefile $(target)
Run Code Online (Sandbox Code Playgroud) 在目标的配方中,我想生成一个处理命令行参数的bash脚本...但是Makefile转义逃脱了我
target:deps echo"./a.out \"$ @ \""> wrapper.a.out
但是,$ @在GNU Makefile中具有特殊含义,这会让事情变得混乱.
试过$ @,$$ @ ......似乎没什么可行的.
那么,这样做的正确方法是什么?
#include<stdio.h>
void print_hello(void);
int factorial(int n);
Run Code Online (Sandbox Code Playgroud)
#include<stdio.h>
#include<functions.h>
int main()
{
print_hello();
printf("\nThe factorial is: %d \n",factorial(5));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
#include<stdio.h>
#include<functions.h>
void print_hello()
{
printf("\nHello World!\n");
}
Run Code Online (Sandbox Code Playgroud)
#include<stdio.h>
#include<functions.h>
int factorial(int n)
{
if(n!=1)
{
return(n*factorial(n-1));
}
else
return 1;
}
Run Code Online (Sandbox Code Playgroud)
exec : \
compile
echo "Executing the object file"
./compile
compile : main.o hello.o factorial.o
echo "Compiling"
gcc -o compile $^
main.o : main.c functions.h
gcc -c main.c -I./INCLUDE -I./SRC
hello.o : hello.c …Run Code Online (Sandbox Code Playgroud) 我有几个扩展的重复模式规则(例如:cpp和cc):
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
@$(CXX) $(CPPFLAGS) -I. -o $@ -c $?
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cc
@$(CXX) $(CPPFLAGS) -I. -o $@ -c $?
Run Code Online (Sandbox Code Playgroud)
有没有办法让一个模式规则在两个扩展上匹配,而不是必须有两个规则?
我想自动检测系统架构,当我在freebsd下编译我的程序,我想要2包括x64和x32但不工作,我试过这样:
ifeq ($(uname -a),i386)
INCDIR += -I../../x32
else
INCDIR += -I../../x64
endif
Run Code Online (Sandbox Code Playgroud)
这有什么不对?当我使用下面的代码在amd64上编译时.当我在i388上编译时不起作用.
当我在amd64上使用makefile下面的代码编译时,请参阅x64目录.当我在i386上使用makefile下面的代码编译时,请参阅x64目录.Soo bassicaly,否则没有任何影响?
我有一个生成文件的python脚本.我想要的是强制它写入特定文件夹中的文件.现在我必须做3个步骤:
cd foo
python ../awesome_script.py
cd ..
Run Code Online (Sandbox Code Playgroud)
有没有什么好的解决方案,我可以在一行中使用一些外部命令,或直接在python解释器中执行此操作?
我正在寻找类似的东西:
python -f foo awesome_script.py
Run Code Online (Sandbox Code Playgroud)
要么
cd_in_and_out_program foo awesome_script.py
Run Code Online (Sandbox Code Playgroud)
之后该指令将在makefile中,因此它可能很难看.
我正在编写一个在Windows和Linux上都可以使用的makefile。因此,我尽可能避免使用特定于OS的Shell命令。
这是我的makefile中的片段,clean最后是函数:
# OS specific part
# -----------------
ifeq ($(OS),Windows_NT)
RM = del /F /Q
RMDIR = -RMDIR /S /Q
MKDIR = -mkdir
ERRIGNORE = 2>NUL || (exit 0)
SEP=\\
else
RM = rm -rf
RMDIR = rm -rf
MKDIR = mkdir -p
ERRIGNORE = 2>/dev/null
SEP=/
endif
PSEP = $(strip $(SEP))
# Definitions for nullstring and space
# -------------------------------------
nullstring :=
space := $(nullstring) #End
# Lists of all files and folders to keep or remove
# …Run Code Online (Sandbox Code Playgroud) GNU Make有-B强制make忽略现有目标的选项.它允许重建目标,但它也会重建目标的所有依赖关系树.我想知道有没有办法强制重建目标而不重建其依赖项(使用GNU Make选项,Makefile中的设置,类似兼容make的软件等)?
问题的插图:
$ mkdir test; cd test
$ unexpand -t4 >Makefile <<EOF
huge:
@echo "rebuilding huge"; date >huge
small: huge
@echo "rebuilding small"; sh -c 'cat huge; date' >small
EOF
$ make small
rebuilding huge
rebuilding small
$ ls
huge Makefile small
$ make small
make: 'small' is up to date.
$ make -B small
rebuilding huge # how to get rid of this line?
rebuilding small
$ make --version | head …Run Code Online (Sandbox Code Playgroud) 我在C ++ 14项目中使用CMake 3.8.2,GNU make 4.2.1和GCC 6.4.0,在构建时我注意到了一个奇怪的行为。我使用CMake在名为“ build”的子文件夹中进行源代码外构建,cmake ..然后运行make。
CMake运行良好,没有任何错误,make会像我期望的那样构建所有源文件,直到完成编译并开始链接它们为止。然后它将失败并显示错误
[ 83%] ...
[100%] Linking CXX executable myproject
/usr/bin/ld: some-source-file.cc.o: undefined reference to symbol '_ZNKSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEE3strEv@@GLIBCXX_3.4.21'
Run Code Online (Sandbox Code Playgroud)
有趣的是,到目前为止,它不显示任何编译器警告,而仅显示上述链接器错误。
现在,当我忽略该错误并简单地运行cmake ..,然后make再次运行(就像我之前所做的那样)时,即使我没有更改任何代码或与CMake相关的文件,我也会得到我的代码应产生的所有编译器警告,并且所有链接都可以正常运行同时。
我可以build通过运行删除目录中的所有文件来重现此行为rm -r *。
这是我的CMakeLists.txt文件:
# Define minimum required CMake version
cmake_minimum_required(VERSION 3.8.2)
# Setting compiler related settings
set(CMAKE_CXX_COMPILER "${CMAKE_SOURCE_DIR}/toolchain/binary/gcc-6.4.0/bin/gcc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion -O2 -lstdc++")
set(CMAKE_CXX_STANDARD 14)
# Define project name
project(MyProject)
# Find source files
file(GLOB_RECURSE …Run Code Online (Sandbox Code Playgroud) 题:
如何在前提条件上禁用隐式规则搜索,同时又确保前提条件确实存在?
背景:
考虑以下初始Makefile:
b: a
@echo MAKING B
cp a b
Run Code Online (Sandbox Code Playgroud)
a是制作所需的文件b。如果文件a存在,则make b运行成功。如果不存在,则会出现以下错误:
make: *** No rule to make target `a', needed by `b'. Stop.`
Run Code Online (Sandbox Code Playgroud)
这正是我们所期望的,但是,在检查的输出时make --debug=a b,我们发现即使a存在,也make正在搜索适合的预定义隐式规则a,以查看是否可以重新生成它。例如,如果文件a.c恰好存在,make则将尝试编译a.c以生成文件a。为避免这种情况,我们为a带有空配方的定义了明确的规则。这给了我们更新的Makefile:
a: ;
b: a
@echo MAKING B
cp a b
Run Code Online (Sandbox Code Playgroud)
现在的问题是make b即使a不存在运行方法,这也会导致失败。a在没有寻找要建立的隐式规则的同时,还有其他方法表明应该存在a吗?我想这样做而不给出a检查其存在的方法。