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