job:  #652  Merging in the OAL way of checking for the first enum.  Beginning to test.

.//============================================================================
.// This archetype generates an include file containing the domain level
.// structured and enumerated user data types defined in the analysis model.
.//============================================================================
.//
.//
.//
.//============================================================================
.function TE_DT_StructuredDataTypes
  .param inst_ref_set te_dts
  .for each te_dt in te_dts
    .invoke r = TE_DT_StructuredDataType( te_dt )
${r.body}\
  .end for
.end function
.//
.//
.//
.//
.//============================================================================
.function TE_DT_StructuredDataType
  .param inst_ref te_dt
  .select any te_string from instances of TE_STRING
  .select any te_file from instances of TE_FILE
  .select one s_sdt related by te_dt->S_DT[R2021]->S_SDT[R17]
  .if ( not te_dt.generated )
    .assign members = ""
    .assign te_dt.Initial_Value = "{"
    .assign te_dt.generated = true
    .select many s_mbrs related by s_sdt->S_MBR[R44]
    .select many mbr_te_dts related by s_mbrs->S_DT[R45]->S_SDT[R17]->S_DT[R17]->TE_DT[R2021]
    .for each mbr_te_dt in mbr_te_dts
      .invoke r = TE_DT_StructuredDataType( mbr_te_dt )
${r.body}\
    .end for
    .// Find the first member of the structure.
    .select any first_te_mbr from instances of TE_MBR where ( false )
    .for each s_mbr in s_mbrs
      .select one previous_s_mbr related by s_mbr->S_MBR[R46.'precedes']
      .if ( empty previous_s_mbr )
        .select one first_te_mbr related by s_mbr->TE_MBR[R2047]
        .break for
      .end if
    .end for
    .assign te_mbr = first_te_mbr
    .while ( not_empty te_mbr )
      .select one mbr_te_dt related by te_mbr->TE_DT[R2068]
      .assign members = members + "  ${mbr_te_dt.ExtName} ${te_mbr.GeneratedName}${te_mbr.array_spec};\n"
      .if ( "" == te_mbr.array_spec )
        .assign te_dt.Initial_Value = te_dt.Initial_Value + "${mbr_te_dt.Initial_Value}"
      .else
        .assign te_dt.Initial_Value = te_dt.Initial_Value + "{${mbr_te_dt.Initial_Value}}"
      .end if
      .select one te_mbr related by te_mbr->TE_MBR[R2067.'succeeds']
      .if ( not_empty te_mbr )
        .assign te_dt.Initial_Value = te_dt.Initial_Value + ","
      .end if
    .end while
    .assign te_dt.Initial_Value = te_dt.Initial_Value + "}"
    .include "${te_file.arc_path}/t.s_sdt.h"
  .end if
.end function
.//
.//
.//
.//============================================================================
.function TE_DT_EnumerationDataTypes
  .param inst_ref te_dt
  .//
  .select any te_sys from instances of TE_SYS
  .select any te_target from instances of TE_TARGET
  .assign dtowner = te_sys.Name
  .select one te_c related by te_dt->TE_C[R2086]
  .if ( not_empty te_c )
    .assign dtowner = te_c.Name
  .end if
  .if ( te_dt.Owning_Dom_Name == dtowner )
    .assign intvalue = -1
    .if ( te_dt.Value != "-1" )
      .// Avoid calling this when default.
      .invoke temp_int = STRING_TO_INTEGER( te_dt.Value )
      .assign intvalue = temp_int.result
    .end if
    .// find the first enumerator
    .select one s_edt related by te_dt->S_DT[R2021]->S_EDT[R17]
    .select any s_enum from instances of S_ENUM where (false)
    .select any prev_s_enum related by s_edt->S_ENUM[R27]
    .while (not_empty prev_s_enum)
      .assign s_enum = prev_s_enum
      .select one prev_s_enum related by prev_s_enum->S_ENUM[R56.'precedes'];
    .end while
/*
 * Enumerated Data Type:  ${te_dt.Name}
 */
typedef enum {
 ${te_dt.Initial_Value} = ${te_dt.Value},
    .while ( not_empty s_enum )
      .select one te_enum related by s_enum->TE_ENUM[R2027]
 ${te_enum.GeneratedName}\
      .if ( "" != te_enum.Value )
        .invoke temp_int = STRING_TO_INTEGER( te_enum.Value )
        .assign intvalue = temp_int.result
      .else
        .assign intvalue = intvalue + 1
      .end if
 = ${intvalue}\
      .select one s_enum related by s_enum->S_ENUM[R56.'succeeds']
      .if  ( not_empty s_enum )
,
      .else

      .end if
    .end while
} ${te_dt.ExtName};
  .end if
.end function
.//

.//============================================================================
.// This archetype generates an include file containing the domain level
.// structured and enumerated user data types defined in the analysis model.
.//============================================================================
.//
.//
.//
.//============================================================================
.function TE_DT_StructuredDataTypes
  .param inst_ref_set te_dts
  .for each te_dt in te_dts
    .invoke r = TE_DT_StructuredDataType( te_dt )
${r.body}\
  .end for
.end function
.//
.//
.//
.//
.//============================================================================
.function TE_DT_StructuredDataType
  .param inst_ref te_dt
  .select any te_string from instances of TE_STRING
  .select any te_file from instances of TE_FILE
  .select one s_sdt related by te_dt->S_DT[R2021]->S_SDT[R17]
  .if ( not te_dt.generated )
    .assign members = ""
    .assign te_dt.Initial_Value = "{"
    .assign te_dt.generated = true
    .select many s_mbrs related by s_sdt->S_MBR[R44]
    .select many mbr_te_dts related by s_mbrs->S_DT[R45]->S_SDT[R17]->S_DT[R17]->TE_DT[R2021]
    .for each mbr_te_dt in mbr_te_dts
      .invoke r = TE_DT_StructuredDataType( mbr_te_dt )
${r.body}\
    .end for
    .// Find the first member of the structure.
    .select any first_te_mbr from instances of TE_MBR where ( false )
    .for each s_mbr in s_mbrs
      .select one previous_s_mbr related by s_mbr->S_MBR[R46.'precedes']
      .if ( empty previous_s_mbr )
        .select one first_te_mbr related by s_mbr->TE_MBR[R2047]
        .break for
      .end if
    .end for
    .assign te_mbr = first_te_mbr
    .while ( not_empty te_mbr )
      .select one mbr_te_dt related by te_mbr->TE_DT[R2068]
      .assign members = members + "  ${mbr_te_dt.ExtName} ${te_mbr.GeneratedName}${te_mbr.array_spec};\n"
      .if ( "" == te_mbr.array_spec )
        .assign te_dt.Initial_Value = te_dt.Initial_Value + "${mbr_te_dt.Initial_Value}"
      .else
        .assign te_dt.Initial_Value = te_dt.Initial_Value + "{${mbr_te_dt.Initial_Value}}"
      .end if
      .select one te_mbr related by te_mbr->TE_MBR[R2067.'succeeds']
      .if ( not_empty te_mbr )
        .assign te_dt.Initial_Value = te_dt.Initial_Value + ","
      .end if
    .end while
    .assign te_dt.Initial_Value = te_dt.Initial_Value + "}"
    .include "${te_file.arc_path}/t.s_sdt.h"
  .end if
.end function
.//
.//
.//
.//============================================================================
.function TE_DT_EnumerationDataTypes
  .param inst_ref te_dt
  .//
  .select any te_sys from instances of TE_SYS
  .select any te_target from instances of TE_TARGET
  .assign dtowner = te_sys.Name
  .select one te_c related by te_dt->TE_C[R2086]
  .if ( not_empty te_c )
    .assign dtowner = te_c.Name
  .end if
  .if ( te_dt.Owning_Dom_Name == dtowner )
    .assign intvalue = -1
    .if ( te_dt.Value != "-1" )
      .// Avoid calling this when default.
      .invoke temp_int = STRING_TO_INTEGER( te_dt.Value )
      .assign intvalue = temp_int.result
    .end if
    .select one s_edt related by te_dt->S_DT[R2021]->S_EDT[R17]
    .select any s_enum related by s_edt->S_ENUM[R27] where ( selected.Previous_Enum_ID == 0 )

/*
 * Enumerated Data Type:  ${te_dt.Name}
 */
typedef enum {
 ${te_dt.Initial_Value} = ${te_dt.Value},
    .while ( not_empty s_enum )
      .select one te_enum related by s_enum->TE_ENUM[R2027]
 ${te_enum.GeneratedName}\
      .if ( "" != te_enum.Value )
        .invoke temp_int = STRING_TO_INTEGER( te_enum.Value )
        .assign intvalue = temp_int.result
      .else
        .assign intvalue = intvalue + 1
      .end if
 = ${intvalue}\
      .select one s_enum related by s_enum->S_ENUM[R56.'succeeds']
      .if  ( not_empty s_enum )
,
      .else

      .end if
    .end while
} ${te_dt.ExtName};
  .end if
.end function
.//


parse-url should default to port 443 for urls which have an https resource and no specified port

; written by Mark Huetsch
; same license as Arc

($ (require openssl))
($ (xdef ssl-connect (lambda (host port)
		                   (ar-init-socket
		                     (lambda () (ssl-connect host port))))))

(load "lib/re.arc")
(load "lib/util.arc")

(def parse-server-cookies (s)
  (map [map trim _]
       (map [matchsplit "=" _]
	    (tokens (cut s (len "Set-Cookie:")) #\;))))

(def parse-server-header (lines)
  (withs (http-response (tokens (car lines))
	  ret
	   (list
	     (list
	       (http-response 0)
	       (http-response 1)
	       (http-response 2))
	     (some (fn (s)
		     (and (begins s "Set-Cookie:")
			  (parse-server-cookies s)))
		   (cdr lines))))
    ret))

(def args->query-string (args)
  (if args
      (let equals-list (map [joinstr _ "="] (pair (map [coerce _ 'string] args)))
	(joinstr equals-list "&"))
      ""))

(def parse-url (url)
  (withs (url (joinstr (butlast (tokens url #\#)) "") ; throw away anchor component
	      has-trailing-slash (endmatch "/" url)
	      components (tokens url #\/)
	      first-component (pop components)
	      first-component-is-resource (endmatch ":" first-component)
	      resource (if first-component-is-resource (downcase (butlast first-component))
			   "http") ; defaults to http
	      host (if first-component-is-resource (pop components)
		       first-component)
	      host-tokens (tokens host #\:)
	      host (car host-tokens)
	      port (if (> (len host-tokens) 1) (int (last host-tokens)) (is "https" resource) 443 80)
	      components (tokens (if components
				     (+ (joinstr components "/") (if has-trailing-slash "/"))
				     "")
				 #\?)
	      filename (if (and components (isnt "" (components 0))) (components 0))
	      query (if (> (len components) 1) (components 1)))
    (obj resource resource host host port port filename filename query query)))

(def encode-cookie (o)
  (let joined-list (map [joinstr _ #\=] (tablist o))
    (+ "Cookie: "
       (if (len> joined-list 1)
	   (reduce [+ _1 "; " _2] joined-list)
	   (car joined-list))
       ";")))

; TODO this isn't very pretty
(def get-or-post-url (url (o args) (o method "GET") (o cookie))
  (withs (method (upcase method)
		 parsed-url (parse-url url)
		 args-query-string (args->query-string args)
		 full-args (joinstr (list args-query-string (parsed-url 'query)) "&")
		 request-path (+ "/" (parsed-url 'filename)
				 (if (and (is method "GET") (> (len full-args) 0))
				     (+ "?" full-args)))
		 header-components (list (+ method " " request-path " HTTP/1.0")
					 (+ "Host: " (parsed-url 'host))
					 "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; uk; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"))
    (when (is method "POST")
      (pushend (+ "Content-Length: " (len (utf-8-bytes full-args))) header-components)
      (pushend "Content-Type: application/x-www-form-urlencoded" header-components))
    (when cookie
      (push (encode-cookie cookie) header-components))
    (withs (header (reduce [+ _1 "\r\n" _2] header-components)
		   body (if (is method "POST") (+ full-args "\r\n"))
		   request-message (+ header "\r\n\r\n" body))
      (let (in out) (if (is "https" (parsed-url 'resource))
			(ssl-connect (parsed-url 'host) (parsed-url 'port))
			(socket-connect (parsed-url 'host) (parsed-url 'port)))
	(disp request-message out)
	(withs (result (tostring
			 (whilet line (readline in) (if line (prn line))))
		       body-start (posmatch "\r\n\r\n" result)
		       header-string (cut result 0 body-start)
		       header-lines (re-split "\r\n" header-string)
		       header (parse-server-header header-lines))
	  (close in out)
	  (list
	    header
	    (if body-start
		(cut result (+ 4 body-start))
		result)))))))

(def get-url (url)
  ((get-or-post-url url) 1))

(def post-url (url args)
  ((get-or-post-url url args "POST") 1))

(def google (q)
  (get-url (+ "www.google.com/search?q=" (urlencode q))))

; just some preliminary hacking
(mac w/browser body
  `(withs (cookies* (table)
		    get-url
		    (fn (url) (let (parsed-header html) (get-or-post-url url '() "GET" cookies*)
				(= cookies* (fill-table cookies* (flat (parsed-header 1))))
				html))
		    post-url
		    (fn (url args) (let (parsed-header html) (get-or-post-url url args "POST" cookies*)
				     (= cookies* (fill-table cookies* (flat (parsed-header 1))))
				     html)))
     (do ,@body)))

; written by Mark Huetsch
; same license as Arc

($ (require openssl))
($ (xdef ssl-connect (lambda (host port)
		                   (ar-init-socket
		                     (lambda () (ssl-connect host port))))))

(load "lib/re.arc")
(load "lib/util.arc")

(def parse-server-cookies (s)
  (map [map trim _]
       (map [matchsplit "=" _]
	    (tokens (cut s (len "Set-Cookie:")) #\;))))

(def parse-server-header (lines)
  (withs (http-response (tokens (car lines))
	  ret
	   (list
	     (list
	       (http-response 0)
	       (http-response 1)
	       (http-response 2))
	     (some (fn (s)
		     (and (begins s "Set-Cookie:")
			  (parse-server-cookies s)))
		   (cdr lines))))
    ret))

(def args->query-string (args)
  (if args
      (let equals-list (map [joinstr _ "="] (pair (map [coerce _ 'string] args)))
	(joinstr equals-list "&"))
      ""))

(def parse-url (url)
  (withs (url (joinstr (butlast (tokens url #\#)) "") ; throw away anchor component
	      has-trailing-slash (endmatch "/" url)
	      components (tokens url #\/)
	      first-component (pop components)
	      first-component-is-resource (endmatch ":" first-component)
	      resource (if first-component-is-resource (butlast first-component)
			   "http") ; defaults to http
	      host (if first-component-is-resource (pop components)
		       first-component)
	      host-tokens (tokens host #\:)
	      host (car host-tokens)
	      port (if (> (len host-tokens) 1) (int (last host-tokens)) 80)
	      components (tokens (if components
				     (+ (joinstr components "/") (if has-trailing-slash "/"))
				     "")
				 #\?)
	      filename (if (and components (isnt "" (components 0))) (components 0))
	      query (if (> (len components) 1) (components 1)))
    (obj resource resource host host port port filename filename query query)))

(def encode-cookie (o)
  (let joined-list (map [joinstr _ #\=] (tablist o))
    (+ "Cookie: "
       (if (len> joined-list 1)
	   (reduce [+ _1 "; " _2] joined-list)
	   (car joined-list))
       ";")))

; TODO this isn't very pretty
(def get-or-post-url (url (o args) (o method "GET") (o cookie))
  (withs (method (upcase method)
		 parsed-url (parse-url url)
		 args-query-string (args->query-string args)
		 full-args (joinstr (list args-query-string (parsed-url 'query)) "&")
		 request-path (+ "/" (parsed-url 'filename)
				 (if (and (is method "GET") (> (len full-args) 0))
				     (+ "?" full-args)))
		 header-components (list (+ method " " request-path " HTTP/1.0")
					 (+ "Host: " (parsed-url 'host))
					 "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; uk; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"))
    (when (is method "POST")
      (pushend (+ "Content-Length: " (len (utf-8-bytes full-args))) header-components)
      (pushend "Content-Type: application/x-www-form-urlencoded" header-components))
    (when cookie
      (push (encode-cookie cookie) header-components))
    (withs (header (reduce [+ _1 "\r\n" _2] header-components)
		   body (if (is method "POST") (+ full-args "\r\n"))
		   request-message (+ header "\r\n\r\n" body))
      (let (in out) (if (is "https" (parsed-url 'resource))
			(ssl-connect (parsed-url 'host) (parsed-url 'port))
			(socket-connect (parsed-url 'host) (parsed-url 'port)))
	(disp request-message out)
	(withs (result (tostring
			 (whilet line (readline in) (if line (prn line))))
		       body-start (posmatch "\r\n\r\n" result)
		       header-string (cut result 0 body-start)
		       header-lines (re-split "\r\n" header-string)
		       header (parse-server-header header-lines))
	  (close in out)
	  (list
	    header
	    (if body-start
		(cut result (+ 4 body-start))
		result)))))))

(def get-url (url)
  ((get-or-post-url url) 1))

(def post-url (url args)
  ((get-or-post-url url args "POST") 1))

(def google (q)
  (get-url (+ "www.google.com/search?q=" (urlencode q))))

; just some preliminary hacking
(mac w/browser body
  `(withs (cookies* (table)
		    get-url
		    (fn (url) (let (parsed-header html) (get-or-post-url url '() "GET" cookies*)
				(= cookies* (fill-table cookies* (flat (parsed-header 1))))
				html))
		    post-url
		    (fn (url args) (let (parsed-header html) (get-or-post-url url args "POST" cookies*)
				     (= cookies* (fill-table cookies* (flat (parsed-header 1))))
				     html)))
     (do ,@body)))


Move kernel start from 0x80080000 to 0x80100000

#	$OpenBSD: Makefile.arc,v 1.4 1996/08/26 10:52:24 pefo Exp $

#	@(#)Makefile.arc	8.2 (Berkeley) 2/16/94
#
# Makefile for 4.4 BSD
#
# This makefile is constructed from a machine description:
#	config machineid
# Most changes should be made in the machine description
#	/sys/arch/MACHINE/conf/``machineid''
# after which you should do
#	 config machineid
# Machine generic makefile changes should be made in
#	/sys/arch/MACHINE/conf/Makefile.``machinetype''
# after which config should be rerun for all machines of that type.
#
# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE
#	IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING
#
# -DTRACE	compile in kernel tracing hooks
# -DQUOTA	compile in file system quotas

# DEBUG is set to -g by config if debugging is requested (config -g).
# PROF is set to -pg by config if profiling is requested (config -p).
AS?=	as
CC?=	cc
CPP?=	cpp
LD=	ld.ok			# XXX TEMPORARY
STRIP?=	strip -d
TOUCH?=	touch -f -c

# source tree is located via $S relative to the compilation directory
S=	../../../..
ARC=	../..

INCLUDES=	-I. -I$S/arch -I$S
CPPFLAGS=	${INCLUDES} ${IDENT} -D_KERNEL -Darc
CFLAGS=		${DEBUG} -O2 -Werror -mno-abicalls -mips2 -mcpu=r4000
AFLAGS=		-x assembler-with-cpp -traditional-cpp -D_LOCORE

### find out what to use for libkern
.include "$S/lib/libkern/Makefile.inc"
.ifndef PROF
LIBKERN=	${KERNLIB}
.else
LIBKERN=	${KERNLIB_PROF}
.endif

### find out what to use for libcompat
.include "$S/compat/common/Makefile.inc"
.ifndef PROF
LIBCOMPAT=	${COMPATLIB}
.else
LIBCOMPAT=	${COMPATLIB_PROF}
.endif

# compile rules: rules are named ${TYPE}_${SUFFIX}${CONFIG_DEP}
# where TYPE is NORMAL, DRIVER, or PROFILE}; SUFFIX is the file suffix,
# capitalized (e.g. C for a .c file), and CONFIG_DEP is _C if the file
# is marked as config-dependent.

USRLAND_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
USRLAND_C_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $<

NORMAL_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
NORMAL_C_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $<

DRIVER_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
DRIVER_C_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $<

NORMAL_S=	${CC} ${AFLAGS} ${CPPFLAGS} -c $<
NORMAL_S_C=	${AS}  ${COPTS} ${PARAM} $< -o $@

%OBJS

%CFILES

%SFILES

# load lines for config "xxx" will be emitted as:
# xxx: ${SYSTEM_DEP} swapxxx.o
#	${SYSTEM_LD_HEAD}
#	${SYSTEM_LD} swapxxx.o
#	${SYSTEM_LD_TAIL}

SYSTEM_OBJ=	locore.o fp.o ${OBJS} param.o ioconf.o ${LIBKERN} \
		${LIBCOMPAT}
#
SYSTEM_DEP=	Makefile ${SYSTEM_OBJ}
SYSTEM_LD_HEAD=	rm -f $@
SYSTEM_LD=	-@if [ X${DEBUG} = X-g ]; \
		then strip=-X; \
		else strip=-x; \
		fi; \
		echo ${LD} $$strip -N -o $@ -e start -Ttext 80100000 \
			'$${SYSTEM_OBJ}' vers.o; \
		${LD} $$strip -N -o $@ -e start -Ttext 80100000 \
			${SYSTEM_OBJ} vers.o
#
SYSTEM_LD_TAIL=	chmod 755 $@; \
		elf2ecoff $@ $@.ecoff; \
		size $@

%LOAD

newvers:
	sh $S/conf/newvers.sh
	${CC} $(CFLAGS) -c vers.c

clean::
	rm -f eddep bsd bsd.gdb bsd.ecoff tags *.o locore.i [a-z]*.s \
	    Errs errs linterrs makelinks genassym

lint: /tmp param.c
	@lint -hbxn -DGENERIC -Dvolatile= ${COPTS} ${PARAM} -UKGDB \
	    ${ARC}/arc/Locore.c ${CFILES} ${ARC}/arc/swapgeneric.c \
	    ioconf.c param.c

symbols.sort: ${ARC}/arc/symbols.raw
	grep -v '^#' ${ARC}/arc/symbols.raw \
	    | sed 's/^	//' | sort -u > symbols.sort

locore.o: ${ARC}/arc/locore.S ${ARC}/include/asm.h \
	${ARC}/include/cpu.h ${ARC}/include/reg.h assym.h
	${NORMAL_S} -mips3 ${ARC}/arc/locore.S

fp.o: ${ARC}/arc/fp.S ${ARC}/include/asm.h \
	${ARC}/include/cpu.h ${ARC}/include/reg.h assym.h
	${NORMAL_S} -mips3 ${ARC}/arc/fp.S

# the following are necessary because the files depend on the types of
# cpu's included in the system configuration
clock.o machdep.o autoconf.o conf.o: Makefile

# depend on network configuration
uipc_domain.o uipc_proto.o vfs_conf.o: Makefile
if_tun.o if_loop.o if_ethersubr.o: Makefile
in_proto.o: Makefile

assym.h: genassym
	./genassym >assym.h

genassym: genassym.o
	${HOSTCC} -o $@ genassym.o

genassym.o: ${ARC}/arc/genassym.c
	${HOSTCC} ${INCLUDES} ${IDENT} -D_KERNEL -Darc -c $<

links:
	egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
	  sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
	echo ${CFILES} | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
	  sort -u | comm -23 - dontlink | \
	  sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
	sh makelinks && rm -f dontlink

tags:
	@echo "see $S/kern/Makefile for tags"

ioconf.o: ioconf.c
	${NORMAL_C}

param.c: $S/conf/param.c
	rm -f param.c
	cp $S/conf/param.c .

param.o: param.c Makefile
	${NORMAL_C_C}

newvers: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP}
	sh $S/conf/newvers.sh
	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c

depend:: .depend
.depend: ${SRCS} assym.h param.c
	mkdep ${AFLAGS} ${CPPFLAGS} ${ARC}/arc/locore.s
	mkdep -a ${CFLAGS} ${CPPFLAGS} param.c ioconf.c ${CFILES}
	mkdep -a ${AFLAGS} ${CPPFLAGS} ${SFILES}
	mkdep -a ${CFLAGS} ${CPPFLAGS} ${PARAM} ${ARC}/arc/genassym.c

%RULES

#	$OpenBSD: Makefile.arc,v 1.3 1996/08/24 18:35:25 imp Exp $

#	@(#)Makefile.arc	8.2 (Berkeley) 2/16/94
#
# Makefile for 4.4 BSD
#
# This makefile is constructed from a machine description:
#	config machineid
# Most changes should be made in the machine description
#	/sys/arch/MACHINE/conf/``machineid''
# after which you should do
#	 config machineid
# Machine generic makefile changes should be made in
#	/sys/arch/MACHINE/conf/Makefile.``machinetype''
# after which config should be rerun for all machines of that type.
#
# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE
#	IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING
#
# -DTRACE	compile in kernel tracing hooks
# -DQUOTA	compile in file system quotas

# DEBUG is set to -g by config if debugging is requested (config -g).
# PROF is set to -pg by config if profiling is requested (config -p).
AS?=	as
CC?=	cc
CPP?=	cpp
LD=	ld.ok			# XXX TEMPORARY
STRIP?=	strip -d
TOUCH?=	touch -f -c

# source tree is located via $S relative to the compilation directory
S=	../../../..
ARC=	../..

INCLUDES=	-I. -I$S/arch -I$S
CPPFLAGS=	${INCLUDES} ${IDENT} -D_KERNEL -Darc
CFLAGS=		${DEBUG} -O2 -Werror -mno-abicalls -mips2 -mcpu=r4000
AFLAGS=		-x assembler-with-cpp -traditional-cpp -D_LOCORE

### find out what to use for libkern
.include "$S/lib/libkern/Makefile.inc"
.ifndef PROF
LIBKERN=	${KERNLIB}
.else
LIBKERN=	${KERNLIB_PROF}
.endif

### find out what to use for libcompat
.include "$S/compat/common/Makefile.inc"
.ifndef PROF
LIBCOMPAT=	${COMPATLIB}
.else
LIBCOMPAT=	${COMPATLIB_PROF}
.endif

# compile rules: rules are named ${TYPE}_${SUFFIX}${CONFIG_DEP}
# where TYPE is NORMAL, DRIVER, or PROFILE}; SUFFIX is the file suffix,
# capitalized (e.g. C for a .c file), and CONFIG_DEP is _C if the file
# is marked as config-dependent.

USRLAND_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
USRLAND_C_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $<

NORMAL_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
NORMAL_C_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $<

DRIVER_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
DRIVER_C_C=	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $<

NORMAL_S=	${CC} ${AFLAGS} ${CPPFLAGS} -c $<
NORMAL_S_C=	${AS}  ${COPTS} ${PARAM} $< -o $@

%OBJS

%CFILES

%SFILES

# load lines for config "xxx" will be emitted as:
# xxx: ${SYSTEM_DEP} swapxxx.o
#	${SYSTEM_LD_HEAD}
#	${SYSTEM_LD} swapxxx.o
#	${SYSTEM_LD_TAIL}

SYSTEM_OBJ=	locore.o fp.o ${OBJS} param.o ioconf.o ${LIBKERN} \
		${LIBCOMPAT}
#
SYSTEM_DEP=	Makefile ${SYSTEM_OBJ}
SYSTEM_LD_HEAD=	rm -f $@
SYSTEM_LD=	-@if [ X${DEBUG} = X-g ]; \
		then strip=-X; \
		else strip=-x; \
		fi; \
		echo ${LD} $$strip -N -o $@ -e start -Ttext 80080000 \
			'$${SYSTEM_OBJ}' vers.o; \
		${LD} $$strip -N -o $@ -e start -Ttext 80080000 \
			${SYSTEM_OBJ} vers.o
#
SYSTEM_LD_TAIL=	chmod 755 $@; \
		elf2ecoff $@ $@.ecoff; \
		size $@

%LOAD

newvers:
	sh $S/conf/newvers.sh
	${CC} $(CFLAGS) -c vers.c

clean::
	rm -f eddep bsd bsd.gdb bsd.ecoff tags *.o locore.i [a-z]*.s \
	    Errs errs linterrs makelinks genassym

lint: /tmp param.c
	@lint -hbxn -DGENERIC -Dvolatile= ${COPTS} ${PARAM} -UKGDB \
	    ${ARC}/arc/Locore.c ${CFILES} ${ARC}/arc/swapgeneric.c \
	    ioconf.c param.c

symbols.sort: ${ARC}/arc/symbols.raw
	grep -v '^#' ${ARC}/arc/symbols.raw \
	    | sed 's/^	//' | sort -u > symbols.sort

locore.o: ${ARC}/arc/locore.S ${ARC}/include/asm.h \
	${ARC}/include/cpu.h ${ARC}/include/reg.h assym.h
	${NORMAL_S} -mips3 ${ARC}/arc/locore.S

fp.o: ${ARC}/arc/fp.S ${ARC}/include/asm.h \
	${ARC}/include/cpu.h ${ARC}/include/reg.h assym.h
	${NORMAL_S} -mips3 ${ARC}/arc/fp.S

# the following are necessary because the files depend on the types of
# cpu's included in the system configuration
clock.o machdep.o autoconf.o conf.o: Makefile

# depend on network configuration
uipc_domain.o uipc_proto.o vfs_conf.o: Makefile
if_tun.o if_loop.o if_ethersubr.o: Makefile
in_proto.o: Makefile

assym.h: genassym
	./genassym >assym.h

genassym: genassym.o
	${HOSTCC} -o $@ genassym.o

genassym.o: ${ARC}/arc/genassym.c
	${HOSTCC} ${INCLUDES} ${IDENT} -D_KERNEL -Darc -c $<

links:
	egrep '#if' ${CFILES} | sed -f $S/conf/defines | \
	  sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
	echo ${CFILES} | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
	  sort -u | comm -23 - dontlink | \
	  sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
	sh makelinks && rm -f dontlink

tags:
	@echo "see $S/kern/Makefile for tags"

ioconf.o: ioconf.c
	${NORMAL_C}

param.c: $S/conf/param.c
	rm -f param.c
	cp $S/conf/param.c .

param.o: param.c Makefile
	${NORMAL_C_C}

newvers: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP}
	sh $S/conf/newvers.sh
	${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c

depend:: .depend
.depend: ${SRCS} assym.h param.c
	mkdep ${AFLAGS} ${CPPFLAGS} ${ARC}/arc/locore.s
	mkdep -a ${CFLAGS} ${CPPFLAGS} param.c ioconf.c ${CFILES}
	mkdep -a ${AFLAGS} ${CPPFLAGS} ${SFILES}
	mkdep -a ${CFLAGS} ${CPPFLAGS} ${PARAM} ${ARC}/arc/genassym.c

%RULES