SConscript
changeset 0 aa628870c1d3
child 2 d1f6d8b6f81c
equal deleted inserted replaced
-1:000000000000 0:aa628870c1d3
       
     1 # vim:filetype=python
       
     2 
       
     3 #  Network Simulation Cradle
       
     4 #  Copyright (C) 2003-2005 Sam Jansen
       
     5 #
       
     6 #  This program is free software; you can redistribute it and/or modify it
       
     7 #  under the terms of the GNU General Public License as published by the Free
       
     8 #  Software Foundation; either version 2 of the License, or (at your option)
       
     9 #  any later version.
       
    10 #
       
    11 #  This program is distributed in the hope that it will be useful, but WITHOUT
       
    12 #  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13 #  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
       
    14 #  more details.
       
    15 #
       
    16 #  You should have received a copy of the GNU General Public License along
       
    17 #  with this program; if not, write to the Free Software Foundation, Inc., 59
       
    18 #  Temple Place, Suite 330, Boston, MA 02111-1307 USA
       
    19 
       
    20 # The following compilers have been shown to not be able to compile this code:
       
    21 #  - gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5) -- compiler bug
       
    22 
       
    23 import os, glob
       
    24 
       
    25 Import('default_env')
       
    26 
       
    27 stackname = "linux2.6.28"
       
    28 arch_i386 = default_env['NSC_TARGET_ARCHITECTURE'] != 'amd64'
       
    29 curdir = Dir('.').path + '/'
       
    30 
       
    31 net = {}
       
    32 net['core'] = Split("""
       
    33 datagram.c   ethtool.c        iovec.c                    sock.c
       
    34 dev.c        filter.c         link_watch.c               stream.c
       
    35 dev_mcast.c  flow.c           neighbour.c   rtnetlink.c  sysctl_net_core.c
       
    36 dst.c        gen_estimator.c  net-sysfs.c   scm.c        utils.c
       
    37              gen_stats.c      skbuff.c      netevent.c	net_namespace.c
       
    38 request_sock.c""")
       
    39 net['ethernet'] = Split("""
       
    40 eth.c""")
       
    41 net['ipv4'] = Split("""
       
    42 af_inet.c        icmp.c                     syncookies.c       udp.c	udplite.c
       
    43 ah4.c            igmp.c         ipconfig.c  sysctl_net_ipv4.c  
       
    44 arp.c            inetpeer.c                 tcp.c                            
       
    45 datagram.c       ip_forward.c   inet_diag.c                       
       
    46 devinet.c        ip_fragment.c              tcp_input.c                     
       
    47 esp4.c           tcp_ipv4.c
       
    48 fib_frontend.c   ip_input.c     tcp_minisocks.c
       
    49 fib_hash.c       ip_options.c   protocol.c  tcp_output.c
       
    50                  ip_output.c    raw.c       
       
    51 fib_semantics.c  ip_sockglue.c  route.c     tcp_timer.c
       
    52 inet_connection_sock.c
       
    53 inet_fragment.c
       
    54 tcp_cong.c	tcp_cubic.c	tcp_highspeed.c
       
    55 tcp_htcp.c	tcp_vegas.c	tcp_veno.c	tcp_westwood.c
       
    56 inet_hashtables.c		tcp_diag.c	tcp_scalable.c
       
    57 inet_timewait_sock.c 		tcp_hybla.c	tcp_illinois.c
       
    58 tcp_lp.c	tcp_bic.c	tcp_yeah.c""")
       
    59 net['ipv6'] = Split("""
       
    60 addrconf.c     addrlabel.c              protocol.c	syncookies.c
       
    61 udp.c	udplite.c
       
    62 af_inet6.c  icmp.c           ipv6_sockglue.c  raw.c
       
    63 ip6_fib.c  	reassembly.c
       
    64 anycast.c   ip6_flowlabel.c  mcast.c          route.c
       
    65 datagram.c  ip6_input.c      ndisc.c
       
    66 ip6_output.c                      sysctl_net_ipv6.c
       
    67 addrconf_core.c
       
    68 exthdrs.c                    tcp_ipv6.c
       
    69 inet6_hashtables.c	     inet6_connection_sock.c""")
       
    70 net['sctp'] = Split("""
       
    71 auth.c associola.c  endpointola.c  outqueue.c       sm_statefuns.c   tsnmap.c
       
    72 bind_addr.c  input.c        primitive.c      sm_statetable.c  ulpevent.c
       
    73 chunk.c      inqueue.c                socket.c         ulpqueue.c
       
    74 command.c    ipv6.c         protocol.c       ssnmap.c
       
    75 sm_make_chunk.c  sysctl.c
       
    76 debug.c      output.c       sm_sideeffect.c  transport.c""")
       
    77 
       
    78 # NOTE: DCCP does not work completely yet; there is an infinite loop when
       
    79 # a dccp connection is being shut down.
       
    80 # For the time being, it isn't compiled.
       
    81 net['dccp'] = Split("""
       
    82 feat.c   ipv4.c  minisocks.c  proto.c ccid.c options.c sysctl.c
       
    83 ackvec.c  input.c  output.c     timer.c
       
    84 ccids/ccid2.c""")
       
    85 net['dccp/ccids'] = Split("""
       
    86 loss_interval.c packet_history.c tfrc.c tfrc_equation.c""")
       
    87 
       
    88 net['netlink'] = Split("""
       
    89 attr.c
       
    90 af_netlink.c""")
       
    91 net['packet'] = ['af_packet.c']
       
    92 net['sched'] = Split("""
       
    93               cls_api.c        cls_u32.c    sch_atm.c             sch_hfsc.c
       
    94               cls_basic.c                   sch_blackhole.c       sch_htb.c
       
    95               cls_fw.c                      sch_cbq.c             sch_ingress.c
       
    96                                             sch_dsmark.c          sch_netem.c
       
    97                                             sch_fifo.c            sch_prio.c
       
    98               cls_rsvp.c                    sch_generic.c         sch_red.c
       
    99                                                                   sch_sfq.c
       
   100               cls_rsvp6.c      sch_tbf.c
       
   101               cls_tcindex.c    sch_api.c    sch_gred.c            sch_teql.c
       
   102 """)  
       
   103 net['.'] = ['socket.c', 'sysctl_net.c']
       
   104 
       
   105 # This array specifies the order. This order is used when linking; we need
       
   106 # to make sure things are linked in the correct order so the initialisation
       
   107 # functions -- initcall functions -- are called in the correct order.
       
   108 # There was a problem earlier where sctp_init was being called before
       
   109 # inet_init, which caused problems. The array below fixes that.
       
   110 dir_order = ['.', 'core', 'packet', 'sched', 'netlink', 'ethernet', 'ipv4', 
       
   111     'ipv6', 'sctp']
       
   112 src_to_globalise = reduce(lambda x,y:x+y,
       
   113     [['net/' + d + '/' + f for f in net[d]] for d in dir_order])
       
   114 
       
   115 src_to_globalise.extend([ 
       
   116     'nsc/unimplemented.c', 'nsc/implemented.c', 'nsc/support.c',
       
   117     'nsc/sysctl.c', 'nsc/tc.c', 'nsc/stub.c',
       
   118     'kernel/softirq.c', 'kernel/timer.c', 'kernel/itimer.c', 'kernel/sysctl.c',
       
   119     'kernel/rwsem.c', 'drivers/net/loopback.c', 'drivers/char/random.c',
       
   120     'lib/find_next_bit.c', 'lib/libcrc32c.c', 'lib/idr.c',
       
   121     'lib/rbtree.c', 'lib/hexdump.c'])
       
   122 
       
   123 sim_sources = ['nsc/sim_support.cpp']
       
   124 asm_sources = []
       
   125 
       
   126 if arch_i386:
       
   127     linker_script = 'arch/x86/kernel/linker-script-32.ld'
       
   128     asm_sources.extend(['arch/x86/lib/checksum_32.S'])
       
   129 else:
       
   130     linker_script = 'arch/x86/kernel/linker-script-64.ld'
       
   131     src_to_globalise.extend(['arch/x86/lib/csum-partial_64.c',
       
   132         'arch/x86/lib/csum-wrappers_64.c'])
       
   133     asm_sources.extend(['arch/x86/lib/csum-copy_64.S'])
       
   134 
       
   135 # -----------------------------------------------------------------------------
       
   136 cflags = ('-O -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -nostdinc '
       
   137     '-fno-inline -iwithprefix include -DKBUILD_BASENAME=\\"clnt\\" '
       
   138     '-DKBUILD_MODNAME=\\"nsc\\" -DMODVERSIONS -DEXPORT_SYMTAB '
       
   139     '-include linux/config.h -g')
       
   140 
       
   141 # You really need to undefine whatever symbol is defined for the operating
       
   142 # system you are compiling on and make sure the various linux symbols are
       
   143 # defined. __linux__ is the only important one I've found; though compilers
       
   144 # tend to define __linux and __Linux__ and so on and so forth.
       
   145 cflags += ' -U__FreeBSD__ -D__linux__=1 -Dlinux=1 -D__linux=1 '
       
   146 
       
   147 glb_cflags = '-include nsc_override.h '
       
   148 
       
   149 include_path = ['include', 'arch/x86/include', 'arch/x86/include/asm/mach-default', '../sim', 'nsc',
       
   150     'override']
       
   151 
       
   152 # We need a special linker script to set up some variables for
       
   153 # initialisation in Linux
       
   154 link_flags = '-Wl,-O1 -shared -Wl,-O1 -Wl,-T' + curdir + linker_script
       
   155 ext_cflags = ''
       
   156 as_flags = '-D__ASSEMBLY__'
       
   157 
       
   158 if arch_i386:
       
   159     cflags += '-DCONFIG_X86_32=1 '
       
   160 else:
       
   161     ext_cflags += '-fPIC '
       
   162     as_flags += '-fPIC '
       
   163     cflags += '-DCONFIG_X86_64=1 '
       
   164 
       
   165 cflags += ext_cflags
       
   166 
       
   167 # -----------------------------------------------------------------------------
       
   168 env = default_env.Clone(CCFLAGS=cflags, CPPPATH=include_path,
       
   169                         GLB_CCFLAGS=glb_cflags,
       
   170                         GLB_LIST=curdir + '/global_list.txt')
       
   171 sim_env = default_env.Clone(CCFLAGS='-g -Wall -O2 ' + ext_cflags,
       
   172                             CPPPATH=['../sim', 'nsc'])
       
   173 
       
   174 objects = env.Globaliser(src_to_globalise)
       
   175 objects.extend([sim_env.SharedObject(s) for s in sim_sources])
       
   176 objects.extend(asm_sources)
       
   177 
       
   178 # Using Program and -shared is a hacky way to make a shared library in SCons
       
   179 # without requiring -fPIC.
       
   180 env['LINKFLAGS'] += link_flags
       
   181 env['ASFLAGS'] += as_flags
       
   182 output = env.Program(source=objects, target='lib%s.so' % stackname)
       
   183 
       
   184 Install(dir = "..", source = output)