#
# 
#	Copyright (C) 2003 Hirohisa MORI joshua@nichibun.ac.jp
# 
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the GLOBALBASE General Public 
#	License as published by http://www.globalbase.org/
# 
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
#	Usage::
#
#	mmake MACHINE=linux		for linux
#	mmake MACHINE=MacOSX		for MacOSX
#	mmake MACHINE=FreeBSD		for FreeBSD
#
#	mmake VER=-update		force to update version code
#	mmake VER=-on			to make version code and object
#
#	combination of MACHINE and VER is abailable
#
#	default machine is solaris
#

@(eq,${UNAME},SunOS)	set MACHINE	solaris
@(eq,${UNAME},Linux)	set MACHINE	linux
@(eq,${UNAME},Darwin)	set MACHINE	MacOSX
@(ndef,MACHINE)		set MACHINE	solaris
@(ndef,VER)		set VER		-off



@ set CC	gcc
@ set LINK	gcc
@ set YY	yacc
@ set PC	p2c
@ set DEP	mdep
@ set VERSION	mversion
@ set CFLAGS	"-g -c -Wreturn-type -D_POSIX_C_SOURCE=199506L -D__EXTENSIONS__ -DMETH_TC -D_REENTRANT"
@ set INCLUDES	"-I${src_dir} -I../../src/h -I../../src/arch/unix/h -I../../src/arch/unix/machine/${MACHINE} -I../../src/ext/zlib-1.1.4 "
@ 				set LFLAGS	"-D_POSIX_C_SOURCE=199506L"
@				set M_LIB	"-lm "
#				set Z_LIB	"-lz "
@				set Z_LIB	" "
@				set T_LIB	"-lposix4 -lpthread "
@				set N_LIB	"-lsocket -lnsl ${T_LIB}"
@				set W_LIB	"-lX11 ${N_LIB}"

@ set V_FLAGS	"${VER} \
		-current ../current.ver \
		-prefix .c .t .cp .cpp \
		-base ${MACHINE}/work/ ../../src/ \
		-except ../../src/version \
		-code ap_version AP.code \
		-log ../../../../cvs.log \
			gbs/env/src/ ../../src/"

@ set VL_VER	-update
@ set VL_FLAGS	"${VL_VER} \
		-current ../current.ver \
		-prefix .c .t .cp .cpp \
		-base ${MACHINE}/work/ ../../src/ \
		-except ../../src/version \
		-log ../../../../cvs.log \
			gbs/env/src/ ../../src/"

@ set	LINKSKIP	off
@(eq,${VER},-update) set LINKSKIP	on

#
#	linux option
#

@(eq,${MACHINE},linux)	set T_LIB	"-lpthread "
@(eq,${MACHINE},linux)	set N_LIB	"-lnsl ${T_LIB} "
@(eq,${MACHINE},linux)	set W_LIB "-L/usr/X11R6/lib -lX11 ${N_LIB} "

#
#	FreeBSD option
#

@(eq,${MACHINE},FreeBSD)	set INCLUDES	"-I${src_dir} -I../../src/h -I../../src/arch/unix/h -I../../src/arch/unix/machine/${MACHINE} -I/usr/X11R6/include"
@(eq,${MACHINE},FreeBSD)	set CFLAGS	"-g -c -pthread -Wreturn-type -D_POSIX_C_SOURCE=199506L -D__EXTENSIONS__ -DMETH_TC -D_REENTRANT -D_THREAD_SAFE"
@(eq,${MACHINE},FreeBSD)	set T_LIB	"-pthread "
@(eq,${MACHINE},FreeBSD)	set N_LIB	"${T_LIB} "
@(eq,${MACHINE},FreeBSD)	set W_LIB "-L/usr/X11R6/lib -lX11 ${N_LIB} "

#
#	MacOS X option
#

@(eq,${MACHINE},MacOSX)			set CFLAGS	"-g -c -Wreturn-type -D_POSIX_C_SOURCE=199506L -D__EXTENSIONS__ -DMETH_TC -D_REENTRANT -no-cpp-precomp"
@(eq,${MACHINE},MacOSX)			set INCLUDES	"-I${src_dir} -I../../src/h -I../../src/arch/unix/h -I../../src/arch/unix/machine/${MACHINE} -I/usr/X11R6/include"
@(eq,${MACHINE},MacOSX)			set T_LIB	"-lpthread "
@(eq,${MACHINE},MacOSX)			set N_LIB	"${T_LIB} "
@(eq,${MACHINE},MacOSX)			set W_LIB "-L/usr/X11R6/lib -lX11.6 ${N_LIB} "




@ set YFLAGS	-d

@ source	../../src
@ work		work

@ keep		CVS d


@ insert	r64
@ insert	ppm
@ insert	test/r64test
@ insert	endian
@ insert	arch/unix/std/utils/u_file.c

@ tree



@ make sufix .c from sufix - .y
	${YY} ${YFLAGS} ${from}
 	cp y.tab.c ${to}.c
 	rm y.tab.c


@ make sufix .o from sufix - .c
	${DEP} ${INCLUDES} -i${from} -o${to}.c.ap
	${CC} ${CFLAGS} ${INCLUDES} -o ${to}.o ${from}

@ make sufix .o from sufix - .t
	${PC} ${from} ${to}.c
	${DEP} ${INCLUDES} -i${from} -o${to}.c.ap
	${CC} ${CFLAGS} ${INCLUDES} -o ${to}.o ${to}.c

@ make file ../../proj/unix/solaris/bin/r64test from \
		sufix work/test/r64test .o \
		file work/r64/file \
			r64_open_file.o \
			r64_close_file.o \
			r64_red.o \
			r64_flush.o \
			_r64_flush.o \
			_search_ce.o \
			_r64_read.o \
			_r64_new_ce.o \
			_fill_background.o \
			r64_init.o \
		sufix work/endian .o \
		file work/arch/unix/std/utils \
			u_file.o

	${LINK} -o ${to} ${LFLAGS} ${from} ${M_LIB} ${N_LIB}

