make_distribution_library.anubis 8.33 KB


   Preparing the official distribution. 
   
      (AP 2014-08-26)


read tools/basis.anubis
read system/files.anubis

read official_library.anubis


type CompileFor:
  linux, 
  windows. 


define One
  do_one_file
  (
    String       srcdir, 
    String       dstdir, 
    String       name
  ) =
  with s = srcdir/name, 
       d = dstdir/name, 
  if copy_file(s,d) is 
  {
     cant_read_file         then print("Cannot read file '"+s+"'.\n")
     cant_create_file       then print("Cannot create file '"+d+"'.\n")
     copy_error             then print("Error while copying '"+s+"'.\n")
     copy_file_mode_error   then print("File mode error while copying '"+s+"'.\n")
     copy_file_times_error  then print("File time error while copying '"+s+"'.\n")
     copy_ok(written)       then print("'"+s+"' copied ("+to_decimal(written)+" bytes).\n")
  }. 

define One
  do_file
  (
    String       srcdir,
    String       dstdir, 
    String       mask 
  ) =
  with l = directory_full_list(srcdir,mask,"",""), 
  //print("in '"+srcdir+"' with mask '"+mask+"' found "+length(l)+" files.\n");
  map_forget((FileDescription fd) |-> (if fd is file(name,_,_,_)
                                       then do_one_file(srcdir,dstdir,name)  
                                       else unique)
             ,l).


define One
  do_for_item
  (
    CompileFor         system, 
    String             srcdir, 
    String             dstdir,
    AnubisSourceItem   i
  ).

define One
  do_directory
  (
    CompileFor                system, 
    String                    srcdir, 
    String                    dstdir,
    String                    name, 
    List(AnubisSourceItem)    content
  ) =
      with dname = dstdir/name, 
      if make_directory(dname,default_directory_mode) is 
      {
        permission_denied      then print("Cannot create directory '"+dname+"' (permission denied).\n"), 
        name_already_exists    then (print("Directory '"+dname+"' already exists.\n");
                                     map_forget((AnubisSourceItem i) |-> do_for_item(system,srcdir/name,dstdir/name,i),
                                                content)), 
        too_many_links         then print("Cannot create directory '"+dname+"' (too many links).\n"),
        not_enough_room        then print("Cannot create directory '"+dname+"' (not enough room).\n"),
        read_only_file_system  then print("Cannot create directory '"+dname+"' (read-only file system).\n"),
        ok                     then (print("Directory '"+dname+"' created.\n");
                                     map_forget((AnubisSourceItem i) |-> do_for_item(system,srcdir/name,dstdir/name,i),
                                                content))
      }.
  
  
  
  
define One
  do_for_item
  (
    CompileFor         system, 
    String             srcdir, 
    String             dstdir, 
    AnubisSourceItem   i
  ) =
  if i is directory(rel,name,content)
  then (if rel:[r,e] then do_directory(system,srcdir,dstdir,name,content) else unique)
  else if i is win32_file(_,_)
       then if system is 
         {
           linux   then unique, 
           windows then (if rel(i):[r,e] then do_file(srcdir,dstdir,name(i)) else unique)
         }
       else (if rel(i):[r,e] then do_file(srcdir,dstdir,name(i)) else unique). 
  

define Maybe(String)
  is_anubis_dev
  (
    ByteArray path,
    String    dest_name
  ) =
  with n = length(path),
  if extract(path,n-10,n) = to_byte_array("anubis_dev")
  then success(to_string(extract(path,0,n-10)+to_byte_array(dest_name)))
  else failure. 
  

define One
  print_item
  (
    WStream             fp,
    AnubisSourceItem    i,
    String              indent
  ). 

define One
  print_item_list
  (
    WStream                   fp, 
    List(AnubisSourceItem)    l,
    String                    indent
  ) =
  if l is 
  {
    [ ] then unique, 
    [h . t] then  
      (if rel(h):[r,e]
       then 
       (
         print_item(fp,h,indent); 
         print(fp,if t is [] then "\n" else ",\n")
       )
       else unique); 
      print_item_list(fp,t,indent)
  }.

define One
  print_item
  (
    WStream             fp,
    AnubisSourceItem    i,
    String              indent
  ) =
  if rel(i):[r,e]
  then if i is 
       {
         anubis_file(rel,name)        then print(fp,indent+"anubis_file     (\""+name+"\")"),  
         anubis_c_file(rel,name)      then print(fp,indent+"anubis_c_file   (\""+name+"\")"),  
         anubis_font(rel,name)        then print(fp,indent+"anubis_font     (\""+name+"\")"),  
         apg_file(rel,name)           then print(fp,indent+"apg_file        (\""+name+"\")"),  
         image(rel,name)              then print(fp,indent+"image           (\""+name+"\")"),  
         h_file(rel,name)             then print(fp,indent+"h_file          (\""+name+"\")"),  
         c_file(rel,name)             then print(fp,indent+"c_file          (\""+name+"\")"),  
         cpp_file(rel,name)           then print(fp,indent+"cpp_file        (\""+name+"\")"),  
         make_file(rel,name)          then print(fp,indent+"make_file       (\""+name+"\")"),  
         flex_file(rel,name)          then print(fp,indent+"flex_file       (\""+name+"\")"),  
         bison_file(rel,name)         then print(fp,indent+"bison_file      (\""+name+"\")"),  
         win32_file(rel,name)         then print(fp,indent+"win32_file      (\""+name+"\")"),  
         shell_file(rel,name)         then print(fp,indent+"shell_file      (\""+name+"\")"),  
         text_file(rel,name)          then print(fp,indent+"text_file       (\""+name+"\")"),  
         pdf_file(rel,name)           then print(fp,indent+"pdf_file        (\""+name+"\")"),  
         binary_file(rel,name)        then print(fp,indent+"binary_file     (\""+name+"\")"),  
         directory(rel,name,content)  then print(fp,indent+"directory       (\""+name+"\",\n"+indent+"  [\n");
             print_item_list(fp,content,indent+"    "); 
             print(fp,indent+"  ])")  
       }
  else unique. 

define One
  generate_released_library_description
  (
    One u
  ) =
  if file("library/official_released_library.anubis",new) is
  {
    failure    then print("Cannot create file 'library/official_released_library.anubis'.\n"), 
    success(f) then with fp = (WStream)weaken(f),
      print(fp,"\n               The Anubis Project\n");  
      print(fp,"\n  This file describes the official Anubis library as Anubis data.\n\n");
      print(fp,"public type AnubisLibraryItem:\n");
      print(fp,"  anubis_file     (String name),\n"); 
      print(fp,"  anubis_c_file   (String name),\n"); 
      print(fp,"  anubis_font     (String name),\n"); 
      print(fp,"  apg_file        (String name),\n"); 
      print(fp,"  image           (String name),\n"); 
      print(fp,"  text_file       (String name),\n"); 
      print(fp,"  pdf_file        (String name),\n"); 
      print(fp,"  directory       (String name, List(AnubisLibraryItem) content).\n\n");
      print(fp,"public define AnubisLibraryItem\n");
      print(fp,"  the_official_Anubis_library\n  =\n");
      print_item(fp,the_official_Anubis_files,"  ");
      print(fp,".\n\n")
  }. 



global define One
  make_linux_tarball
  (
    List(String) args
  ) =
  if get_environment_variable("HOME") is 
  {
    failure then print("Cannot find your home directory.\n"), 
    success(home_dir) then
      with main_name = name(the_official_Anubis_files),   // for example "anubis.1.14"
             src_dir = home_dir,
            dest_dir = home_dir/"linux_tarball",
        forget((String)make_directory(dest_dir));  
        do_for_item(linux,src_dir,dest_dir,the_official_Anubis_files);
        forget((Maybe(Word8))execute(success(dest_dir),"tar",["-czf",main_name+".tar.gz",main_name]))
  }. 
 
  
  

global define One
  make_distribution_library
  (
    List(String)   args   // not used
  ) =
  with cdir = get_current_directory,   // should be 'anubis_dev'
  print("Current directory: "+cdir+"\n"); 
  if is_anubis_dev(to_byte_array(cdir),"anubis_distrib") is 
  {
    failure then print("'anbexec make_distribution_library' must be executed from within 'anubis_dev'.\n"), 
    success(ddir) then 
      generate_released_library_description(unique); 
      do_for_item(cdir,ddir,the_official_Anubis_library); 
      do_for_item(cdir,ddir,the_official_Anubis_documentation); 
      do_for_item(cdir,ddir,the_official_Anubis_server_certs); 
      do_for_item(cdir,ddir,the_official_Anubis_trusted_certs) 
  }.