xref: /freebsd/contrib/bmake/mk/suffixes.mk (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: suffixes.mk,v 1.3 2024/02/17 17:26:57 sjg Exp $
4#
5#	@(#) Copyright (c) 2024, Simon J. Gerraty
6#
7#	This file is provided in the hope that it will
8#	be of use.  There is absolutely NO WARRANTY.
9#	Permission to copy, redistribute or otherwise
10#	use this file is hereby granted provided that
11#	the above copyright notice and this notice are
12#	left intact.
13#
14#	Please send copies of changes and bug-fixes to:
15#	sjg@crufty.net
16#
17
18# some reasonable defaults
19.SUFFIXES: .out .a .ln .o ${PICO} ${PCM} .s .S .c ${CXX_SUFFIXES} \
20	${CCM_SUFFIXES} .F .f .r .y .l .cl .p .h \
21	.sh .m4 .cpp-out
22
23#
24AFLAGS ?=
25ARFLAGS ?=	r
26.if ${MACHINE_ARCH} == "sparc64"
27AFLAGS+= -Wa,-Av9a
28.endif
29AS ?=		as
30CC ?=		cc
31CFLAGS ?=	${DBG}
32CXX ?=		c++
33CXXFLAGS ?=	${CFLAGS}
34CXXFLAGS ?=	${CFLAGS}
35DBG ?=		-O2
36FC ?=		f77
37FFLAGS ?=	-O
38INSTALL ?=	install
39LD ?=		ld
40LEX ?=		lex
41LFLAGS ?=
42NM ?=		nm
43OBJC ?=		${CC}
44OBJCFLAGS ?=	${CFLAGS}
45PC ?=		pc
46PFLAGS ?=
47RFLAGS ?=
48SIZE ?=		size
49YACC ?=		yacc
50YFLAGS ?=
51
52COMPILE.s ?=	${CC} ${AFLAGS} -c
53LINK.s ?=	${CC} ${AFLAGS} ${LDFLAGS}
54COMPILE.S ?=	${CC} ${AFLAGS} ${CPPFLAGS} -c -traditional-cpp
55LINK.S ?=	${CC} ${AFLAGS} ${CPPFLAGS} ${LDFLAGS}
56COMPILE.c ?=	${CC} ${CFLAGS} ${CPPFLAGS} -c
57LINK.c ?=	${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
58COMPILE.cc ?=	${CXX} ${CXXFLAGS} ${CPPFLAGS} -c
59COMPILE.pcm ?=	${COMPILE.cc:N-c} --precompile -c
60LINK.cc ?=	${CXX} ${CXXFLAGS} ${CPPFLAGS} ${LDFLAGS}
61COMPILE.m ?=	${OBJC} ${OBJCFLAGS} ${CPPFLAGS} -c
62LINK.m ?=	${OBJC} ${OBJCFLAGS} ${CPPFLAGS} ${LDFLAGS}
63COMPILE.f ?=	${FC} ${FFLAGS} -c
64LINK.f ?=	${FC} ${FFLAGS} ${LDFLAGS}
65COMPILE.F ?=	${FC} ${FFLAGS} ${CPPFLAGS} -c
66LINK.F ?=	${FC} ${FFLAGS} ${CPPFLAGS} ${LDFLAGS}
67COMPILE.r ?=	${FC} ${FFLAGS} ${RFLAGS} -c
68LINK.r ?=	${FC} ${FFLAGS} ${RFLAGS} ${LDFLAGS}
69LEX.l ?=	${LEX} ${LFLAGS}
70COMPILE.p ?=	${PC} ${PFLAGS} ${CPPFLAGS} -c
71LINK.p ?=	${PC} ${PFLAGS} ${CPPFLAGS} ${LDFLAGS}
72YACC.y ?=	${YACC} ${YFLAGS}
73LEX.l ?=	${LEX} ${LFLAGS}
74
75# C
76.c:
77	${LINK.c} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
78.c.o:
79	${COMPILE.c} ${.IMPSRC}
80.c.a:
81	${COMPILE.c} ${.IMPSRC}
82	${AR} ${ARFLAGS} $@ $*.o
83	rm -f $*.o
84.c.ln:
85	${LINT} ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i ${.IMPSRC}
86
87# C++
88${CXX_SUFFIXES}:
89	${LINK.cc} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
90${CXX_SUFFIXES:%=%.o}:
91	${COMPILE.cc} ${.IMPSRC}
92${CXX_SUFFIXES:%=%.a}:
93	${COMPILE.cc} ${.IMPSRC}
94	${AR} ${ARFLAGS} $@ $*.o
95	rm -f $*.o
96
97# C++ precompiled modules
98${CCM_SUFFIXES:%=%${PCM}}:
99	@${COMPILE.pcm} ${.IMPSRC}
100
101# Fortran/Ratfor
102.f:
103	${LINK.f} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
104.f.o:
105	${COMPILE.f} ${.IMPSRC}
106.f.a:
107	${COMPILE.f} ${.IMPSRC}
108	${AR} ${ARFLAGS} $@ $*.o
109	rm -f $*.o
110
111.F:
112	${LINK.F} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
113.F.o:
114	${COMPILE.F} ${.IMPSRC}
115.F.a:
116	${COMPILE.F} ${.IMPSRC}
117	${AR} ${ARFLAGS} $@ $*.o
118	rm -f $*.o
119
120.r:
121	${LINK.r} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
122.r.o:
123	${COMPILE.r} ${.IMPSRC}
124.r.a:
125	${COMPILE.r} ${.IMPSRC}
126	${AR} ${ARFLAGS} $@ $*.o
127	rm -f $*.o
128
129# Pascal
130.p:
131	${LINK.p} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
132.p.o:
133	${COMPILE.p} ${.IMPSRC}
134.p.a:
135	${COMPILE.p} ${.IMPSRC}
136	${AR} ${ARFLAGS} $@ $*.o
137	rm -f $*.o
138
139# Assembly
140.s:
141	${LINK.s} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
142.s.o:
143	${COMPILE.s} ${.IMPSRC}
144.s.a:
145	${COMPILE.s} ${.IMPSRC}
146	${AR} ${ARFLAGS} $@ $*.o
147	rm -f $*.o
148.S:
149	${LINK.S} -o ${.TARGET} ${.IMPSRC} ${LDLIBS}
150.S.o:
151	${COMPILE.S} ${.IMPSRC}
152.S.a:
153	${COMPILE.S} ${.IMPSRC}
154	${AR} ${ARFLAGS} $@ $*.o
155	rm -f $*.o
156
157# Lex
158.l:
159	${LEX.l} ${.IMPSRC}
160	${LINK.c} -o ${.TARGET} lex.yy.c ${LDLIBS} -ll
161	rm -f lex.yy.c
162.l.c:
163	${LEX.l} ${.IMPSRC}
164	mv lex.yy.c ${.TARGET}
165.l.o:
166	${LEX.l} ${.IMPSRC}
167	${COMPILE.c} -o ${.TARGET} lex.yy.c
168	rm -f lex.yy.c
169
170# Yacc
171.y:
172	${YACC.y} ${.IMPSRC}
173	${LINK.c} -o ${.TARGET} y.tab.c ${LDLIBS}
174	rm -f y.tab.c
175.y.c:
176	${YACC.y} ${.IMPSRC}
177	mv y.tab.c ${.TARGET}
178.y.o:
179	${YACC.y} ${.IMPSRC}
180	${COMPILE.c} -o ${.TARGET} y.tab.c
181	rm -f y.tab.c
182
183# Shell
184.sh:
185	rm -f ${.TARGET}
186	cp ${.IMPSRC} ${.TARGET}
187	chmod a+x ${.TARGET}
188
189
190# this often helps with debugging
191.c.cpp-out:
192	@${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
193
194${CXX_SUFFIXES:%=%.cpp-out}:
195	@${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
196