forked from flightno23/OS161
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os161.hostprog.mk
107 lines (93 loc) · 3.09 KB
/
os161.hostprog.mk
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
#
# OS/161 build environment: build a host-system program
#
# Usage:
# TOP=../..
# .include "$(TOP)/mk/os161.config.mk"
# [defs go here]
# .include "$(TOP)/mk/os161.hostprog.mk"
# [any extra rules go here]
#
# Variables controlling this file:
#
# PROG Name of program to generate.
# SRCS .c and .S files to compile.
#
# HOST_CFLAGS Compile flags.
# HOST_LDFLAGS Link flags.
# HOST_LIBS Libraries to link with.
#
# HOSTBINDIR Directory under $(OSTREE) to install into,
# e.g. /hostbin. Should have a leading slash.
# If not set, the program goes in
# $(TOOLDIR)/hostbin instead.
#
# Note that individual program makefiles should only *append* to
# HOST_CFLAGS, HOST_LDFLAGS, and HOST_LIBS, not assign them. Otherwise
# stuff set by os161.config.mk will get lost and bad things will
# happen.
#
# This is set up so it can be used together with os161.prog.mk if
# necessary.
#
# Real name
_PROG_=host-$(PROG)
# Directory to install into
.if defined(HOSTBINDIR)
_INSTALLDIR_=$(INSTALLTOP)$(HOSTBINDIR)
.else
_INSTALLDIR_=$(TOOLDIR)/hostbin
.endif
# We may want these directories created. (Used by os161.baserules.mk.)
MKDIRS+=$(MYBUILDDIR)
MKDIRS+=$(_INSTALLDIR_)
.if defined(HOSTBINDIR)
MKDIRS+=$(OSTREE)$(HOSTBINDIR)
.endif
# Default rule: create the program.
# (In make the first rule found is the default.)
all: $(MYBUILDDIR) .WAIT $(MYBUILDDIR)/$(_PROG_)
# Now get rules to compile the SRCS.
.include "$(TOP)/mk/os161.hostcompile.mk"
# Further rules for programs.
# Clean: delete extraneous files.
clean: cleanhostprog
cleanhostprog:
rm -f $(MYBUILDDIR)/$(_PROG_)
#
# Install: we can install into either $(INSTALLTOP) or $(OSTREE).
# When building the whole system, we always install into the staging
# area. However, if you're working on a particular program it is
# usually convenient to be able to install it directly to $(OSTREE)
# instead of doing a complete top-level install.
#
# Note that we make a hard link instead of a copy by default to reduce
# overhead.
#
install-staging: $(_INSTALLDIR_) .WAIT $(_INSTALLDIR_)/$(_PROG_)
$(_INSTALLDIR_)/$(_PROG_): $(MYBUILDDIR)/$(_PROG_)
rm -f $(.TARGET)
ln $(MYBUILDDIR)/$(_PROG_) $(.TARGET) || \
cp $(MYBUILDDIR)/$(_PROG_) $(.TARGET)
.if defined(HOSTBINDIR)
install: install-hostprog
install-hostprog: $(OSTREE)$(HOSTBINDIR) $(MYBUILDDIR)/$(_PROG_)
rm -f $(OSTREE)$(HOSTBINDIR)/$(_PROG_)
ln $(MYBUILDDIR)/$(_PROG_) $(OSTREE)$(HOSTBINDIR)/$(_PROG_) || \
cp $(MYBUILDDIR)/$(_PROG_) $(OSTREE)$(HOSTBINDIR)/$(_PROG_)
.else
install:
@echo "Nothing to manually install"
.endif
# Always implicitly include the compat library.
_COMPATLIB_=$(TOOLDIR)/hostlib/libhostcompat.a
# Link the program.
$(MYBUILDDIR)/$(_PROG_): $(HOST_OBJS) $(_COMPATLIB_)
$(HOST_LDCC) $(HOST_LDFLAGS) $(HOST_OBJS) $(HOST_LIBS) $(_COMPATLIB_) \
-o $(.TARGET)
# Mark targets that don't represent files PHONY, to prevent various
# lossage if files by those names appear.
.PHONY: all clean cleanhostprog install-staging install install-hostprog
# Finally, get the shared definitions for the most basic rules.
.include "$(TOP)/mk/os161.baserules.mk"
# End.