Ada: Unterschied zwischen den Versionen

Aus FabLab Region Nürnberg
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 93: Zeile 93:
|  
|  
     0001:  # ############################################################################
     0001:  # ############################################################################
     0001:  #  Copyright (C) 2022 by                                                    #
     0002:  #  Copyright (C) 2022 by                                                    #
     0001:  #  Christoph Stadelmann, M.Sc.                                              #
     0003:  #  Christoph Stadelmann, M.Sc.                                              #
     0001:  #                                                                            #
     0004:  #                                                                            #
     0001:  #  This file is free software; you can redistribute it and/or modify        #
     0005:  #  This file is free software; you can redistribute it and/or modify        #
     0001:  #  it under the terms of the GNU General Public License as published by    #
     0006:  #  it under the terms of the GNU General Public License as published by    #
     0001:  #  the Free Software Foundation; either version 2 of the License, or        #
     0007:  #  the Free Software Foundation; either version 2 of the License, or        #
     0001:  #  (at your option) any later version.                                      #
     0008:  #  (at your option) any later version.                                      #
     0001:  #                                                                            #
     0009:  #                                                                            #
     0001:  #  This program is distributed in the hope that it will be useful,          #
     0010:  #  This program is distributed in the hope that it will be useful,          #
     0001:  #  but WITHOUT ANY WARRANTY; without even the implied warranty of          #
     0011:  #  but WITHOUT ANY WARRANTY; without even the implied warranty of          #
     0001:  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
     0012:  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
     0001:  #  GNU General Public License for more details.                            #
     0013:  #  GNU General Public License for more details.                            #
     0001:  #                                                                            #
     0014:  #                                                                            #
     0001:  #  You should have received a copy of the GNU General Public License        #
     0015:  #  You should have received a copy of the GNU General Public License        #
     0001:  #  along with this program; if not, write to the                            #
     0016:  #  along with this program; if not, write to the                            #
     0001:  #  Free Software Foundation, Inc.,                                          #
     0017:  #  Free Software Foundation, Inc.,                                          #
     0001:  #  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                #
     0018:  #  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                #
     0001:  # ############################################################################
     0019:  # ############################################################################
     0001:   
     0020:   
     0001:  PROJECT_NAME                = ADA_PRGM_0000_hello_world
     0021:  PROJECT_NAME                = ADA_PRGM_0000_hello_world
     0001:   
     0022:   
     0001:  TARGET_EXEC_NAME            = hello_world.exec
     0023:  TARGET_EXEC_NAME            = hello_world.exec
     0001:   
     0024:   
     0001:   
     0025:   
     0001:  # ############################################################################
     0026:  # ############################################################################
     0001:  # all
     0027:  # all
     0001:  # ############################################################################
     0028:  # ############################################################################
     0001:   
     0029:   
     0001:  GNAT                        = /usr/bin/i686-linux-gnu-gcc
     0030:  GNAT                        = /usr/bin/i686-linux-gnu-gcc
     0001:  GNATBIND                    = /usr/bin/i686-linux-gnu-gnatbind
     0031:  GNATBIND                    = /usr/bin/i686-linux-gnu-gnatbind
     0001:  GNATLINK                    = /usr/bin/i686-linux-gnu-gnatlink
     0032:  GNATLINK                    = /usr/bin/i686-linux-gnu-gnatlink
     0001:   
     0033:   
     0001:  FOLDERS                      = work \
     0034:  FOLDERS                      = work \
     0001:                                ../BACKUP
     0035:                                ../BACKUP
     0001:   
     0036:   
     0001:  ADA_BODIES                  = $(shell cd ada_body; ls *.adb)
     0037:  ADA_BODIES                  = $(shell cd ada_body; ls *.adb)
     0001:                                 
     0038:                                 
     0001:  .PHONY: all
     0039:  .PHONY: all
     0001:  all: $(FOLDERS)
     0040:  all: $(FOLDERS)
     0001:  cp  $(shell pwd)/ada_body/*.adb  $(shell pwd)/ada_package/*.ads  $(shell pwd)/work
     0041:  cp  $(shell pwd)/ada_body/*.adb  $(shell pwd)/ada_package/*.ads  $(shell pwd)/work
     0001:  (cd $(shell pwd)/work; \
     0042:  (cd $(shell pwd)/work; \
     0001:  for item in $(ADA_BODIES); do \
     0043:  for item in $(ADA_BODIES); do \
     0001:      $(GNAT) -c $$item; \
     0044:      $(GNAT) -c $$item; \
     0001:  done ; \
     0045:  done ; \
     0001:  $(GNATBIND) main; \
     0046:  $(GNATBIND) main; \
     0001:  $(GNATLINK) main; \
     0047:  $(GNATLINK) main; \
     0001:  cp main ../$(TARGET_EXEC_NAME))
     0048:  cp main ../$(TARGET_EXEC_NAME))
     0001:  echo "all done"
     0049:  echo "all done"
     0001:  echo "$(ADA_BODIES)"
     0040:  echo "$(ADA_BODIES)"
     0001:   
     0041:   
     0001:  # ############################################################################
     0042:  # ############################################################################
     0001:  # $(FOLDERS)
     0043:  # $(FOLDERS)
     0001:  # ############################################################################
     0044:  # ############################################################################
     0001:   
     0045:   
     0001:  work:
     0046:  work:
     0001:  mkdir -p $@
     0047:  mkdir -p $@
     0001:   
     0048:   
     0001:  ../BACKUP:
     0049:  ../BACKUP:
     0001:  mkdir -p $@
     0050:  mkdir -p $@
     0001:   
     0051:   
     0001:   
     0052:   
     0001:  # ############################################################################
     0053:  # ############################################################################
     0001:  # edit, clean
     0054:  # edit, clean
     0001:  # ############################################################################
     0055:  # ############################################################################
     0001:   
     0056:   
     0001:  .PHONY: edit
     0057:  .PHONY: edit
     0001:  edit:
     0058:  edit:
     0001:  kate makefile  ada_body/*.adb  ada_package/*.ads &
     0059:  kate makefile  ada_body/*.adb  ada_package/*.ads &
     0001:  echo "edit done"
     0060:  echo "edit done"
     0001:   
     0061:   
     0001:   
     0062:   
     0001:  .PHONY: clean
     0063:  .PHONY: clean
     0001:  clean:
     0064:  clean:
     0001:  rm -f  $(shell pwd)/*.exec
     0065:  rm -f  $(shell pwd)/*.exec
     0001:  rm -f  $(shell pwd)/work/*      $(shell pwd)/work/*.*
     0066:  rm -f  $(shell pwd)/work/*      $(shell pwd)/work/*.*
     0001:  echo "clean done"
     0067:  echo "clean done"
     0001:   
     0068:   
     0001:   
     0069:   
     0001:  # ############################################################################
     0070:  # ############################################################################
     0001:  # backup
     0071:  # backup
     0001:  # ############################################################################
     0072:  # ############################################################################
     0001:   
     0073:   
     0001:  BACKUP_OBJECTS                                  = makefile  ada_body/*.adb  ada_package/*.ads
     0074:  BACKUP_OBJECTS                                  = makefile  ada_body/*.adb  ada_package/*.ads
     0001:   
     0075:   
     0001:  .PHONY: backup
     0076:  .PHONY: backup
     0001:  backup: $(FOLDERS)
     0077:  backup: $(FOLDERS)
     0001:  zip -r ../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).zip $(BACKUP_OBJECTS) >
     0088:  zip -r ../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).zip $(BACKUP_OBJECTS) >
  ../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).txt
  ../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).txt
     0001:  @echo "backup done"
     0089:  @echo "backup done"
     0001:                                                                                                       
     0090:                                                                                                       
|}
|}



Version vom 3. Dezember 2022, 00:16 Uhr

Ada

Framework

Zum Erstellen eines lauffähigen Programms unter Linux muss der Quelltext, welcher kompiliert werden soll, in ein Framework eingefügt werden. Dieses besteht im Wesentlichen aus einer flachen Ordnerstruktur, in welcher neben Paket-Header-Dateien (engl: *.ads) und Paket-Implementierungs-Dateien (engl: *.adb) temporäre Dateien sortiert sind. Zur Kompilierung und zur Dateiverwaltung unter Verwendung des Steuerprogramms "make" genügt eine Steuerdatei namens "makefile" im Wurzelverzeichnis. Die Bedienung des Frameworks erfolgt unter Verwendung der Kommandozeile.


Ordner "ada_package"

In diesem Ordner werden alle Paket-Header-Dateien (engl: *.ads) abgelegt.

Ordner "ada_body"

In diesem Ordner werden alle Paket-Implementierungs-Dateien (engl: *.adb) abgelegt.

Ordner "work"

Hier werden während des Kompiliervorgangs temporäre Dateien erzeugt. Der Inhalt des Ordners muss weder bearbeitet noch archiviert werden.

Ordner "../BACKUP"

Es besteht die Möglichkeit, unter Verwendung der Steuerdatei Zwischenstände abzuspeichern. Die Quelltexte in den Ordnern "ada_body" und "ada_package" werden in einer Zip-Datei archiviert. Der Name der Zip-Datei in der Steuerdatei unter Verwendung des Projektnamens, eines Datumstempels und eines Zeitstempels automatisch vergeben.




Erstes Programm: Hallo Welt!

Dieses Programm gibt die Zeichenkette "Hallo Welt!" unter Verwendung der Bibliothek "Ada.Text_IO" in der Kommandozeile aus.

ada_body/*.adb: Paket-Implementierungs-Dateien

main.adb
   0001:  with Ada.Text_IO;
   0002:  with Greetings_Task;
   0003:
   0004:  procedure main is
   0005:      use Ada.Text_IO;
   0006:  begin
   0007:      Put_Line( "Hallo Welt!" );
   0008:      Greetings_Task.Goodby;
   0009:  end main;
   0010:                                                                                                       


greetings_task.ads
   0001:  with Ada.Text_IO;
   0002:  
   0003:  package body Greetings_Task is
   0004:      procedure Goodby is
   0005:      begin
   0006:          Ada.Text_IO.Put_Line("Goodby");
   0007:      end Goodby;
   0008:  end Greetings_Task;
   0009:                                                                                                       


ada_package/*.ads: Paket-Header-Dateien

greetings_task.ads
   0001:  package Greetings_Task is
   0002:      procedure Goodby;
   0003:  end Greetings_Task;
   0004:                                                                                                       


makefile

makefile
   0001:  # ############################################################################
   0002:  #   Copyright (C) 2022 by                                                    #
   0003:  #   Christoph Stadelmann, M.Sc.                                              #
   0004:  #                                                                            #
   0005:  #   This file is free software; you can redistribute it and/or modify        #
   0006:  #   it under the terms of the GNU General Public License as published by     #
   0007:  #   the Free Software Foundation; either version 2 of the License, or        #
   0008:  #   (at your option) any later version.                                      #
   0009:  #                                                                            #
   0010:  #   This program is distributed in the hope that it will be useful,          #
   0011:  #   but WITHOUT ANY WARRANTY; without even the implied warranty of           #
   0012:  #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
   0013:  #   GNU General Public License for more details.                             #
   0014:  #                                                                            #
   0015:  #   You should have received a copy of the GNU General Public License        #
   0016:  #   along with this program; if not, write to the                            #
   0017:  #   Free Software Foundation, Inc.,                                          #
   0018:  #   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                #
   0019:  # ############################################################################
   0020:  
   0021:  PROJECT_NAME                 = ADA_PRGM_0000_hello_world
   0022:  
   0023:  TARGET_EXEC_NAME             = hello_world.exec
   0024:  
   0025:  
   0026:  # ############################################################################
   0027:  #	all
   0028:  # ############################################################################
   0029:  
   0030:  GNAT                         = /usr/bin/i686-linux-gnu-gcc
   0031:  GNATBIND                     = /usr/bin/i686-linux-gnu-gnatbind
   0032:  GNATLINK                     = /usr/bin/i686-linux-gnu-gnatlink
   0033:  
   0034:  FOLDERS                      = work \
   0035:                                 ../BACKUP
   0036:  
   0037:  ADA_BODIES                   = $(shell cd ada_body; ls *.adb)
   0038:                                 
   0039:  .PHONY: all
   0040:  all: $(FOLDERS)
   0041:  	cp   $(shell pwd)/ada_body/*.adb   $(shell pwd)/ada_package/*.ads   $(shell pwd)/work
   0042:  	(cd $(shell pwd)/work; \
   0043:  	for item in $(ADA_BODIES); do \
   0044:  	     $(GNAT) -c $$item; \
   0045:  	done ; \
   0046:  	$(GNATBIND) main; \
   0047:  	$(GNATLINK) main; \
   0048:  	cp main ../$(TARGET_EXEC_NAME))
   0049:  	echo "all done"
   0040:  	echo "$(ADA_BODIES)"
   0041:  
   0042:  # ############################################################################
   0043:  #	$(FOLDERS)
   0044:  # ############################################################################
   0045:  
   0046:  work:
   0047:  	mkdir -p $@
   0048:  
   0049:  ../BACKUP:
   0050:  	mkdir -p $@
   0051:  
   0052:  
   0053:  # ############################################################################
   0054:  #	edit, clean
   0055:  # ############################################################################
   0056:  
   0057:  .PHONY: edit
   0058:  edit:
   0059:  	kate makefile   ada_body/*.adb   ada_package/*.ads &
   0060:  	echo "edit done"
   0061:  
   0062:  
   0063:  .PHONY: clean
   0064:  clean:
   0065:  	rm -f   $(shell pwd)/*.exec
   0066:  	rm -f   $(shell pwd)/work/*       $(shell pwd)/work/*.*
   0067:  	echo "clean done"
   0068:  
   0069:  
   0070:  # ############################################################################
   0071:  #	backup
   0072:  # ############################################################################	
   0073:  
   0074:  BACKUP_OBJECTS                                  = makefile   ada_body/*.adb   ada_package/*.ads
   0075:  
   0076:  .PHONY: backup
   0077:  backup: $(FOLDERS)
   0088:  	zip -r ../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).zip $(BACKUP_OBJECTS) >
../BACKUP/ZIP__$(PROJECT_NAME)__$$(date +"%Y_%m%d_%H%M%S" -u).txt
   0089:  	@echo "backup done"
   0090:                                                                                                       


Stand: 2022_1202