xref: /illumos-kvm-cmd/Makefile.joyent (revision 980ed28b)
1#
2# Copyright (c) 2018, Joyent, Inc.
3#
4# Permission is hereby granted, free of charge, to any person obtaining a copy
5# of this software and associated documentation files (the "Software"), to deal
6# in the Software without restriction, including without limitation the rights
7# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8# copies of the Software, and to permit persons to whom the Software is
9# furnished to do so, subject to the following conditions:
10#
11# The above copyright notice and this permission notice shall be included in
12# all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20# THE SOFTWARE.
21#
22
23include		$(PWD)/../../../build.env
24
25PROTO_AREA =	$(PWD)/../../../proto
26STRAP_AREA =	$(PWD)/../../../proto.strap
27KERNEL_SOURCE =	$(PWD)/../../illumos
28MDB_SOURCE =	$(KERNEL_SOURCE)/usr/src/cmd/mdb
29CTFBINDIR=	$(KERNEL_SOURCE)/usr/src/tools/proto/*/opt/onbld/bin/i386
30CSTYLE =	$(KERNEL_SOURCE)/usr/src/tools/scripts/cstyle
31CC =		$(STRAP_AREA)/usr/bin/gcc
32INSTALL =	/usr/sbin/install
33
34QEMU_CPPFLAGS = \
35	-DTARGET_PHYS_ADDR_BITS=64 \
36	-D__EXTENSIONS__
37
38DMOD_CPPFLAGS = \
39	$(QEMU_CPPFLAGS) \
40	-D_KERNEL \
41	-DTEXT_DOMAIN="SUNW_OST_OSCMD" \
42	-D_TS_ERRNO \
43	-D_ELF64 \
44	-Ui386 \
45	-U__i386 \
46	-isystem $(PROTO_AREA)/usr/include \
47	-I. \
48	-Ihw
49
50ALWAYS_CFLAGS = \
51	-fident \
52	-fno-builtin \
53	-nodefaultlibs \
54	-Wall \
55	-Werror \
56	-fno-inline-functions
57
58# Skip dubious optimizations in later GCCs
59ifneq ($(PRIMARY_COMPILER_VER),4)
60ALWAYS_CFLAGS += -fno-aggressive-loop-optimizations
61endif
62
63USER_CFLAGS = \
64	-finline \
65	-gdwarf-2 \
66	-std=gnu89
67
68DMOD_CFLAGS = \
69	$(ALWAYS_CFLAGS) \
70	$(USER_CFLAGS) \
71	-m64 \
72	-fno-strict-aliasing \
73	-fno-unit-at-a-time \
74	-fno-optimize-sibling-calls \
75	-O2 \
76	-fno-inline-small-functions \
77	-fno-inline-functions-called-once \
78	-mtune=opteron \
79	-ffreestanding \
80	-fPIC
81
82DMOD_LDFLAGS = \
83	-m64 \
84	-shared \
85	-nodefaultlibs \
86	-Wl,-M$(KERNEL_SOURCE)/usr/src/common/mapfiles/common/map.pagealign \
87	-Wl,-M$(KERNEL_SOURCE)/usr/src/common/mapfiles/common/map.noexdata \
88	-Wl,-ztext \
89	-Wl,-zdefs \
90	-Wl,-M$(MDB_SOURCE)/common/modules/conf/mapfile-extern \
91	-L$(PROTO_AREA)/lib \
92	-L$(PROTO_AREA)/usr/lib
93
94DMOD_LIBS = \
95	-lc
96
97DMOD_SRCS = \
98	qemu_mdb.c
99
100world: qemu qemu.so
101
102config-host.mak:
103	STRAP_AREA=$(STRAP_AREA) PATH=$(CTFBINDIR):$(PATH) CONFIGURE_ONLY=1 ./build.sh
104
105qemu: config-host.mak
106	echo "Building world"
107	STRAP_AREA=$(STRAP_AREA) PATH=$(CTFBINDIR):$(PATH) V=1 gmake all
108
109qemu.so: $(DMOD_SRCS)
110	$(CC) $(DMOD_CPPFLAGS) $(DMOD_CFLAGS) $(DMOD_LDFLAGS) -o $@ \
111	    $(DMOD_SRCS) $(DMOD_LIBS)
112
113update:
114	git pull --rebase
115
116manifest:
117	cp manifest $(DESTDIR)/$(DESTNAME)
118
119mancheck_conf:
120
121install: world
122	STRAP_AREA=$(STRAP_AREA) DESTDIR=$(DESTDIR) PATH=$(CTFBINDIR):$(PATH) V=1 gmake install
123	$(INSTALL) -f $(DESTDIR)/usr/lib/mdb/proc/amd64/ qemu.so
124
125clean:
126	gmake clean
127	rm -f qemu.so config-host.mak
128
129xref:
130	find . -type f -name '*.[ch]' > cscope.files
131	cscope-fast -bq
132
133check:
134	$(CSTYLE) qemu_mdb.c
135
136.PHONY: manifest mancheck_conf xref check clean
137