# vim: filetype=python

#  Network Simulation Cradle
#  Copyright (C) 2003-2005 Sam Jansen
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
#
#  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. See the GNU General Public License for
#  more details.
#
#  You should have received a copy of the GNU General Public License along
#  with this program; if not, write to the Free Software Foundation, Inc., 59
#  Temple Place, Suite 330, Boston, MA 02111-1307 USA

# $Id: SConscript 1665 2008-01-10 20:42:26Z stj2 $
from glob import glob
import os

curdir = Dir('.').path + '/'


# Example compile line:
# cc  -Werror -Wall -Wstrict-prototypes -Wmissing-prototypes  -Wno-uninitialized -Wno-format -Wno-main -march=i486 -fno-builtin-printf -fno-builtin-log -O2  -nostdinc -I. -I/usr/src/sys/arch/i386/compile/SAMSKERNEL/../../../../arch -I/usr/src/sys/arch/i386/compile/SAMSKERNEL/../../../.. -DDDB -DDIAGNOSTIC -DKTRACE -DKMEMSTATS -DPTRACE -DCRYPTO -DSYSVMSG -DSYSVSEM -DSYSVSHM -DUVM_SWAP_ENCRYPT -DCOMPAT_43 -DLKM -DFFS -DFFS_SOFTUPDATES -DUFS_DIRHASH -DQUOTA -DEXT2FS -DMFS -DXFS -DTCP_SACK -DTCP_ECN -DTCP_SIGNATURE -DNFSCLIENT -DNFSSERVER -DCD9660 -DMSDOSFS -DFDESC -DFIFO -DKERNFS -DPORTAL -DPROCFS -DNULLFS -DUMAPFS -DUNION -DINET -DALTQ -DINET6 -DIPSEC -DPPP_BSDCOMP -DPPP_DEFLATE -DBOOT_CONFIG -DI586_CPU -DI686_CPU -DUSER_PCICONF -DUSER_LDT -DAPERTURE -DCOMPAT_SVR4 -DCOMPAT_IBCS2 -DCOMPAT_LINUX -DCOMPAT_FREEBSD -DCOMPAT_BSDOS -DCOMPAT_AOUT -DPCIVERBOSE -DEISAVERBOSE -DUSBVERBOSE -DWSDISPLAY_COMPAT_USL -DWSDISPLAY_COMPAT_RAWKBD -DWSDISPLAY_DEFAULTSCREENS="6" -DWSDISPLAY_COMPAT_PCVT -DPCIAGP -D_KERNEL -Di386  -c /usr/src/sys/arch/i386/compile/SAMSKERNEL/../../../../netinet/if_ether.c

# -Werror

Import('default_env')

optimise='-O2 -pg'

env = default_env.Copy(GLB_LIST = curdir + '/global_list.txt')
env['CCFLAGS'] = ' -Wstrict-prototypes -Wmissing-prototypes  -Wno-uninitialized -Wno-format -Wno-main -march=i486 -fno-builtin-printf -fno-builtin-log '+optimise+'  -nostdinc' \
+ ' -DDDB -DDIAGNOSTIC -DKTRACE -DKMEMSTATS -DPTRACE -DCRYPTO -DSYSVMSG -DSYSVSEM -DSYSVSHM -DUVM_SWAP_ENCRYPT -DCOMPAT_43 -DLKM -DFFS -DFFS_SOFTUPDATES -DUFS_DIRHASH -DQUOTA -DEXT2FS -DMFS -DXFS -DTCP_SACK -DTCP_ECN -DTCP_SIGNATURE -DNFSCLIENT -DNFSSERVER -DCD9660 -DMSDOSFS -DFDESC -DFIFO -DKERNFS -DPORTAL -DPROCFS -DNULLFS -DUMAPFS -DUNION -DINET -DALTQ -DINET6 -DIPSEC -DPPP_BSDCOMP -DPPP_DEFLATE -DBOOT_CONFIG -DI586_CPU -DI686_CPU -DUSER_PCICONF -DUSER_LDT -DAPERTURE -DCOMPAT_SVR4 -DCOMPAT_IBCS2 -DCOMPAT_LINUX -DCOMPAT_FREEBSD -DCOMPAT_BSDOS -DCOMPAT_AOUT -DPCIVERBOSE -DEISAVERBOSE -DUSBVERBOSE -DWSDISPLAY_COMPAT_USL -DWSDISPLAY_COMPAT_RAWKBD -DWSDISPLAY_DEFAULTSCREENS="6" -DWSDISPLAY_COMPAT_PCVT -DPCIAGP -D_KERNEL -Di386'

env['CPPPATH'] = [ '.', 
'openbsd/' + 'usr/src/sys/arch/i386/compile/SAMSKERNEL',
'openbsd/' + 'usr/src/sys/arch/i386/compile/SAMSKERNEL/../../../../arch',
'openbsd/' + 'usr/src/sys/arch/i386/compile/SAMSKERNEL/../../../..',
'../sim'
]
env['CPPDEFINES'] = { 
# __OpenBSD__ needs to be defined (but not to anything)
    '__OpenBSD__':'',
# This changes the gcc attribute; it doesn't know about kprintf on non-
# OpenBSD systems I guess.
    '__kprintf__':'__printf__'
}
env['CCFLAGS'] += ' -U__FreeBSD__ '

ext_ccflags = ' -g -Wall -O '
linkflags = '-Wl,-O1  '

if os.uname()[4] == 'x86_64':
    ext_ccflags += '-m32 '
    linkflags += '-m32 '

cc = 'gcc-3.4'
cxx = 'g++-3.4'

env['CCFLAGS'] += ext_ccflags
env['CC'] = cc
#env['CXX'] = cxx

sources = []


sim_env = Environment(CPPFLAGS = ext_ccflags, 
        CPPPATH = ['../sim', 'support'])
sources += [ sim_env.SharedObject('support/sim_support.cpp') ]

# netccitt and netiso have problems compiling.
# netns has extra external references.
# not sure why I bother with atalk, ipx and natm
input_sources = [ 'kern/uipc_mbuf.c', 'kern/uipc_mbuf2.c', 'kern/kern_subr.c',
    'kern/uipc_domain.c', 'kern/uipc_socket2.c', 'kern/uipc_socket.c',
    'kern/kern_timeout.c' ] \
    + glob('netinet/*.c')\
    + glob('netatalk/*.c')\
    + glob('netipx/*.c')\
    + glob('netnatm/*.c')\
    + glob('netinet6/*.c')\
    + glob('crypto/*.c')\
    + [x for x in glob('net/*.c') if x != 'net/if_arcsubr.c' 
                                 and x != 'net/if_ieee80211subr.c'
                                 ]\
    + glob('altq/*.c')\
    + glob('support/*.c')

input_sources = [x for x in input_sources if x[-8:] != 'parsed.c']

# Tell our Parser to parse everything in input_sources
parsed_sources = []
for i in input_sources:
    output = os.path.splitext(i)[0]+'.parsed.c'
    parsed_sources.append( env.Parser(output, i) )
    # Make sure the parser is built so we can actually create the output
    # file.
    env.Depends(output, '#' + default_env['GLOBALISER'])

output = env.SharedLibrary(target = 'openbsd3.5', source =
    sources + parsed_sources,
    LINKFLAGS = linkflags
)
Install(dir = "..", source = output)
