# Copyright 2010 The Go Authors.  All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# mkfile for commands written in C, Alef or Assembler.

LDFLAGS=
YFLAGS=-d
AFLAGS=

# In due course these should lapse
CFLAGS= -I$ROOT/include -I$ROOT/$objtype/include $CFLAGS

all:V: $O.$TARG

install:V:	$BIN/$TARG

installall:V:
	for(objtype in $CPUS)
		mk install

allall:V:
	for(objtype in $CPUS)
		mk all

$O.$TARG: $OFILES $LIB
	$LD $LDFLAGS -o $target $prereq

%.$O:	$HFILES		# don't combine with following %.$O rules

%.$O:	%.c
	$CC $CFLAGS $stem.c

%.$O:	%.s
	$AS $AFLAGS $stem.s

(.*)\.[vkq8]'$':R:	\1.l
	$ALEF $CFLAGS $stem1.l

(.*)\.[26z]'$':RQ:	\1.l
	;

y.tab.h: $YFILES
	$YACC $YFLAGS $prereq

y.tab.c: y.tab.h
	test -f y.tab.c && touch y.tab.c

lex.yy.c:	$LFILES
	$LEX $LFLAGS $prereq

$BIN/$TARG:	$O.$TARG
	cp $prereq $target

nuke:V:	clean
	rm -f *.acid $BIN/$TARG

clean:V:
	rm -f *.[$OS] [$OS].out y.tab.? lex.yy.c y.debug y.output [$OS].$TARG $CLEANFILES

# These are used by enough different mkfiles to be
# worth writing down in one place, even if they don't
# apply to every command that builds with "src/cmd/mkone"

enam.$O:	../${OBJ}l/enam.c
	$CC $CFLAGS ../$OBJ^l/enam.c

../${OBJ}l/enam.c:	../${OBJ}l/$OBJ.out.h
	cd ../$OBJ^l
	mk enam.c

enam.c: $OBJ.out.h
	cat ../ld/mkenam.ed | ed - $OBJ.out.h

# goos.c (lib9 is not used by the Plan 9 port)
goos.$O: ../../lib9/goos.c
	$CC '-DGOOS="plan9"' '-DGOARCH="'^$ARCH^'"' '-DGOROOT="'^$ROOT^'"' '-DGOVERSION="'^$"VERSION^'"' $CFLAGS ../../lib9/goos.c
