makefile,make,gnu-make,makefile-project,multiple-makefiles , Autodependency generation in makefiles

Autodependency generation in makefiles


Tag: makefile,make,gnu-make,makefile-project,multiple-makefiles

I am trying to understand how autodependency is generated in makefiles in the given link, i cannot understand the following piece of code:

DEPDIR = .deps
df = $(DEPDIR)/$(*F)

SRCS = foo.c bar.c ...

%.o : %.c
        @$(MAKEDEPEND); \
          cp $(df).d $(df).P; \
          sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
              -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \
          rm -f $(df).d
        $(COMPILE.c) -o [email protected] $<

-include $(SRCS:%.c=$(DEPDIR)/%.P)

I got it from this link. I know it will generate dependency files but I am not able to understand what this line does:

sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
    -e '/^$$/ d' -e 's/$$/ :/' < $(df).d >> $(df).P; \

Can somebody please explain me this code, so many wildcards give me butterflies, i am new to makefiles.


That is a number of distinct commands so break it up.

  1. -e 's/#.*//'

    Delete everything that starts with a # (Comments? Pre-processor directives?)

  2. -e 's/^[^:]*: *//'

    Delete everything up to a : on any that has : it.

  3. -e 's/ *\\$$//'

    Delete line-continuation slashes (and spaces before them) from the end of lines.

  4. -e '/^$$/ d'

    Delete any blank lines.

  5. -e 's/$$/ :/'

    Add : to the end of every line.

This adds explicit targets for every listed dependency file so that make "knows" how to build them to avoid the "No rule to make target" errors. The reasoning here is explained in your link in an earlier section.

Briefly, this creates a .P file with the original prerequisites list, then adds targets to it by taking each line, removing any existing target information and any line continuation (\) characters, then adding a target separator (:) to the end. This works with the values for MAKEDEPEND I suggest below; it’s possible you will need to modify the translation for other dependency generators you might use.


Haskell make recipe fails for Paradox theorem prover using GHC

I am trying to install the paradox theorem prover sourced from here. When I run the makefile this is the command that runs: ghc -optl -static -lstdc++ -I../instantiate -I../minisat/current-base ../minisat/current-base/Solver.or ../minisat/current-base/Prop.or ../instantiate/MiniSatWrapper.or ../instantiate/MiniSatInstantiateClause.or -fglasgow-exts -O2 -static -threaded -main-is Paradox.Main.main --make Paradox.Main -o paradox And it results in several errors like...

How to build a './configure && make && make install' software against a custom library which I also build?

I am building tmux-2.0 from sources on a pretty regular Linux host. First attempt failed as it turned out that the version of libevent installed is older than required, so I proceeded to download and build libevent-2.0.22 from sources (current at the time of writing) first. Building of libevent succeeded...

make error during building webkitgtk

I use UBuntu 14.04 LTS. I need to build webkitgtk 2.8.3 Here is an example instruction which I have used: linuxfromscratch When I run sudo make -j8 I get following log: Scanning dependencies of target JavaScriptCore-4-gir Scanning dependencies of target fake-generated-webkitdom-headers [ 0%] Scanning dependencies of target WebKit2-fake-api-headers Scanning dependencies...

gcc auto dependency full path

I have a simple project - it has a foo.cxx and a bar.h: // bar.h // nothing // foo.cxx #include "bar.h" // nothing else If I include bar.h with ""s, then the dependency file has everything with its full paths: $ g++ -std=c++11 -MP -MMD -MF /home/barry/sandbox/foo.d -c /home/barry/sandbox/foo.cxx -o...

GNU make - depend only on file existence and not modification time

I want to have a makefile in which I have a task a that can only run if a file b exists, but does not need to be re-run if b is updated. How do I do this?

What does $(@:.h=.h.d) mean in GNU make?

I'm maintaining a (horrendously complicated) Makefile, and in some recipes I saw the following: $(@:.h=.h.d) I have absolutely no clue as to how to interpret this, or whether there's any documentation on those characters. Obviously, Google won't work because it thinks I'm typing gibberish. I saw a related question about...

How does MAKE remember the file timestamps

I've found this question which is basically asking the same, but got no real answer. Where is the make's config file / database file where it remembers the file timestamps, so it can tell what changed? I checked and there's no .make or similar in my project, nor in the...

makefile library dependencies - resolve circular dependency

I am trying to build a feature into my makefile which allows me to specify a list of libraries a particular library depends on This will allow dependants of a library to automatically be rebuilt if that library's dependencies are rebuilt, and also have the dependencies added to the link...

Makefile not recompiling on header file change

I have 2 .cpp files : main.cpp A.cpp and few header files in include dir. I am trying to write a makefile that recompiles whenever a header file changes. Now I tried following the method outlines in the example here. However I could not get started. Here is my attempt...

gcc make dependency and object simultaneously

I am using gcc 4.8.2, and I am trying to build both the object file and the dependency file concurrently. This works: $ g++ -std=c++11 -MP -MD -c foo.cxx -o foo.o $ [ -s foo.d ] && [ -s foo.o ] && echo yay yay However, instead of generating foo.d,...

How to export directly in a Makefile?

I want to export something directly in my Makefile so I did a rule like this one : export: export LD_LIBRARY_PATH=./smthing/here And then I call this rule in my $(NAME) $(NAME): $(OBJS) $(CXX) -o $(NAME) $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(export) $(OBJS) is a simple rule to convert all my .cpp into...

Installing twitcurl on OS X

I am attempting to install twitcurl on OS X and have met with some problems. At first, running make would return the clang error: ld: unknown option: -soname. I looked through the responses from other users with similar problems on OS X and found the following advice: In the makefile,...

make: *** No rule to make target 'rm', needed by 'clean.Stop

I am working with cygwin on windows 8.1. I have used the following make file .SUFFIXES : .o .C CFLAGS = -g2 CC =g++ ${CFLAGS} LIBRARIES = -lm .C.o : ${CC} -c $< SOURCE-FILES = sparsegraph.C myvarious.C pairlist.C graphlist.C peo.graph.C choldc.C copy.C metropolis_fns.C likelihood.C metropolis.C OBJECT-FILES = sparsegraph.o myvarious.o pairlist.o...

basic makefile ifeq how to

I am just learning about Makefiles and am having trouble with ifeq. Version = GNU Make 3.82 Here is my simple Makefile: CHECK := 0 CHECK2 := 0 check : @echo "Check=${CHECK}" @echo "Check2=${CHECK2}" ifeq (${CHECK2},${CHECK}) @echo "EQUAL" else @echo "NOT EQUAL" endif Here is the output: Check=0 Check2=0 NOT...

Why does gcc search header files from non-exist folders?

I am trying to build an open source project shark on CentOS 7, and get very weird build errors: make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h', needed by `core/luv/luv.o'. make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h', needed by `core/luv/luv.o'. make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h', needed...

What does the following makefile command do? /no-symbols-control-file

I cam across the following command in a makefile: %-nosyms.$(TARGET).elf: $(PROJECT_OBJECTFILES) $(INTERRUPT_OBJECTFILES) contiki-$(TARGET).a $(CC) $(CFLAGS) -o [email protected] $(filter-out %.a,$^) $(filter %.a,$^) $(filter %.a,$^) $(LDFLAGS) Source: Contiki/cpu/arm/stm32f103/Makefile.stm32f103 . Does this command generate no-symbols-control-file? What is the use of a no symbol image file?...

Fortran: makefile error

I have a fortran main program called solidsolver.f90, and a module called read_mesh.f90. The module contains two subroutines and is used in the main program. I can compile them manually but not with a makefile. My makefile is named makefile.makefile, and it gives me an error: make: *** No targets...

undefined reference to `vtable for implementation' error

I wrote some c++ files and after compiling with out make file it works fine . But when using make file it pop out some errors . My codes are : include directory files : application.h #ifndef APPLICATION_H #define APPLICATION_H #include "employee.h" #include "employee_data.h" #include "employee.h" ...some defintions here... #endif...

NASM: Makefile for library

I'm having trouble building a makefile for a library in nasm, since it requires that you run nasm with one input file at a time. I have tried with the %.o : %.s thing but I'm probably doing it incorrectly since it's not working. Here is what I have: NAME...

Makefile: wildcard and patsubst does not change file source names

I am trying to write a Makefile for my project, all the *.c and *.h files are in a folder called src, and the Makefile looks like this -- CC := gcc CFLAGS := -g -Wall -ansi -pedantic -std=gnu99 LDFLAGS := -lm INCLUDES := $(wildcard src/*.h) IFLAGS := $(addprefix -I/,$(INCLUDES))...

what does -wl, --start-group mean in make file?

I have this in my Make file.. # Create list of object files # LIB_OBJS = -Wl,--start-group \ $(T_OBJ_DIR)/Source1.o \ $(T_OBJ_DIR)/Source2.o \ $(T_OBJ_DIR)/Source3.o \ $(T_OBJ_DIR)/Source4.o \ $(T_OBJ_DIR)/Source5.o \ -Wl,--end-group \ Could anyone please explain What "-Wl,--start-group" and "-Wl,--end-group" mean?...

Link target to libraries

I have a "CMakified" version of CryptoPP and I am using CMake-GUI to create a MakeFile which ming-make could process as shown in the image below. The "MakeFile" creation was successful but when I executed mingw32-make.exe I got below errors at the very end. Linking CXX executable cryptest.exe CMakeFiles\cryptest.dir/objects.a(test.cpp.obj):test.cpp:(.text+0x8e82): undefined...

Makefile overriding default implicit rule

Why this rule cannot override the default implicit rule ? When make is invoked like: make myapp (suppose myapp.c is there). The make runs the default command to build and link the program instead the commands defined in this implicit rule: #... omitted code LCUS=$(LIBS)/libcus.a #... omitted code % :...

Makefile with two targets and two languages

I work with C and C++ and thanks to this answer I was able to compile and run my project. Now I am writing a makefile to spare time. But things are getting complicated : Project structure project makefile client bin src c cc java server ... # Directories #...

A make rule for verbosity

Typically we have this in a Makefile %.o:%.c $(cc) $(flags) -o [email protected] -c $< When the amount of flags is huge, I feel better to write this instead %.o:%.c $(info $(cc): $< --> [email protected]) @$(cc) $(flags) -o [email protected] -c $< However it can be useful to sometime see everything. So...

Can Make be made to understand that a/../z and b/../z are the same location?

I have a somewhat large and complex Makefile setup that postprocesses some data files. Overall it work quite well, but I have run into an annoying issue where Make builds the same target many times over under different directory names. As a simple example, consider the Makefile foo : 1/foo...

non-recursive make constrict targets

Based on this paper, I'm trying to rework a subset of my build system to be non-recursive. It's actually working pretty well. By default, I have part of my makefile include all the relevant directories via a template: DIRECTORIES = dirA dirB ... etc ... define import_template dir := $(1)...

How to correctly make install of binaries and data after compile in linux?

After make of sources I have compiled executable file and data directory with images for it. What should I do at "make install" phase to correctly install these files to the linux system? And how then application can find installed data (in case when binary and data are placed in...

Makefile: two different executables taking two overlapping subsets of code

This is my situation, I am trying to write a Makefile for my c program, it has these components -- 2 Headers: src/header1.h src/header2.h N Sources: src/src1.c src/src2.c src/src3.c ... src/srcn.c 2 Mains: src/main1.c src/main2.c main1.c and main2.c takes all the same src*.c and header*.h files, but in a different...

What's the difference between [email protected] and $1 when there is only one parameter?

There are some C code: apple.c #include<stdio.h> int main(void) { printf("apple\n"); return 0; } Makefile apple: gcc -c [email protected] gcc [email protected] -o [email protected] $ make apple and it works perfectly. But if I modify Makefile as: apple: gcc -c $1.c gcc $1.o -o $1 $ make apple It does not...

makefile read reused variable inside recipe

In trying to implement nonrecursive make, I have a which looks like: ############ # Enter Stack ############ sp := $(sp).x dirstack_$(sp) := $(d) d := $(dir) .. setup things like OBJECTS_$(d), DEPS_$(d), TARGET_$(d), etc ... ############ # Exit Stack ############ -include $(DEPS_$(d)) d := $(dirstack_$(sp)) sp := $(basename $(sp))...

Makefile: no rule to make target with variables

I'm trying to write a Makefile that when I add some deps in my application I just have to change DEPS_NAME variable, but something is wrong and I can't figure out what. I know that this is not the only problem with this Makefile, I just started to study this...

Nested For loop in makefile

I am trying to loop through the .c files in a specific directory through the makefile. i used the following code, but it seems not working: DIR= Sources \ Sources_2 @for entry in ${DIR} ; \ do \ @for i in $${entry}/*.c ; \ do \ echo "Processing $${i}"; \...

Makefiile with many flags

I am trying to learn how a Makefile should look like, when it comes to the flags, especially the linking ones. Here is my Makefile: OBJS = n.o SOURCE = n.cpp # HEADER = there are no header files, so I commented that OUT = test CXX = ../mpich-install/bin/mpic++ FLAGS...

xcode 6.3.2 external build

I'm trying to compile an existing c++ project, originally developed on linux with gcc. The only external library is GSL (GNU Scientific Library). I have created an external build tool project to use xcode's debugger, but I currently have two issues. 1) When I try to build in xcode it...

Dot in front of variables in make files

I am not able to figure out what does a dot . in front of a variable in makefile does. For e.g.: SOURCEDIRS = . $(PROJECTDIRS) $(TARGET_DIRS_CONCAT) vpath %.c $(SOURCEDIRS) It would be great if someone could tell me. Thanks!...

Why Make doesn't recognize my variable?

I have a short Make script, which works if I put the Build directory in as a string manually myself instead of as a variable: CC = gcc CFLAGS = -O2 -g -Wall -fmessage-length=0 LDFLAGS = SRCDIR = Src BUILDDIR = Build SRCS = $(SRCDIR)/Main.c OBJS = $(SRCS:.c=.o) LIBS =...

What are the steps to setup an RTOS application on STM32 using Linux and Makefiles instead of using Windows based IDEs?

I am using STM32F4 Discovery board to develop a simple application to on-board accelerometer while simultaneously lighting respective LEDs mounted around the accelerometer device. I want to use any RTOS but I am unable to decide which one since I am new to using RTOS. If anyone could elaborate the...

add dependencies to a library, and add them to a binary which depends on that library

What I have: I have a non-recursive makefile which searches for files, and includes them modules := $(shell find . -name include $(modules) If I want to create a static library, the looks like this: $(eval $(call make-lib, test_lib)) Which will find a list of all .cpp...