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