summaryrefslogtreecommitdiff
path: root/Makeconf
blob: 609d8311c19b01a25d72c2f7edfffa118ea9eb3a (plain)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# Generic configuration for Hurd compilation

# Directory makefiles should set the variable makemode to either
# `server' if they compile and install a single program for /hurd
# `utility' if they compile and install a single program for /bin
# `servers' if they compile and install multiple programs for /hurd
# `utilities' if they compile and install multiple programs for /bin
# `library' if they compile and install a library
# `misc' if they do none of those

# Every makefile should define
# SRCS (all actual source code)
# LCLHDRS (all source headers in this directory [NOT MiG created])
# REMHDRS (all Hurd headers in other directories [NOT .defs files])

# Types `server', `utility', and `library' should define
# OBJS (all .o files used to produce the target).

# Types `server', `utility', `servers', and `utilities' should define
# HURDLIBS (all Hurd libraries used, omitting the dirname and the .a.)

# Types `server' and `utility' should define
# OTHERLIBS (all other libraries used)
# target (the name of the program built)

# Types `servers' and `utilities' should define
# targets (the names of all the programs built)

# Type `library' should define
# libname (the name of the library, without .a.)
# installhdrs (header files that should be installed in /include)


# Put this first so it's the default
all:


# This is the directory into which Hurd cross-building tools are placed
hurdinst := /home/gd3/hurdinst

# This is the directory which serves as root for the Hurd.
hostname := $(shell hostname)
hurdroot-douglas.gnu.ai.mit.edu = /home/hm2/hurdroot
hurdroot-ernst.gnu.ai.mit.edu = /home/hm1/hurdroot
hurdroot := $(hurdroot-$(hostname))

# This is the device with the filesystem mounted as $(hurdroot)
hurdrootdev := /dev/hd0f

# This is the directory containing the top-level Hurd source (and this file).
hurdsource := /home/gd3/gnu/hurd

# Where to find various things for compilation:

includedir := $(hurdinst)/include

startup := $(hurdinst)/lib/crt0.o
libc := $(hurdinst)/lib/libc.a

# END CONFIGURATION AREA


# Decode makemode:


ifeq ($(makemode),server)
 doinst := one
 installationdir := $(hurdroot)/hurd
 clean := yes
 cleantarg := $(target)
endif

ifeq ($(makemode),utility)
 doinst := one
 installationdir := $(hurdroot)/bin
 clean := yes
 cleantarg := $(target)
endif

ifeq ($(makemode),servers)
 doinst := many
 installationdir := $(hurdroot)/hurd
 clean := yes
 cleantarg := $(targets)
endif

ifeq ($(makemode),utilities)
 doinst := many
 installationdir := $(hurdroot)/bin
 clean := yes
 cleantarg := $(targets)
endif

ifeq ($(makemode),library)
 clean := yes
 cleantarg := $(libname).a
endif



# Hurd libraries
libthreads := $(hurdsource)/libthreads/libthreads.a
libports := $(hurdsource)/libports/libports.a
libioserver := $(hurdsource)/libioserver/libioserver.a
libpager := $(hurdsource)/libpager/libpager.a
libfshelp := $(hurdsource)/libfshelp/libfshelp.a
libdiskfs := $(hurdsource)/libdiskfs/libdiskfs.a
libtrivfs := $(hurdsource)/libtrivfs/libtrivfs.a
alllibs := libthreads libports libioserver libpager libfshelp libdiskfs\
	libtrivfs

# Finding binaries
include $(hurdsource)/Maketools

# Flags for compilation.  
# It is important to have this inclusion first; that picks up our 
# library header files locally rather than from installed copies.
CPPFLAGS := -I$(hurdsource)
CFLAGS := -Wall -Wno-parentheses -g


# Standard targets

# Installation
ifeq ($(doinst),one)
all: $(target)
install: $(target)
	$(INSTALL_BIN) $(target) $(installationdir)/$(target)
endif

ifeq ($(doinst),many)
all: $(targets)
install: $(targets)
	for i in $(targets) ; do $(INSTALL_BIN) $$i $(installationdir)/$$i ; done
endif

ifeq ($(makemode),library)
all: $(libname).a
install: $(libname).a $(installhdrs)
	cp $(installhdrs) $(includedir)/hurd/
	cp $(libname).a $(hurdinst)/lib/$(libname).a
	ranlib $(hurdinst)/lib/$(libname).a
endif

# Provide default.
install:


# Each word of $(HURDLIBS) is a library name `libfoo', which is defined as
# a variable above with the complete file name to find it.
# Yippee!  A use for computed variable references!
HURDLIBS-files := $(foreach var,$(HURDLIBS),$($(var)))
#HURDLIBS-libs := $(foreach lib,$(HURDLIBS-files), \
#			   -L$(dir $(lib)) \
#			   $(patsubst lib%.a,-l%,$(notdir $(lib))))

# Building the target
ifeq ($(doinst),one)
$(target): $(OBJS) $(HURDLIBS-files) $(OTHERLIBS) $(libc)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(target) $(link-objects)
# Don't use $^ to collect the args to the link because $^ omits duplicates.
#link-objects = $(OBJS) $(HURDLIBS-files) $(OTHERLIBS)
# -lg avoids "No input files" error.
link-objects = -nostdlib -Wl,$(subst $(empty) ,$(comma),$(strip \
	       $(startup) $(OBJS) -\( $(HURDLIBS-files) $(OTHERLIBS) -\))) \
	       $(libc)  -lg
empty =
comma = ,
endif


ifeq ($(makemode),library)
$(libname).a: $(OBJS)
	rm -f $(libname).a
	$(AR) r $@ $^
	$(RANLIB) $@
endif

# Making a snapshot
distfiles = Makefile ChangeLog $(SRCS) $(LCLHDRS) $(DIST_FILES)
lndist: $(distfiles) $(hurdsource)/hurd-snap/$(dir) FORCE
	ln $(distfiles) $(hurdsource)/hurd-snap/$(dir)
 
ifeq ($(dir),.)
$(hurdsource)/hurd-snap/$(dir):
else
$(hurdsource)/hurd-snap/$(dir):
	mkdir $(hurdsource)/hurd-snap/$(dir)
endif

# TAGS files
ifneq ($(dir),.)
TAGS: $(SRCS) $(LCLHDRS) $(REMHDRS) $(OTHERTAGS)
	etags -o $@ $(HURDLIBS:-i ../%/TAGS) $(SRCS) \
	      $(LCLHDRS) $(REMHDRS) $(OTHERTAGS)
endif


# Cleaning
ifeq ($(clean),yes)
clean:
	rm -f *.o *Server.c *User.c *_S.h *_U.h $(cleantarg)
ifneq ($(makemode),library)
relink:
	rm -f $(cleantarg)
endif
endif
clean:
relink:



# Subdependencies

# Mounting $(hurdroot)
ifeq ($(hurdroot),)
$(hurdroot): FORCE
	@echo Cannot do install on this machine.
	false
else
$(hurdroot): $(hurdroot)/mounted
$(hurdroot)/mounted:
	fsck -p $(hurdrootdev)
	mount $(hurdrootdev)
endif

# Building Hurd libraries
$(foreach lib,$(alllibs),$(hurdsource)/$(lib)/%.a): FORCE
	$(MAKE) -C $(dir $@) $(notdir $@)


# How to build RPC stubs

# User settable variables:
# 	MIGSFLAGS	   flags to CPP when building server stubs and headers
#	foo-MIGSFLAGS	   same, but only for interface `foo'
# 	MIGCOMSFLAGS	   flags to MiG when building server stubs and headers
#	foo-MIGCOMSFLAGS   same, but only for interface `foo'
# 	MIGUFLAGS	   flags to CPP when building user stubs and headers
#	foo-MIGUFLAGS	   same, but only for interface `foo'
# 	MIGCOMUFLAGS	   flags to MiG when building user stubs and headers
#	foo-MIGCOMUFLAGS   same, but only for interface `foo'
#	CPPFLAGS	   flags to CPP

hurddefs := $(notdir $(basename $(wildcard $(hurdsource)/hurd/*.defs)))
ht := $(hurdsource)/hurd/hurd_types.defs

# Implicit rules for building server and user stubs from mig .defs files.
%_S.h %Server.c: %.defs
	$(CPP) $(CPPFLAGS) $(MIGSFLAGS) $($*-MIGSFLAGS) -DSERVERPREFIX=S_ $< \
	| $(MIGCOM) $(MIGCOMSFLAGS) $($*-MIGCOMSFLAGS) \
		    -sheader $*_S.h -server $*Server.c \
		    -user /dev/null -header /dev/null
%_U.h %User.c: %.defs
	$(CPP) $(CPPFLAGS) $(MIGUFLAGS) $($*-MIGUFLAGS) $< \
	| $(MIGCOM) -user $*User.c -server /dev/null -header $*_U.h


# Where to find .defs files.
vpath %.defs $(hurdsource)/hurd:$(includedir)/mach:$(includedir)/device

# Files generated from the Hurd .defs files depend on hurd_types.defs.
$(foreach if,$(hurddefs),$(if)_S.h $(if)Server.c $(if)_U.h $(if)User.c): $(ht)

FORCE: