xref: /illumos-gate/usr/src/test/libproc-tests/Makefile.com (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
1#
2# This file and its contents are supplied under the terms of the
3# Common Development and Distribution License ("CDDL"), version 1.0.
4# You may only use this file in accordance with the terms of version
5# 1.0 of the CDDL.
6#
7# A full copy of the text of the CDDL should have accompanied this
8# source.  A copy of the CDDL is also available via the Internet at
9# http://www.illumos.org/license/CDDL.
10#
11
12#
13# Copyright 2024 Oxide Computer Company
14#
15
16#
17# Common Makefile rules and patterns for building the various libproc
18# tests.
19#
20# Individual test directories can use this to build multiple bitness
21# programs and scripts. The following assumptions are used in this
22# Makefile:
23#
24# 'PROGS': This variable is a list of programs to build. The expectation
25#  is that each one has a corresponding .c file.
26#
27# 'COMMON_SRCS': This is a list of .c files that should be built into
28# every test object.
29#
30# 'SCRIPTS': These are ksh files that should be installed into the test
31# directory.
32#
33# 'TESTDIR': This is the name of the directory under libproc-tests/tests
34# that tests should appear.
35#
36# 'LDLIBS'/'LDLIBS64': Individual makefiles are expected to include
37# -lproc here. This isn't done universally so it's easier to build
38# binaries that don't use libproc.
39#
40
41PROGS32 = $(PROGS:%=%.32)
42PROGS64 = $(PROGS:%=%.64)
43
44EXTRA_OBJS32 = $(COMMON_SRCS:%.c=%.o.32)
45EXTRA_OBJS64 = $(COMMON_SRCS:%.c=%.o.64)
46
47ROOTOPTDIR = $(ROOT)/opt/libproc-tests
48ROOTOPTTESTS = $(ROOTOPTDIR)/tests
49ROOTOPTTARG = $(ROOTOPTTESTS)/$(TESTDIR)
50ROOTOPTPROGS = $(PROGS32:%=$(ROOTOPTTARG)/%) $(PROGS64:%=$(ROOTOPTTARG)/%)
51ROOTOPTPROGS += $(SCRIPTS:%=$(ROOTOPTTARG)/%)
52
53include $(SRC)/cmd/Makefile.cmd
54include $(SRC)/cmd/Makefile.ctf
55
56CPPFLAGS += -D_REENTRANT
57CSTD = $(CSTD_GNU99)
58CTF_MODE = link
59
60.KEEP_STATE:
61
62all: $(PROGS32) $(PROGS64)
63
64clobber: clean
65	-$(RM) $(PROGS32) $(PROGS64)
66
67clean:
68	-$(RM) *.o.32 *.o.64
69
70install: $(ROOTOPTTARG) .WAIT $(ROOTOPTPROGS)
71
72$(ROOTOPTDIR):
73	$(INS.dir)
74
75$(ROOTOPTTESTS): $(ROOTOPTDIR)
76	$(INS.dir)
77
78$(ROOTOPTTARG): $(ROOTOPTTESTS)
79	$(INS.dir)
80
81$(ROOTOPTTARG)/%: %
82	$(INS.file)
83
84$(ROOTOPTTARG)/%: %.ksh
85	$(INS.rename)
86
87%.o.32: %.c
88	$(COMPILE.c) -o $@ -c $<
89	$(POST_PROCESS_O)
90
91%.o.64: %.c
92	$(COMPILE64.c) -o $@ -c $<
93	$(POST_PROCESS_O)
94
95%.64: %.o.64 $(EXTRA_OBJS64)
96	$(LINK64.c) -o $@ $< $(EXTRA_OBJS64) $(LDLIBS64)
97	$(POST_PROCESS)
98
99%.32: %.o.32 $(EXTRA_OBJS32)
100	$(LINK.c) -o $@ $< $(EXTRA_OBJS32) $(LDLIBS)
101	$(POST_PROCESS)
102