xref: /freebsd/contrib/bmake/make-bootstrap.sh.in (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
1#!/bin/sh
2
3set -e
4
5srcdir=@srcdir@
6
7DEFAULT_SYS_PATH="@default_sys_path@"
8
9case "@use_meta@" in
10yes) XDEFS="-DUSE_META ${XDEFS}";;
11esac
12
13CC="@CC@"
14CFLAGS="@CFLAGS@ -I. -I${srcdir} @DEFS@ @CPPFLAGS@ -DMAKE_NATIVE ${XDEFS} -DBMAKE_PATH_MAX=@bmake_path_max@"
15
16MAKE_VERSION=@_MAKE_VERSION@
17
18MDEFS="-DMAKE_VERSION=\"$MAKE_VERSION\" \
19-D@force_machine@MACHINE=\"@machine@\" \
20-D@force_machine_arch@MACHINE_ARCH=\"@machine_arch@\" \
21-D_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\""
22
23
24LDFLAGS="@LDFLAGS@"
25LIBS="@LIBS@"
26
27toUpper() {
28    ${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
29}
30
31do_compile2() {
32	obj="$1"; shift
33	src="$1"; shift
34	echo ${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
35	${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
36}
37
38do_compile() {
39	obj="$1"; shift
40	case "$1" in
41	*.c) src=$1; shift;;
42	*) src=`basename "$obj" .o`.c;;
43	esac
44
45	for d in "$srcdir" "$srcdir/lst.lib"
46	do
47		test -s "$d/$src" || continue
48
49		do_compile2 "$obj" "$d/$src" "$@" || exit 1
50		return
51	done
52	echo "Unknown object file '$obj'" >&2
53	exit 1
54}
55
56do_link() {
57	output="$1"; shift
58	echo ${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
59	${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
60}
61
62BASE_OBJECTS="arch.o buf.o compat.o cond.o dir.o for.o hash.o \
63lst.o make.o make_malloc.o metachar.o parse.o sigcompat.o str.o \
64suff.o targ.o trace.o var.o util.o"
65
66LIB_OBJECTS="@LIBOBJS@"
67
68do_compile main.o ${MDEFS}
69
70for o in ${BASE_OBJECTS} ${LIB_OBJECTS}
71do
72	do_compile "$o"
73done
74
75case "@use_meta@" in
76yes)
77	case "@use_filemon@" in
78	no) MDEFS=;;
79	*)
80		MDEFS="-DUSE_FILEMON -DUSE_FILEMON_`echo @use_filemon@ | toUpper`"
81		case "@use_filemon@,@filemon_h@" in
82		dev,*/filemon.h) FDEFS="-DHAVE_FILEMON_H -I`dirname @filemon_h@`";;
83		*) FDEFS=;;
84		esac
85		do_compile filemon_@use_filemon@.o filemon/filemon_@use_filemon@.c ${FDEFS}
86		BASE_OBJECTS="filemon_@use_filemon@.o $BASE_OBJECTS"
87		;;
88	esac
89	do_compile meta.o ${MDEFS}
90	BASE_OBJECTS="meta.o ${BASE_OBJECTS}"
91	;;
92esac
93do_compile job.o ${MDEFS}
94
95do_link bmake main.o job.o ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS}
96