File: rules

package info (click to toggle)
mocka 9905-2
  • links: PTS
  • area: non-free
  • in suites: potato, sarge, woody
  • size: 5,436 kB
  • ctags: 160
  • sloc: asm: 23,203; makefile: 124; sh: 102; ansic: 23
file content (164 lines) | stat: -rwxr-xr-x 4,066 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#! /usr/bin/make -f

MOCKADRV :=	$(shell command -v mocka 2>/dev/null || true)
ifeq ($(strip $(MOCKADRV)),)
MOCKA	:=	MOCKADIR=$(shell pwd) $(shell pwd)/bin/mc
else
MOCKA	:=	$(MOCKADRV)
endif

# Installation directories
PKGDIR  :=	$(shell pwd)/debian/tmp
BINDIR	:=	$(PKGDIR)/usr/bin
LIBDIR	:=	$(PKGDIR)/usr/lib/mocka
SCRIPTDIR :=	$(PKGDIR)/usr/share/mocka
MANDIR	:=	$(PKGDIR)/usr/share/man
DOCDIR  :=	$(PKGDIR)/usr/share/doc/mocka

# Things to build

LIB_MODULES = 	$(wildcard lib/*.mi)
LIB_DEFS =	$(wildcard lib/*.md)
C_MODULES = 	$(wildcard lib/*.c)
ASM_MODULES = 	$(wildcard lib/*.s)
RTS_MODULES =	sys/M2RTS-elf.s
LIB_OBJS = 	$(LIB_MODULES:.mi=.o) $(LIB_DEFS:.md=.d) $(LIB_MODULES:.mi=.r) \
		$(RTS_MODULES:.s=.o)  \
		$(C_MODULES:.c=.r) $(C_MODULES:.c=.o)		\
		$(ASM_MODULES:.s=.r) $(ASM_MODULES:.s=.o)

SCRIPTS =	$(addprefix debian/, asm link list)
BINARIES = 	$(addprefix sys/, Lister Unlister)

# Build the mocka compiler "Mc" in src
# This target triggers compilation of the compiler and utilities 
# by having dependencies on them. The actual compilation code is at 
# the end of this file.

stamp/build:	stamp/patched $(LIB_OBJS) src/Mc $(BINARIES) 
	touch $@

# Install the compiler

stamp/install:	stamp/build
	dh_testdir
	dh_testroot
	dh_installdirs

# Install compiler and utilities
	install -s src/Mc $(LIBDIR)/mc
	install -s $(BINARIES) $(LIBDIR)

# Install library object files
	install -m 644 $(LIB_OBJS) $(LIBDIR)
	strip --strip-debug $(LIBDIR)/*.o

# Install definition modules for reference
	install -m 644 $(LIB_DEFS) $(DOCDIR)/lib

# Install compiler driver
	install $(SCRIPTS) $(SCRIPTDIR)
	install debian/mocka $(BINDIR)

# Install manpage
	install -m 644 man1/mc.1 $(MANDIR)/man1/mocka.1

	touch $@

clean:
	dh_testdir
	dh_testroot
	-test -f stamp/patched && 				\
		patch -d src -R <patches/setup && rm stamp/patched
	-test -f stamp/fixed-missing && rm src/Emit.mi
	rm -f src/Mc $(LIB_OBJS) $(BINARIES) src/*.[ord] lib/tst.r	\
	      $(addsuffix .[ro], $(BINARIES))
	dh_clean
	rm -Rf patches stamp

binary-arch:	stamp/install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installchangelogs
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Somehow upstream managed to lose the Emit.mi file from the current 
# distribution. It was included in 9903 though so I included that file
# in the package. As it is generated and the source did not change 
# (I can't regenerate it since I don't have access to BEG :(()
# I assume that the old file still works.

stamp/fixed-missing:	stamp/exists
	test -f src/Emit.mi || cp debian/Emit.mi src/
	touch $@

# The current source files have some kind of conditional compilation. I 
# don't know how to trigger that by using the mocka command line so I 
# am using awk to setup the files accordingly. A log of what was done 
# is in patches/setup after this target. Note that this target is not 
# omnipotent...

stamp/patched:	stamp/fixed-missing patches/exists
	rm -f patches/setup
	cd src;						\
	for i in *.m[di]; do				\
	  echo -n Patching $$i...;			\
	  awk <$$i >$$i.new '				\
	  	/^%\( CGMOBIL/	{ opened=1; next }	\
	  	/^%\( Debug/	{ opened=1; next }	\
		/^%\( I386/	{ opened=1; next }	\
		/^%\)/	{ if(opened) {opened=0; next} }	\
				{ print }'; 		\
	  diff -u $$i $$i.new >>../patches/setup;	\
	  mv $$i.new $$i; 				\
	  echo done;					\
	done
	touch $@

# Building of Modula 2 binaries

.SUFFIXES:	.mi
%	:	%.mi
	@cd $(@D) && rm -f $(@F).o $(@F).r; echo p $(*F) | $(MOCKA)

# Building symbol files

.SUFFIXES:	.d .md
%.d	:	%.md
	@cd $(@D) && echo s $(*F) | $(MOCKA)

# Building object files

.SUFFIXES:	.o .r
%.o %.r	:	%.mi
	@cd $(@D) && echo c $(*F) | $(MOCKA)

# Assembling .s files
.SUFFIXES:	.s
%.o	:	%.s
	as -o $@ $<

# Auxilary targets for creating directories

stamp/exists:
	test -d stamp || mkdir stamp
	touch $@

patches/exists:
	test -d patches || mkdir patches
	touch $@

install:	stamp/install
build:		stamp/build
binary:		binary-arch
binary-indep:

.PHONY:	build clean binary-indep binary-arch binary install