Plan 9 from Bell Labs’s /usr/web/sources/contrib/ericvh/go-plan9/src/mk.pkg

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


# Copyright 2009 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.

all: package

package: _obj/$TARG.a

testpackage: _test/$TARG.a

elem=`{echo $TARG | sed 's@.*/@@'}

dir=`{echo $TARG | sed 's@/[^/]**@@'}

pkgdir=$GOROOT/pkg/$GOOS'_'$GOARCH

INSTALLFILES=$pkgdir/$TARG.a

# The rest of the cgo rules are below, but these variable updates
# must be done here so they apply to the main rules.
GOFILES=`{echo $GOFILES; for(f in $CGOFILES) echo $f | sed 's/(.*)\.go/\1.cgo1.go \1.cgo2.go/'}
OFILES=`{echo $OFILES; for(f in $CGOFILES) echo $f | sed 's/(.*)\.go/\1.cgo1.go \1.cgo3.$O/'}
INSTALLFILES=`{echo $INSTALLFILES; for(f in $CGOFILES) echo $f | sed 's/(.*)\.go/$pkgdir/$dir/$elem_\1.so/'}
PREREQ=`{echo $PREREQ; for(f in $DEPS) echo $f.make}

coverage:
	gotest
	6cov -g `{pwd} | grep -v '_test\.go:'

clean:
	rm -rf *.[o$O] *.a [$OS].out *.cgo[12].go *.cgo[34].c *.so _obj _test _testmain.go $CLEANFILES

test:
	gotest

nuke: clean
	rm -f $pkgdir/$TARG.a

testpackage-clean:
	rm -f _test/$TARG.a _gotest_.$O

install: $INSTALLFILES

$pkgdir/$TARG.a: package
	@test -d $GOROOT/pkg && mkdir -p $pkgdir/$dir
	cp _obj/$TARG.a $target

_go_.$O: $GOFILES $PREREQ
	$GC -o $target $GOFILES

_gotest_.$O: $GOFILES $GOTESTFILES $PREREQ
	$GC -o $target $GOFILES $GOTESTFILES

_obj/$TARG.a: _go_.$O $OFILES
	@mkdir -p _obj/$dir
	rm -f _obj/$TARG.a
	gopack grc $target _go_.$O $OFILES

_test/$TARG.a: _gotest_.$O $OFILES
	@mkdir -p _test/$dir
	rm -f _test/$TARG.a
	gopack grc $target _gotest_.$O $OFILES

importpath:
	@echo $TARG

dir:
	@echo $dir

&.make:
	(cd $stem && make)

# To use cgo in a Go package, add a line
#
#	CGOFILES=x.go
#
# to the main Makefile.  This signals that cgo should process x.go.
# There are two optional variables to set, CGO_CFLAGS and CGO_LDFLAGS,
# which specify compiler and linker flags to use when compiling
# (using gcc) the C support for x.go.

# Cgo translates each x.go file listed in $CGOFILES into
#
#	x.cgo1.go - basic translation of x.go
#	x.cgo2.go - declarations needed for x.cgo1.go; imports "unsafe"
#	x.cgo3.c - C trampoline code to be compiled with 6c and linked into the package
#	x.cgo4.c - C implementations compiled with gcc to create dynamic library
#
&.cgo1.go &.cgo2.go &.cgo3.c &.cgo4.c: &.go
	cgo $CGO_CFLAGS $stem.go

# The rules above added x.cgo1.go and x.cgo2.go to $GOFILES,
# added x.cgo3.$O to $OFILES, and added the installed copy of
# package_x.so (built from x.cgo4.c) to $INSTALLFILES.

# Compile x.cgo3.c with 6c; needs access to the runtime headers.
RUNTIME_CFLAGS_amd64=-D_64BIT
RUNTIME_CFLAGS=-I$GOROOT/src/pkg/runtime $RUNTIME_CFLAGS'_'$GOARCH
&.cgo3.$O: &.cgo3.c
	$CC $CFLAGS $RUNTIME_CFLAGS $stem.cgo3.c

# Have to run gcc with the right size argument on hybrid 32/64 machines.
_CGO_CFLAGS_386=-m32
_CGO_CFLAGS_amd64=-m64
_CGO_LDFLAGS_linux=-shared -lpthread -lm
_CGO_LDFLAGS_darwin=-dynamiclib -Wl,-undefined,dynamic_lookup


# Compile x.cgo4.c with gcc to make package_x.so.
&.cgo4.o: &.cgo4.c
	gcc $_CGO_CFLAGS'_'$GOARCH -fPIC -O2 -o $target -c $CGO_CFLAGS $stem.cgo4.c

$elem_&.so: &.cgo4.o
	gcc $_CGO_CFLAGS'_'$GOARCH $_CGO_LDFLAGS'_'$GOOS -o $target $stem.cgo4.o $CGO_LDFLAGS

$pkgdir/$dir/$elem_&.so: $elem_&.so
	@test -d $GOROOT/pkg && mkdir -p $pkgdir/$dir
	cp $elem_$stem.so $target

# Generic build rules.
# These come last so that the rules above can override them
# for more specific file names.
&.$O:	&.c
	$CC $CFLAGS $stem.c

&.$O:	&.s
	$AS $stem.s

&.$O:	$HFILES


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.