File: Rules.mk

package info (click to toggle)
lockdev 1.0.1-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 204 kB
  • ctags: 75
  • sloc: ansic: 653; makefile: 156; perl: 44; sh: 6
file content (51 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download | duplicates (6)
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
### this fragment of makefile _must_ be included in the makefile
### and this variable ( create_debug_lib ) must be passed to the 
### sub-make to activate this rule. Do this in the debug building 

ifdef create_debug_lib

_SRCDIR_:
	ln -sf . $@

### How does this work?
### a little explanation:
### the build stage (and all the binary) depends from a file not phony
### named _SRCDIR_ which is created in the current working dir as a 
### symlink to . (dot, the current dir), and removed in the clean stage.
### We overwrite the implicit rule to make objects from .c sources,
### producing the asm source file from the .c source seen through the
### _SRCDIR_ symlink. In the rule we change that strange name with the
### absolute pathname where we will store the sources, so that the
### object (and the libraries) will record that name instead that the 
### actual one.
### The purpose is to have a default link from the libraries to the
### place where the debugging binary package will put the sources, so that
### gdb will diplay source lines without _any_ need of strange declarations.

define compile.c
	${COMPILE.c} -S _SRCDIR_/$< -o $*.ss
endef
define compile.cc
	${COMPILE.cc} -S _SRCDIR_/$< -o $*.ss
endef
define the_rest
	sed 's,^.stabs \"_SRCDIR_\/,.stabs \"${abs_src}/,' $*.ss > $*.s
	${COMPILE.s} -o $@ $*.s
	${RM} $*.ss $*.s
endef

# overwriting implicit rule 
%.o: %.c _SRCDIR_
	@echo "=== overwritten rule .o:.c ($@: $^) ==="
	${compile.c}
	${the_rest}

# overwriting implicit rule 
%.o: %.cc _SRCDIR_
	@echo "=== overwritten rule .o:.cc ($@: $^) ==="
	${compile.cc}
	${the_rest}

endif # create_debug_lib

###############################################################################