Build
How to avoid full compilation for a small change in header file in C
Sep 13th
Sometimes it is very annoying to wait for full compilation when a small and non-invasive change is made in a common header file that is included by many C files. This typically happens due to header file dependency rules. If you are sure that your change doesn’t really affect other C files expect a few, you change the time stamp of the modified header to a date in past. Also you should change the time stamp of affected C files to current. This ensures that no other files compile except the ones for which you changed the time stamp.
Identifying the More >
How to build in silent mode using GNU make
Aug 19th
Use the following command for absolutely silent build
make -s
Use the following command for absolutely silent build except printing directory before and after processing.
make -s -w
Why GNU make compiles even if there are no modified files
Dec 8th
Some times GNU Make continue to compile some files even if there are no modifications. Typically it happens if you have transferred the files from some other system whose time is set to future. As while transferring files using tarball (archive created by tar command) retains the time stamps of the files, GNU Make thinks that those files are modified and keeps compiling them all the time.
To get rid of this problem, just set time stamp of all source files to current date and time of the system. You can use “touch” command as shown below.
[neo@techpulp ~]# find . -iname More >
Why GNU Make always says `target’ is up to date
Dec 5th
The GNU make expects the rule target to be files by default. That’s why it first checks the presense of a file/directory with the name specified in the rule. For example GNU make attempts to find if a file with name “target1″ with the following Makefile.
target1: prog prog: one.o two.o gcc $^ -o prog
If by chance you have a file or directory with name “target1” in the same directory, GNU Make interprets its last modified date. Because of that some times Make doesn’t compile anything saying target is up to date even if some of the dependencies are changed.
It is More >
GNU Make – How to compile all c files in present directory
Dec 5th
The “shell” built-in function supported by GNU Make can be used to get the list of C source files in a directory. Then a list of corresponding object files can be created by replacing the file extension in the file list. The following example shows how to compile all C source files present in the current directory to generate an executable named “target“. If you are doing copy and paste of the following example, ensure that you place TAB for all commands under each rule. Otherwise GNU Make complains about “missing separator” error.
TARGET=target SRCS=$(shell ls *.c) OBJS=$(SRCS:.c=.o) all: $(TARGET) $(TARGET):$(OBJS) More >
How to clean multiple sub-directories in Makefile
Oct 23rd
The following example assumes that all sub-directories are listed in $(SUBDIRS) variable. All the entries in $(SUBDIRS) can be iterated using a “for” loop as shown below and “make clean” can be run in each directory.
SUBDIRS = dir1 dir2 dir3 clean: for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
Note that if you doing are copy-n-paste of the above snippet, the “for” statement should be indented with a TAB. Otherwise it will result in make error.
In the above example “clean” rule can be replaced with any other rule.
The -C option tells GNU make to change to a specific directory before reading the More >


Recent Comments