gnu-make

Getting make to create object files in a specific directory

被刻印的时光 ゝ 提交于 2019-11-26 18:55:51
GNU Make 3.82 gcc 4.7.2 c89 I have the following make file: INC_PATH=-I/home/dev_tools/apr/include/apr-1 LIB_PATH=-L/home/dev_tools/apr/lib LIBS=-lapr-1 -laprutil-1 RUNTIME_PATH=-Wl,-rpath,/home/dev_tools/apr/lib CC=gcc CFLAGS=-Wall -Wextra -g -m32 -O2 -D_DEBUG -D_THREAD_SAFE -D_REENTRANT -D_LARGEFILE64_SOURCE $(INC_PATH) SOURCES=$(wildcard src/*.c) OBJECTS=$(patsubst %.c, %.o, $(SOURCES)) EXECUTABLE=bin/to all: build $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(CFLAGS) -o $@ $(RUNTIME_PATH) $(OBJECTS) $(LIB_PATH) $(LIBS) $(OBJECTS): $(SOURCES) $(CC) $(CFLAGS) -c $(SOURCES) $(LIB_PATH) $

How to get current relative directory of your Makefile?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 17:55:36
问题 I have a several Makefiles in app specific directories like this: /project1/apps/app_typeA/Makefile /project1/apps/app_typeB/Makefile /project1/apps/app_typeC/Makefile Each Makefile includes a .inc file in this path one level up: /project1/apps/app_rules.inc Inside app_rules.inc I'm setting the destination of where I want the binaries to be placed when built. I want all binaries to be in their respective app_type path: /project1/bin/app_typeA/ I tried using $(CURDIR) , like this: OUTPUT_PATH

Force gnu make to rebuild objects affected by compiler definition

*爱你&永不变心* 提交于 2019-11-26 16:07:15
问题 I have a makefile that takes options at the command line make OPTION_1=1 Based on the value it will add additional compiler definitions to a subset of objects. ifeq ($(OPTION_1), 1) CC_FLAGS += -DOPTION_1_ON endif The change in the definition affects the included header file content - a stub or an implementation is exposed to the object files. How can I get make to rebuild the files 'affected' by this option changing? 回答1: I use a file to remember the last value of such options, like this:

What do @, - and + do as prefixes to recipe lines in Make?

两盒软妹~` 提交于 2019-11-26 15:38:58
In the GNU Makefile manual, it mentions these prefixes. If .ONESHELL is provided, then only the first line of the recipe will be checked for the special prefix characters (‘@’, ‘-’, and ‘+’). What do these prefixes do, and where are they mentioned? They control the behaviour of make for the tagged command lines: @ suppresses the normal 'echo' of the command that is executed. - means ignore the exit status of the command that is executed (normally, a non-zero exit status would stop that part of the build). + means 'execute this command under make -n ' (or 'make -t' or 'make -q') when commands

Define make variable at rule execution time

两盒软妹~` 提交于 2019-11-26 14:56:41
In my GNUmakefile, I would like to have a rule that uses a temporary directory. For example: out.tar: TMP := $(shell mktemp -d) echo hi $(TMP)/hi.txt tar -C $(TMP) cf $@ . rm -rf $(TMP) As written, the above rule creates the temporary directory at the time that the rule is parsed . This means that, even I don't make out.tar all the time, many temporary directories get created. I would like to avoid my /tmp being littered with unused temporary directories. Is there a way to cause the variable to only be defined when the rule is fired, as opposed to whenever it is defined? My main thought is to

Why .SECONDARY does not work with patterns (%) while .PRECIOUS does?

大城市里の小女人 提交于 2019-11-26 14:46:00
问题 My question is to understand better what i missed in make process and .SECONDARY purpose vs .PRECIOUS, not to get my script working, since it does work already. I am using make to either open a emacs editor on a file ( java but irrelevant for purpose of this question ) or to create it with a template if not existing. If it works well with existing files, when using generated file it is removed at the end . I added prerequisite in .SECONDARY but didn't help, i had to add it in .PRECIOUS. This

Escaping in makefile

眉间皱痕 提交于 2019-11-26 13:26:34
I'm trying to do this in a makefile and it fails horribly: M_ARCH := $(shell g++ -dumpmachine | awk '{split($1,a,"-");print a[1]}') do you know why? I guess it has to do with escaping, but what and where? It's the dollar sign, in makefiles you'll have to type $$ to get a single dollar sign: M_ARCH := $(shell g++ -dumpmachine | awk '{split($$1,a,"-");print a[1]}') Make is quite lispy when you get down to it. Here's a non-awk version that does the same thing: space := $() # M_ARCH := $(firstword $(subst -,$(space),$(shell g++ -dumpmachine))) all: $(info $(M_ARCH)) 来源: https://stackoverflow.com

Recursive wildcards in GNU make?

拜拜、爱过 提交于 2019-11-26 12:54:32
It's been a while since I've used make , so bear with me... I've got a directory, flac , containing .FLAC files. I've got a corresponding directory, mp3 containing MP3 files. If a FLAC file is newer than the corresponding MP3 file (or the corresponding MP3 file doesn't exist), then I want to run a bunch of commands to convert the FLAC file to an MP3 file, and copy the tags across. The kicker: I need to search the flac directory recursively, and create corresponding subdirectories in the mp3 directory. The directories and files can have spaces in the names, and are named in UTF-8. And I want to

Difference between CPPFLAGS and CXXFLAGS in GNU Make

半城伤御伤魂 提交于 2019-11-26 12:20:05
问题 What\'s the difference between CPPFLAGS and CXXFLAGS in GNU Make? 回答1: CPPFLAGS is supposed to be for flags for the C P re P rocessor; CXXFLAGS is for flags for the C++ compiler. The default rules in make (on my machine, at any rate) pass CPPFLAGS to just about everything, CFLAGS is only passed when compiling and linking C, and CXXFLAGS is only passed when compiling and linking C++. 回答2: By default, CPPFLAGS will be given to the C preprocessor, while CXXFLAGS will be given to the C++ compiler

How to place object files in separate subdirectory

好久不见. 提交于 2019-11-26 11:13:48
I'm having trouble with trying to use make to place object files in a separate subdirectory, probably a very basic technique. I have tried to use the information in this page: http://www.gnu.org/software/hello/manual/make/Prerequisite-Types.html#Prerequisite-Types I get the following output from make: make: *** No rule to make target `ku.h', needed by `obj/kumain.o'. Stop. However ku.h is a dependency not a target (although it's obviously #included within the c source files). When I don't try to use a subdirectory for object files (i.e. miss out the OBJDIR parts) it works fine. Why does make