aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Host/LowLevel/PrinterHost/makefile
blob: 225f8b298282fb8eb0f8291bebefac6296742b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
#             LUFA Library
#     Copyright (C) Dean Camera, 2019.
#
#  dean [at] fourwalledcubicle [dot] com
#           www.lufa-lib.org
#
# --------------------------------------
#         LUFA Project Makefile.
# --------------------------------------

# Run "make help" for target help.

MCU          = at90usb1287
ARCH         = AVR8
BOARD        = USBKEY
F_CPU        = 8000000
F_USB        = $(F_CPU)
OPTIMIZATION = s
TARGET       = PrinterHost
SRC          = $(TARGET).c ConfigDescriptor.c Lib/PrinterCommands.c $(LUFA_SRC_USB) $(LUFA_SRC_SERIAL)
LUFA_PATH    = ../../../../LUFA
CC_FLAGS     = -DUSE_LUFA_CONFIG_HEADER -IConfig/
LD_FLAGS     =

# Default target
all:

# Include LUFA-specific DMBS extension modules
DMBS_LUFA_PATH ?= $(LUFA_PATH)/Build/LUFA
include $(DMBS_LUFA_PATH)/lufa-sources.mk
include $(DMBS_LUFA_PATH)/lufa-gcc.mk

# Include common DMBS build system modules
DMBS_PATH      ?= $(LUFA_PATH)/Build/DMBS/DMBS
include $(DMBS_PATH)/core.mk
include $(DMBS_PATH)/cppcheck.mk
include $(DMBS_PATH)/doxygen.mk
include $(DMBS_PATH)/dfu.mk
include $(DMBS_PATH)/gcc.mk
include $(DMBS_PATH)/hid.mk
include $(DMBS_PATH)/avrdude.mk
include $(DMBS_PATH)/atprogram.mk
f { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
----------------------------------------------------------------------------
--      get_entities (get_entities.adb)
--
--               Copyright (C) 2013, Brian Drummond
--
--      This file is part of the ghdl-updates project.
--
--      get_entities 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.
--
--      get_entities 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 get_entities.  If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------

with Ada.Text_Io; use Ada.Text_IO;
with Ada.Characters.Handling;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Ada.Strings.Unbounded;
with Ada.Directories;
with Ada.Command_Line;

procedure get_entities is

   function Valid_Test(Name : in String) return boolean is
      use Ada.Directories;
      use Ada.Characters.Handling;
   begin
      return Extension(To_Lower(Name)) = "vhd"
        or Extension(To_Lower(Name)) = "vhdl";
   end Valid_Test;

   procedure Get_Top_Entities(Test_Name : in String) is
      use Ada.Text_Io;
      use Ada.Strings.Fixed;
      use Ada.Characters.Handling;
      use Ada.Strings.Unbounded;

      File : File_Type;

      function Get_End(Line : in String) return Natural is
         Comment : natural := Index(Line,"--");
      begin
         if Comment = 0 then
            return Line'last;
         else
            return Comment - 1;
         end if;
      end Get_End;

      type State_Type is (Idle, Have_Entity, Have_Name, In_Entity);
      State : State_Type;

      Top_Level_Entity : Boolean;
      Name : Unbounded_String;

      Last_Entity : Unbounded_String;
   begin
   -- Return the name of all top-level entities in the file.
   -- Report on stderr, a malformed one
   -- "malformed" means not conforming to the expectations of this simple parser.
   -- A top level entity has the form
   -- Entity <name> is
   -- <no port clause>
   -- end {entity} <name>

      Open(File, In_File, Test_Name);
      State := Idle;
      loop
         declare
            -- strip name of blanks etc...
            CharSet       : constant Ada.Strings.Maps.Character_Ranges := (('A','Z'), ('a','z'), ('0','9'), ('_','_'));

            function Token(Source, Name : String; From : positive := 1) return natural is
               use Ada.Strings.Maps;
               Pos : natural := Index(Source, Name, From => From);
            begin
               -- Look in Source for Name, either surrounded by whitespace or at the start or end of a line
               if Pos = 0 or Pos = 1 or Pos + Name'Length > Source'Length then
                  return Pos;
               elsif not is_in (Source(Pos - 1), To_Set(CharSet)) and
                     not is_in (Source(Pos + Name'Length), To_Set(CharSet)) then
                  return Pos;
               else
                  return 0;
               end if;
            end Token;

            function  Strip_Quoted(Raw : String) return String is
               temp : String(Raw'range);
               t    : natural := Raw'first;
               copy : Boolean := true;
            begin
               -- Eliminate quoted text
               for i in Raw'range loop
                  if copy then
                     if Raw(i) = '"' then
                        copy := not copy;
                     else
                        temp(t) := Raw(i);
                        t := t + 1;
                     end if;
                  else
                     if Raw(i) = '"' then
                        copy := not copy;
                     end if;
                  end if;
               end loop;
               if t > Raw'last then t := Raw'last; end if;
               return temp(Raw'first .. t);
            end Strip_Quoted;

	    Line    : String  := Get_Line (File); -- line based to strip off comments
            EndLine : natural := Get_End (Line);
            Raw     : String  := To_Lower(Line (1 .. EndLine));
            Code    : String  := Strip_Quoted(Raw);
            -- positions of specific strings in a line.
            Ent     : Natural := Token(Code, "entity");
            Port    : Natural := Token(Code, "port");
            End_Pos : Natural := Token(Code, "end");
            I       : Natural;  -- position of "is" in current line
            Name_s  : Natural;	-- start of a possible entity name
            Name_e  : Natural;  -- end of a possible entity name
            Name_n  : Natural;  -- start of next name (should be "is")
            Dot     : Natural;  -- position of "." indicating qualified name, e.g. entity instantiation

            procedure Get_Name is
            begin
               Name_e := Index(Code, Ada.Strings.Maps.To_Set(CharSet),
                                        Test => Ada.Strings.Outside, From => Name_s);
               if Name_e = 0 then Name_e := Code'last; end if;
               --Put_Line("Name : " & To_S(Name) & " "
               --           & natural'image(Name_s) & " " & natural'image(Name_e)
               --           & natural'image(Code'last));
               if Name_e < Code'last then
                  Name_n := Index(Code, Ada.Strings.Maps.To_Set(CharSet), From => Name_e);
               else
                  Name_n := 0;
               end if;
               I := Token(Code, "is", From => Name_e);
               Dot := Index(Code, ".", From => Name_e);

               if Name_e < Name_s then
                  Put_Line(Standard_Error, "Malformed name : " & Code);
               end if;
               Name := To_Unbounded_String (Code (Name_s .. Name_e-1));
               if I = 0 then  -- "is" must be on a subsequent line
                  State := Have_Name;
               elsif Name_n = I then   -- next word is "is"
                  State := In_Entity;
               elsif Dot < Name_n and Dot >= Name_e then
                  -- direct instantiation ... reject
                  State := Idle;
               elsif Name_n < I then
                  Put_Line(Standard_Error, "Name error : file " & Test_Name);
                  Put_Line(Standard_Error, "Entity : """ & Code(Name_s .. I-1) & """ not valid");
                  -- raise Program_Error;
               end if;
            end Get_Name;

         begin
            case State is
               when Idle =>
                  if Ent /= 0 then
                     -- Put_Line(Code);
                     Top_Level_Entity := True;
                     Name_s := Index(Code, Ada.Strings.Maps.To_Set(CharSet), From => Ent + 6);

                     if Name_s = 0 then -- entity name must be on a subsequent line
                        State := Have_Entity;
                     else
                        Get_Name;
                     end if;
                  end if;
               when Have_Entity =>
                  Name_s := Index(Code, Ada.Strings.Maps.To_Set(CharSet), From => Ent + 6);
                  if Name_s > 0 then
                     Get_Name;
                  end if;
               when Have_Name =>
                  if I > 0 then
                     State := In_Entity;
                  end if;
               when In_Entity =>  -- wait for End, handle Port;
                  -- NB the End may not be End Entity, but whatever it Ends, it must follow the port list
                  -- so we may stop looking for a port list when we see it.
                  if Port > 0 then
                     Top_Level_Entity := False;
                  end if;
                  if End_Pos > 0 then 
                     if Top_Level_Entity then -- write name to stdout
                        Last_Entity := Name;
                     end if;
                     State := Idle;
                  end if;
            end Case;
	    exit when End_Of_File (File);
         end;
      end loop;

      if Last_Entity /= "" then
         Put_Line (To_String (Last_Entity));
      end if;
      Close(File);

   end Get_Top_Entities;

   procedure Usage is
   begin
      Put_Line(Standard_Error,
               "Usage : " & Ada.Command_Line.Command_Name & " <filename>");
   end Usage;

begin
   if Ada.Command_Line.Argument_Count = 0 then
      raise Program_Error;
   end if;
   Get_Top_Entities(Ada.Command_Line.Argument(1));
exception
   when Program_Error => Usage;
end get_entities;