about summary refs log tree commit diff
path: root/Makefile.lib
blob: 5d9910e35b7848c7a9c0c7c10216d35dc5b8b388 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
default: all

here = $(dir $(lastword $(MAKEFILE_LIST)))

LIBS =

QUIET = @

%.o: %.cc
	$(QUIET) g++ -o $@ -c $< -g -fPIC $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP

%.o: %.c
	$(QUIET) gcc -o $@ -c $< -g -fPIC $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP


# Generate Make rules for libraries.
libs_list :=

define LIBS_template =
  _d := $$($(1)_DIR)
  _objs := $$(foreach src, $$($(1)_SOURCES), $$(_d)$$(basename $$(src)).o)
  _libs := $$(foreach lib, $$($(1)_LIBS), $$(lib).a)
  _lib := $$(_d)$(1).a

  $$(_lib): $$(_objs)
	$(QUIET) ar crs $$@ $$?

  # Propagate CXXFLAGS to the individual object files.
  $$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))

  include $$(wildcard $$(_d)/*.dep)

  clean_list += $$(_d)*.a $$(_d)*.o $$(_d)*.dep
  libs_list += $$(_lib)
endef


# Generate Make rules for programs.
programs_list :=

define PROGRAMS_template =
  _d := $$($(1)_DIR)
  _objs := $$(foreach src, $$($(1)_SOURCES), $$(_d)$$(basename $$(src)).o)
  _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_DIR)$$(lib).a)
  _prog := $$(_d)$(1)

  $$(_prog): $$(_objs) $$(_libs)
	$(QUIET) g++ -o $$@ $$^ $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS))

  # Propagate CXXFLAGS to the individual object files.
  $$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))

  clean_list += $$(_prog) $$(_d)*.o $$(_d)*.dep
  programs_list += $$(_prog)
endef


# Cleaning stuff.
clean_list :=

clean:
	rm -fv $(clean_list)

dryclean:
	@echo $(clean_list)