Generic rule from makefile to CMake

In CMake you can always declare your own compiler language. So in your case you can e.g. do: cmake_minimum_required(VERSION 2.8) project(MakeBarFromFoo NONE) set( CMAKE_FOO_COMPILE_OBJECT “make_bar_from_foo <SOURCE> <OBJECT>” ) file(GLOB SRCS “*.foo”) add_library(my_rule OBJECT ${SRCS}) set_source_files_properties(${SRCS} PROPERTIES LANGUAGE FOO) Then you can simply work with it as you would with other object library targets. But you … Read more

Building C-program “out of source tree” with GNU make

Here’s the Makefile I’ve added to the documentation (currently in review so I’ll post it here) : # Set project directory one level above the Makefile directory. $(CURDIR) is a GNU make variable containing the path to the current working directory PROJDIR := $(realpath $(CURDIR)/..) SOURCEDIR := $(PROJDIR)/Sources BUILDDIR := $(PROJDIR)/Build # Name of the … Read more

Create directories using make file

In my opinion, directories should not be considered targets of your makefile, either in technical or in design sense. You should create files and if a file creation needs a new directory then quietly create the directory within the rule for the relevant file. If you’re targeting a usual or “patterned” file, just use make‘s … Read more

crti.o file missing

crti.o is the bootstrap library, generally quite small. It’s usually statically linked into your binary. It should be found in /usr/lib. If you’re running a binary distribution they tend to put all the developer stuff into -dev packages (e.g. libc6-dev) as it’s not needed to run compiled programs, just to build them. You’re not cross-compiling … Read more

How to use LDFLAGS in makefile

Your linker (ld) obviously doesn’t like the order in which make arranges the GCC arguments so you’ll have to change your Makefile a bit: CC=gcc CFLAGS=-Wall LDFLAGS=-lm .PHONY: all all: client .PHONY: clean clean: $(RM) *~ *.o client OBJECTS=client.o client: $(OBJECTS) $(CC) $(CFLAGS) $(OBJECTS) -o client $(LDFLAGS) In the line defining the client target change … Read more

What’s the opposite of ‘make install’, i.e. how do you uninstall a library in Linux?

make clean removes any intermediate or output files from your source / build tree. However, it only affects the source / build tree; it does not touch the rest of the filesystem and so will not remove previously installed software. If you’re lucky, running make uninstall will work. It’s up to the library’s authors to … Read more