xref: /freebsd/contrib/bmake/make-bootstrap.sh.in (revision 02e9120893770924227138ba49df1edb3896112a)
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_PATH_DEFSYSPATH=\"${DEFAULT_SYS_PATH}\""
23
24
25LDFLAGS="@LDFLAGS@"
26LIBS="@LIBS@"
27
28toUpper() {
29    ${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
30}
31
32do_compile2() {
33	obj="$1"; shift
34	src="$1"; shift
35	echo ${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
36	${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
37}
38
39do_compile() {
40	obj="$1"; shift
41	case "$1" in
42	*.c) src=$1; shift;;
43	*) src=`basename "$obj" .o`.c;;
44	esac
45
46	for d in "$srcdir" "$srcdir/lst.lib"
47	do
48		test -s "$d/$src" || continue
49
50		do_compile2 "$obj" "$d/$src" "$@" || exit 1
51		return
52	done
53	echo "Unknown object file '$obj'" >&2
54	exit 1
55}
56
57do_link() {
58	output="$1"; shift
59	echo ${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
60	${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
61}
62
63BASE_OBJECTS="arch.o buf.o compat.o cond.o dir.o for.o hash.o \
64lst.o make.o make_malloc.o metachar.o parse.o sigcompat.o str.o \
65suff.o targ.o trace.o var.o util.o"
66
67LIB_OBJECTS="@LIBOBJS@"
68
69do_compile main.o ${MDEFS}
70
71for o in ${BASE_OBJECTS} ${LIB_OBJECTS}
72do
73	do_compile "$o"
74done
75
76case "@use_meta@" in
77yes)
78	case "@use_filemon@" in
79	no) MDEFS=;;
80	*)
81		MDEFS="-DUSE_FILEMON -DUSE_FILEMON_`echo @use_filemon@ | toUpper`"
82		case "@use_filemon@,@filemon_h@" in
83		dev,*/filemon.h) FDEFS="-DHAVE_FILEMON_H -I`dirname @filemon_h@`";;
84		*) FDEFS=;;
85		esac
86		do_compile filemon_@use_filemon@.o filemon/filemon_@use_filemon@.c ${FDEFS}
87		BASE_OBJECTS="filemon_@use_filemon@.o $BASE_OBJECTS"
88		;;
89	esac
90	do_compile meta.o ${MDEFS}
91	BASE_OBJECTS="meta.o ${BASE_OBJECTS}"
92	;;
93esac
94do_compile job.o ${MDEFS}
95
96do_link bmake main.o job.o ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS}
97