Makefile Notes
Implicit Make Rule
%.o:%.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
Target-specific Variables
ex:
target1: CFLAGS = -IINCLUDEPATH1
target1: LDLIBS = -lLIB1
target1: target1.o misc.o
- Makefile - change variable value depending on a target
- Change Makefile variable value
- How to compile different c files with different CFLAGS using Makefile?
- What is the best approach to use different CFLAGS for the same source files?
LDFLAGS & LDLIBS
LDLIBS
is for libraries, LDFLAGS
should be used for flags/search paths (-L)
Auto Dependency
ex:
Gpp = g++
srcs = $(wildcard *.cpp)
objs = $(srcs:.cpp=.o)
deps = $(srcs:.cpp=.d)
test: $(objs)
$(Gpp) $^ -o $@
%.o: %.cpp
$(Gpp) -MMD -MP -c $< -o $@
.PHONY: clean
# $(RM) is rm -f by default
clean:
$(RM) $(objs) $(deps) test
-include $(deps)
Others
comments powered by Disqus