xref: /freebsd/contrib/bmake/make-bootstrap.sh.in (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
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=`sed -n '/^MAKE_VERSION=/s,.*=[^0-9]*,,p' $srcdir/Makefile`
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
26do_compile2() {
27	obj="$1"; shift
28	src="$1"; shift
29	echo ${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
30	${CC} -c ${CFLAGS} "$@" -o "$obj" "$src"
31}
32
33do_compile() {
34	obj="$1"; shift
35	src=`basename "$obj" .o`.c
36
37	for d in "$srcdir" "$srcdir/lst.lib"
38	do
39		test -s "$d/$src" || continue
40
41		do_compile2 "$obj" "$d/$src" "$@" || exit 1
42		return
43	done
44	echo "Unknown object file '$obj'" >&2
45	exit 1
46}
47
48do_link() {
49	output="$1"; shift
50	echo ${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
51	${CC} ${LDSTATIC} ${LDFLAGS} -o "$output" "$@" ${LIBS}
52}
53
54BASE_OBJECTS="arch.o buf.o compat.o cond.o dir.o for.o getopt hash.o \
55job.o make.o make_malloc.o metachar.o parse.o sigcompat.o str.o strlist.o \
56suff.o targ.o trace.o var.o util.o"
57
58LST_OBJECTS="lstAppend.o lstDupl.o lstInit.o lstOpen.o \
59lstAtEnd.o lstEnQueue.o lstInsert.o lstAtFront.o lstIsAtEnd.o \
60lstClose.o lstFind.o lstIsEmpty.o lstRemove.o lstConcat.o \
61lstFindFrom.o lstLast.o lstReplace.o lstFirst.o lstDatum.o \
62lstForEach.o lstMember.o lstSucc.o lstDeQueue.o lstForEachFrom.o \
63lstDestroy.o lstNext.o lstPrev.o"
64
65LIB_OBJECTS="@LIBOBJS@"
66
67do_compile main.o ${MDEFS}
68
69for o in ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS}
70do
71	do_compile "$o"
72done
73
74case "@use_meta@" in
75yes)
76        case "@filemon_h@" in
77	*/filemon.h) FDEFS="-DHAVE_FILEMON_H -I`dirname @filemon_h@`";;
78	esac
79        do_compile meta.o ${FDEFS}
80        BASE_OBJECTS="meta.o ${BASE_OBJECTS}"
81        ;;
82esac
83
84do_link bmake main.o ${BASE_OBJECTS} ${LST_OBJECTS} ${LIB_OBJECTS}
85