Browse Source

Add an automatic build environment setup script for POSIX-compliant systems.

coderain 8 months ago
parent
commit
e06a5d13a3

+ 8 - 2
.gitignore

@@ -6,6 +6,13 @@
 !README.md
 !grub.cfg
 !Makefile
+!common.mk
+!syscalls.awk
+!setup
+!tools
+!tools/keyring.gpg
+!tools/packages
+!tools/packages/*.sig
 !kernel
 !kernel/*
 !crt
@@ -20,7 +27,6 @@
 !drivers/**
 !sdk
 !sdk/*
-!syscalls.awk
 
-# Exclude generate files:
+# Exclude generated files:
 sdk/syscall_enum.h

+ 12 - 7
Makefile

@@ -1,6 +1,12 @@
 .PHONY: all clean crt kernel drivers library manager tests generate
 
-GENERATED_SOURCES = sdk/syscall_enum.h kernel/src/syscall_table.inl library/src/wrappers.c
+TOOLSDIR     := tools
+TOOLSROOTDIR := root
+
+PROJECT_ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
+export PATH  := $(PROJECT_ROOT)/$(TOOLSDIR)/$(TOOLSROOTDIR)/bin:$(PATH)
+
+GENERATED_SOURCES := sdk/syscall_enum.h kernel/src/syscall_table.inl library/src/wrappers.c
 
 all: livecd.iso tests
 
@@ -32,12 +38,11 @@ kernel/src/syscall_table.inl: sdk/syscall_enum.h
 
 library/src/wrappers.c: sdk/syscall_enum.h
 
-livecd.iso: kernel drivers library manager
-	mkdir -p livecd/boot/grub
-	cp kernel/monolithium livecd/boot/monolithium
-	mkdir -p livecd/boot/drivers
-	find drivers -type f -name '*.drv' -exec cp {} livecd/boot/drivers/ \;
-	cp manager/manager livecd/manager
+livecd.iso : kernel drivers library manager
+	mkdir -p livecd/monolithium livecd/boot/grub livecd/monolithium/drivers
+	cp kernel/monolithium livecd/monolithium/kernel
+	find drivers -type f -name '*.drv' -exec cp {} livecd/monolithium/drivers/ \;
+	cp manager/manager livecd/monolithium/manager
 	cp grub.cfg livecd/boot/grub/grub.cfg
 	grub-mkrescue -o $@ livecd
 

+ 6 - 5
README.md

@@ -47,10 +47,11 @@ the project.
 
 ### COMPILING ###
 
+Run the "setup" script to download, configure, and locally install required
+packages, then run "make". To speed things up, use the -j flag to compile with
+more threads in parallel.
+
 Prerequisites:
 
-* [GNU GCC](https://gcc.gnu.org/), built for the i686-elf target
-* [GNU Binutils](https://www.gnu.org/software/binutils/), also built for the i686-elf target
-* [NASM](http://www.nasm.us/)
-* grub-mkrescue
-* Other tools required by scripts: GNU coreutils, mkfs.vfat, xxd, ...
+* A POSIX-compatible environment.
+* An internet connection (to download required packages).

+ 88 - 0
common.mk

@@ -0,0 +1,88 @@
+#
+# common.mk
+#
+# Copyright (C) 2018 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+ARCH := i686-elf
+
+# Directories
+SRCDIR       := src
+OBJDIR       := obj
+DEPDIR       := dep
+TOOLSDIR     := tools
+TOOLSROOTDIR := root
+
+PROJECT_ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
+export PATH  := $(PROJECT_ROOT)/$(TOOLSDIR)/$(TOOLSROOTDIR)/bin:$(PATH)
+
+# Compilers and tools
+CC   := $(ARCH)-gcc
+ASM  := nasm
+LINK := $(ARCH)-ld
+
+ifeq ($(DEBUG), yes)
+    CFLAGS += -g -DDEBUG
+else
+    CFLAGS += -O3
+endif
+
+ifeq ($(LINK_WITH_LIBGCC), yes)
+	LIBGCCDIR := $(shell PATH=$(PATH) $(CC) -print-file-name=)
+	LDFLAGS   += -L "$(LIBGCCDIR)" -lgcc
+endif
+
+# Output files
+OUTPUTS := $(OUTPUT_KERNEL) $(OUTPUT_PROGRAM) $(OUTPUT_DRIVER) $(OUTPUT_STATIC_LIB) $(OUTPUT_DYNAMIC_LIB) $(ADDITIONAL_OBJECTS)
+DEPENDS := $(shell find $(DEPDIR) -type f -name \*.d)
+OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
+
+.PHONY: all clean
+
+all: $(OBJDIR) $(DEPDIR) $(OUTPUTS)
+
+-include $(DEPENDS)
+
+clean:
+	rm -f $(OUTPUTS)
+	find $(OBJDIR) -name \*.o -delete
+	find $(DEPDIR) -name \*.d -delete
+
+$(OBJDIR):
+	mkdir -p $(OBJDIR)
+
+$(DEPDIR):
+	mkdir -p $(DEPDIR)
+
+$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
+	mkdir -p $(dir $@)
+	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
+	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+
+$(OBJDIR)/%.o: $(SRCDIR)/%.asm Makefile
+	$(ASM) $(ASMFLAGS) -o $@ $<
+
+$(OUTPUT_KERNEL): $(OBJECTS) $(ADDITIONAL_OBJECTS)
+	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+
+$(OUTPUT_PROGRAM): $(OBJECTS)
+	$(LINK) -eprocess_startup -o $@ $(OBJECTS) $(LDFLAGS)
+
+$(OUTPUT_STATIC_LIB): $(OBJECTS)
+	$(AR) rcs $@ $^
+
+$(OUTPUT_DYNAMIC_LIB) $(OUTPUT_DRIVER): $(OBJECTS)
+	$(LINK) -shared -o $@ $(OBJECTS) $(LDFLAGS)

+ 5 - 47
crt/Makefile

@@ -17,59 +17,17 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+# Settings
 DEBUG = yes
 
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-AR = i686-elf-ar
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
 # Flags
-CFLAGS = -Wall -Werror -ffreestanding -nostdlib -fPIC -I include -I ../sdk
-ASMFLAGS = -felf
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+CFLAGS   := -Wall -Werror -ffreestanding -nostdlib -fPIC -I include -I ../sdk
+ASMFLAGS := -felf
 
 # Input and output files
 SOURCES =  $(wildcard $(SRCDIR)/*.c)
 SOURCES += $(wildcard $(SRCDIR)/*.asm)
 
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) libmlcrt.a
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm Makefile
-	$(ASM) $(ASMFLAGS) -o $@ $<
-
-libmlcrt.a: $(OBJECTS)
-	$(AR) rcs $@ $^
+OUTPUT_STATIC_LIB = libmlcrt.a
 
-clean:
-	rm -f libmlcrt.a
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
+-include ../common.mk

+ 7 - 51
drivers/acpica/Makefile

@@ -18,61 +18,17 @@
 #
 
 # Settings
-DEBUG  = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
-CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I include -I ../../kernel/include -I ../../crt/include
-ASMFLAGS = -felf
-LDFLAGS = -shared
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I include -I ../../kernel/include -I ../../crt/include
+ASMFLAGS := -felf
 
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+LINK_WITH_LIBGCC := yes
 
 # Input and output files
-SOURCES =  $(shell find $(SRCDIR) -type f -name \*.c)
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) acpica.drv
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f acpica.drv
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+SOURCES = $(shell find $(SRCDIR) -type f -name \*.c)
 
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+OUTPUT_DRIVER := acpica.drv
 
-acpica.drv: $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../../common.mk

+ 6 - 53
drivers/fatfs/Makefile

@@ -18,62 +18,15 @@
 #
 
 # Settings
-DEBUG  = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
-CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
-ASMFLAGS = -felf
-LDFLAGS = -shared
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
+ASMFLAGS := -felf
 
 # Input and output files
-SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(wildcard $(SRCDIR)/*.asm)
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) fatfs.drv
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f fatfs.drv
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+OUTPUT_DRIVER := fatfs.drv
 
-fatfs.drv: $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../../common.mk

+ 6 - 53
drivers/floppy/Makefile

@@ -18,62 +18,15 @@
 #
 
 # Settings
-DEBUG  = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
-CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
-ASMFLAGS = -felf
-LDFLAGS = -shared
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
+ASMFLAGS := -felf
 
 # Input and output files
-SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(wildcard $(SRCDIR)/*.asm)
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) floppy.drv
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f floppy.drv
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+OUTPUT_DRIVER := floppy.drv
 
-floppy.drv: $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../../common.mk

+ 6 - 53
drivers/ps2/Makefile

@@ -18,62 +18,15 @@
 #
 
 # Settings
-DEBUG  = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
-CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
-ASMFLAGS = -felf
-LDFLAGS = -shared
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
+ASMFLAGS := -felf
 
 # Input and output files
-SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(wildcard $(SRCDIR)/*.asm)
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) ps2.drv
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f ps2.drv
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+OUTPUT_DRIVER := ps2.drv
 
-ps2.drv: $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../../common.mk

+ 6 - 53
drivers/ramfs/Makefile

@@ -18,62 +18,15 @@
 #
 
 # Settings
-DEBUG  = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
-CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
-ASMFLAGS = -felf
-LDFLAGS = -shared
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
+ASMFLAGS := -felf
 
 # Input and output files
-SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(wildcard $(SRCDIR)/*.asm)
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) ramfs.drv
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f ramfs.drv
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+OUTPUT_DRIVER := ramfs.drv
 
-ramfs.drv: $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../../common.mk

+ 6 - 53
drivers/serial/Makefile

@@ -18,62 +18,15 @@
 #
 
 # Settings
-DEBUG  = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
-CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
-ASMFLAGS = -felf
-LDFLAGS = -shared
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
+ASMFLAGS := -felf
 
 # Input and output files
-SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(wildcard $(SRCDIR)/*.asm)
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) serial.drv
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f serial.drv
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+OUTPUT_DRIVER := serial.drv
 
-serial.drv: $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../../common.mk

+ 4 - 51
drivers/speaker/Makefile

@@ -18,62 +18,15 @@
 #
 
 # Settings
-DEBUG  = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
 CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
 ASMFLAGS = -felf
-LDFLAGS = -shared
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
 
 # Input and output files
-SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(wildcard $(SRCDIR)/*.asm)
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) speaker.drv
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f speaker.drv
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+OUTPUT_DRIVER := speaker.drv
 
-speaker.drv: $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../../common.mk

+ 4 - 51
drivers/vesa/Makefile

@@ -18,62 +18,15 @@
 #
 
 # Settings
-DEBUG  = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
 CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I ../.. -I ../../kernel/include -I ../../crt/include
 ASMFLAGS = -felf
-LDFLAGS = -shared
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
 
 # Input and output files
-SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(wildcard $(SRCDIR)/*.asm)
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) vesa.drv
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f vesa.drv
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+OUTPUT_DRIVER := vesa.drv
 
-vesa.drv: $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../../common.mk

+ 10 - 9
grub.cfg

@@ -1,11 +1,12 @@
 menuentry "Monolithium OS" {
-    multiboot2 /boot/monolithium manager:Floppy0/MANAGER debug:COM1
-    module2 /boot/drivers/acpica.drv
-    module2 /boot/drivers/fatfs.drv
-    module2 /boot/drivers/floppy.drv
-    module2 /boot/drivers/ps2.drv
-    module2 /boot/drivers/ramfs.drv
-    module2 /boot/drivers/serial.drv
-    module2 /boot/drivers/speaker.drv
-    module2 /boot/drivers/vesa.drv
+    multiboot2 /monolithium/kernel manager:Floppy0/MONOLI~1/MANAGER debug:COM1
+    module2 /monolithium/drivers/acpica.drv
+    module2 /monolithium/drivers/fatfs.drv
+    module2 /monolithium/drivers/floppy.drv
+    module2 /monolithium/drivers/isocdfs.drv
+    module2 /monolithium/drivers/ps2.drv
+    module2 /monolithium/drivers/ramfs.drv
+    module2 /monolithium/drivers/serial.drv
+    module2 /monolithium/drivers/speaker.drv
+    module2 /monolithium/drivers/vesa.drv
 }

+ 8 - 51
kernel/Makefile

@@ -18,30 +18,14 @@
 #
 
 # Settings
-DEBUG = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-elf-ld
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+DEBUG := yes
 
 # Flags
-CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I include -I .. -I ../crt/include
-ASMFLAGS = -felf
-LDFLAGS = -T link.ld -L $(LIBGCC_DIR) -L ../crt -lgcc -lmlcrt -lgcc
+CFLAGS   := -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I include -I .. -I ../crt/include
+ASMFLAGS := -felf
+LDFLAGS  := -T link.ld -L ../crt -lmlcrt
 
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g -DDEBUG
-else
-    CFLAGS += -O3
-endif
+LINK_WITH_LIBGCC := yes
 
 # Input and output files
 SOURCES =  $(wildcard $(SRCDIR)/*.c)
@@ -49,34 +33,7 @@ SOURCES += $(wildcard $(SRCDIR)/memory/*.c)
 SOURCES += $(wildcard $(SRCDIR)/exec/*.c)
 SOURCES += $(wildcard $(SRCDIR)/*.asm)
 
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) monolithium
-
-clean:
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
-	rm -f monolithium
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm
-	mkdir -p $(dir $@)
-	$(ASM) $(ASMFLAGS) -o $@ $<
+ADDITIONAL_OBJECTS := obj/boot/boot.o
+OUTPUT_KERNEL := monolithium
 
-monolithium: $(OBJDIR)/boot/boot.o $(OBJECTS)
-	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)
+-include ../common.mk

+ 1 - 1
kernel/link.ld

@@ -10,7 +10,7 @@ SECTIONS
     .code ALIGN(0x1000) : AT(ADDR(.code) - 0x7FF00000)
     {
         _code = .;
-        *(.text);
+        *(.text*);
         . = ALIGN(4096);
     }
 

+ 8 - 51
library/Makefile

@@ -17,59 +17,16 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-DEBUG = yes
+# Settings
+DEBUG := yes
 
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-AR = i686-elf-ar
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-# Flags
-CFLAGS = -Wall -Werror -ffreestanding -nostdlib -fPIC -I ..
-ASMFLAGS = -felf
-
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+CFLAGS   := -Wall -Werror -ffreestanding -nostdlib -fPIC -I ..
+ASMFLAGS := -felf
 
 # Input and output files
-SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(wildcard $(SRCDIR)/*.asm)
-
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(WRAPPERS) $(OBJDIR) $(DEPDIR) libmlsys.a
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm Makefile
-	$(ASM) $(ASMFLAGS) -o $@ $<
+SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/*.asm)
 
-libmlsys.a: $(OBJECTS)
-	$(AR) rcs $@ $^
+OUTPUT_STATIC_LIB  := libmlsys.a
+OUTPUT_DYNAMIC_LIB := mlsys.dyn
 
-clean:
-	rm -f libmlsys.a
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
+-include ../common.mk

+ 9 - 52
manager/Makefile

@@ -17,64 +17,21 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-DEBUG = yes
-
-# Compilers and tools
-CC = i686-elf-gcc
-ASM = nasm
-LINK = i686-aout-ld
-OBJCOPY = i686-elf-objcopy
-
-# Directories
-SRCDIR = src
-OBJDIR = obj
-DEPDIR = dep
-
-LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+# Settings
+DEBUG := yes
 
 # Flags
-CFLAGS = -Wall -Werror -ffreestanding -nostdlib -I ../sdk
-ASMFLAGS = -felf
-LDFLAGS = -mi386aout -e process_startup -L $(LIBGCC_DIR) -lgcc -L ../library -lmlsys
+CFLAGS   += -Wall -Werror -ffreestanding -nostdlib -I ../sdk -I ../crt/include
+ASMFLAGS += -felf
+LDFLAGS  += -T link.ld -L ../library -L ../crt -lmlcrt -lmlsys
 
-ifeq ($(DEBUG), yes)
-    CFLAGS += -g
-else
-    CFLAGS += -O3
-endif
+LINK_WITH_LIBGCC := yes
 
 # Input and output files
 SOURCES =  $(wildcard $(SRCDIR)/*.c)
+SOURCES += $(wildcard $(SRCDIR)/servers/*.c)
 SOURCES += $(wildcard $(SRCDIR)/*.asm)
 
-DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
-OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
-
-.PHONY: all clean
-
-all: $(OBJDIR) $(DEPDIR) manager
-
--include $(DEPENDS)
-
-$(OBJDIR):
-	mkdir -p $(OBJDIR)
-
-$(DEPDIR):
-	mkdir -p $(DEPDIR)
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
-	mkdir -p $(dir $@)
-	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
-	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
-	$(OBJCOPY) --keep-file-symbols -j .text -j .data -j .bss $@ $@
-
-$(OBJDIR)/%.o: $(SRCDIR)/%.asm Makefile
-	$(ASM) $(ASMFLAGS) -o $@ $<
-
-manager: $(OBJECTS)
-	$(LINK) $(LDFLAGS) -o $@ $^
+OUTPUT_PROGRAM := manager
 
-clean:
-	rm -f manager
-	find $(OBJDIR) -name \*.o -delete
-	find $(DEPDIR) -name \*.d -delete
+-include ../common.mk

+ 263 - 0
setup

@@ -0,0 +1,263 @@
+#!/bin/sh
+
+TOOLSDIR='tools'
+PACKAGESDIR='packages'
+WORKSPACEDIR='workspace'
+TOOLSROOTDIR='root'
+KEYRING='keyring.gpg'
+GNUMIRROR='ftp.gnu.org'
+
+packages=' '
+
+package_binutils_protocols=' https http ftp '
+package_binutils_server=$GNUMIRROR
+package_binutils_remotedir='/gnu/binutils'
+package_binutils_filename='binutils-2.30'
+package_binutils_extensions=' tar.xz tar.lz tar.bz2 tar.gz '
+package_binutils_recipe='setup_binutils'
+
+package_gawk_protocols=' https http ftp '
+package_gawk_server=$GNUMIRROR
+package_gawk_remotedir='/gnu/gawk'
+package_gawk_filename='gawk-4.2.1'
+package_gawk_extensions=' tar.xz tar.lz tar.gz '
+package_gawk_recipe='setup_gawk'
+
+package_gcc_protocols=' https http ftp '
+package_gcc_server=$GNUMIRROR
+package_gcc_remotedir='/gnu/gcc/gcc-7.3.0'
+package_gcc_filename='gcc-7.3.0'
+package_gcc_extensions=' tar.xz tar.gz '
+package_gcc_recipe='setup_gcc'
+
+package_grub_protocols=' https http ftp '
+package_grub_server=$GNUMIRROR
+package_grub_remotedir='/gnu/grub'
+package_grub_filename='grub-2.02'
+package_grub_extensions=' tar.xz tar.gz '
+package_grub_recipe='setup_grub'
+
+package_nasm_protocols=' http '
+package_nasm_server='www.nasm.us'
+package_nasm_remotedir='/pub/nasm/releasebuilds/2.13.03'
+package_nasm_filename='nasm-2.13.03'
+package_nasm_extensions=' tar.xz tar.bz2 tar.gz zip '
+package_nasm_recipe='setup_nasm'
+
+package_xorriso_protocols=' https http ftp '
+package_xorriso_server=$GNUMIRROR
+package_xorriso_remotedir='/gnu/xorriso'
+package_xorriso_filename='xorriso-1.4.8'
+package_xorriso_extensions=' tar.gz '
+package_xorriso_recipe='setup_xorriso'
+
+setup_binutils() {
+    cd 'binutils-2.30' && ./configure "--prefix=$PREFIX" --target=i686-elf --disable-nls && make $MAKEFLAGS && make install
+}
+
+setup_gawk() {
+    cd 'gawk-4.2.1' && ./configure "--prefix=$PREFIX" && make $MAKEFLAGS && make install
+}
+
+setup_gcc() {
+    cd 'gcc-7.3.0' && mkdir -p build && cd build \
+        && ../configure "--prefix=$PREFIX" --target=i686-elf --enable-languages=c --without-headers --disable-nls --disable-libssp \
+        && make $MAKEFLAGS all-gcc && make $MAKEFLAGS all-target-libgcc \
+        && make install-gcc && make install-target-libgcc
+}
+
+setup_grub() {
+    cd 'grub-2.02' && ./configure "--prefix=$PREFIX" && make $MAKEFLAGS && make install
+}
+
+setup_nasm() {
+    cd 'nasm-2.13.03' && ./configure "--prefix=$PREFIX" && make $MAKEFLAGS && make install
+}
+
+setup_xorriso() {
+    cd 'xorriso-1.4.8' && ./configure "--prefix=$PREFIX" && make $MAKEFLAGS && make install
+}
+
+download() {
+    download_url="$1://$2/$3"
+
+    if [ -n "$AXEL" ]
+    then
+        "$AXEL" -o "$4" "$download_url"
+    elif [ -n "$WGET" ]
+    then
+        "$WGET" -O "$4" "$download_url"
+    elif [ -n "$CURL" ]
+    then
+        "$CURL" -L -o "$4" "$download_url"
+    elif [ -n "$PFTP" ] && [ "$1" = "ftp" ]
+    then
+        separator=`expr index + "$2" + :`
+
+        if  [ $separator -ne 0 ]
+        then
+            host=`expr substr + "$2" 1 \( "$separator" - 1 \)`
+            port=`expr substr + "$2" \( $separator + 1 \) \( length + "$2" \)`
+        else
+            host="$2"
+            port=""
+        fi
+
+        "$PFTP" -n $host $port <<EOF
+user ftp
+binary
+get "$remotepath" "$localpath"
+quit
+EOF
+    else
+        printf 'No suitable program available to download "%s". Giving up.\n' "$url" 1>&2
+        exit 1
+    fi
+}
+
+extract() {
+    if expr + "$1" : '.*\.tar.*' 1>/dev/null
+    then
+        "$TAR" -C "$2" -x -f "$1"
+    elif expr + "$1" : '.*\.zip$' 1>/dev/null
+    then
+        "$UNZIP" "$1" -d "$2"
+    fi
+}
+
+[ -d "$TOOLSDIR" ] || mkdir "$TOOLSDIR" || exit 1
+cd "$TOOLSDIR" || exit 1
+
+[ -d "$PACKAGESDIR" ]  || mkdir "$PACKAGESDIR"  || exit 1
+[ -d "$WORKSPACEDIR" ] || mkdir "$WORKSPACEDIR" || exit 1
+[ -d "$TOOLSROOTDIR" ] || mkdir "$TOOLSROOTDIR" || exit 1
+
+export PATH="$PWD/$TOOLSROOTDIR/bin:$PATH"
+
+AXEL=`command -v axel`
+WGET=`command -v wget`
+CURL=`command -v curl`
+FTP=`command -v ftp`
+PFTP=`command -v pftp` || ([ -n "$FTP" ] && PFTP="$FTP -p")
+TAR=`command -v tar`
+UNZIP=`command -v unzip`
+
+if ! GPG=`command -v gpg`
+then
+    echo 'GNU Privacy Guard is required to verify signatures. Please install it.' 1>&2
+    exit 1
+fi
+
+ARCHIVES=' '
+
+if [ -n "$TAR" ]
+then
+    for comp in xz.xz lzip.lz bzip2.bz2 gzip.gz
+    do
+        program=`expr substr "$comp" 1 \( index + "$comp" . - 1 \)`
+        extension=`expr substr "$comp" \( index + "$comp" . + 1 \) \( length $comp \)`
+        command -v "$program" 1>/dev/null && ARCHIVES="${ARCHIVES}tar.$extension "
+    done
+fi
+
+[ -n "$UNZIP" ] && ARCHIVES="${ARCHIVES}zip "
+
+echo 'Detecting installed packages...' 1>&2
+command -v gawk || packages="${packages}gawk "
+command -v i686-elf-gcc || packages="${packages}gcc "
+command -v i686-elf-ld || packages="${packages}binutils "
+command -v grub-mkrescue || packages="${packages}grub "
+command -v nasm || packages="${packages}nasm "
+command -v xorriso || packages="${packages}xorriso "
+
+for package in $packages
+do
+    printf 'Installing package %s\n' "$package" 1>&2
+    [ -d "$WORKSPACEDIR/$package" ] || mkdir "$WORKSPACEDIR/$package" || exit 1
+
+    unset packagefile
+
+    eval "protocols=\"\$package_${package}_protocols\"\
+          server=\"\$package_${package}_server\"\
+          remotedir=\"\$package_${package}_remotedir\"\
+          filename=\"\$package_${package}_filename\"\
+          extensions=\"\$package_${package}_extensions\"\
+          recipe=\"\$package_${package}_recipe\""
+
+    for ext in $extensions
+    do
+        printf '%s' "$ARCHIVES" | grep -q -F " $ext " || continue
+
+        file="${filename}.$ext"
+        url="$remotedir/$file"
+
+        if ! [ -f "$PACKAGESDIR/$file" ]
+        then
+            success=false
+
+            for protocol in $protocols
+            do
+                printf 'Downloading %s from %s://%s/%s\n' "$file" "$protocol" "$server" "$url" 1>&2
+                if download "$protocol" "$server" "$url" "$PACKAGESDIR/$file"
+                then
+                    success=true
+                    break
+                fi
+            done
+
+            if ! $success
+            then
+                echo 'Download failed.' 1>&2
+                continue
+            fi
+        fi
+
+        packagefile="$PACKAGESDIR/$file"
+        break;
+    done
+
+    if [ -z "$packagefile" ]
+    then
+        printf 'No files could be downloaded and/or extracted to install package %s. Giving up.\n' "$package" 1>&2
+        exit 1
+    fi
+
+    if ! [ -f ${packagefile}.sig ]
+    then
+        printf 'Retrieving signature %s\n' "${packagefile}.sig" 1>&2
+        if ! download "$protocol" "$server" "${url}.sig" "${packagefile}.sig"
+        then
+            printf 'Could not retrieve the signature for %s. Giving up.\n' "$packagefile" 1>&2
+            exit 1
+        fi
+    fi
+
+    printf 'Verifying signature %s\n' "${packagefile}.sig" 1>&2
+    if ! "$GPG" --no-default-keyring --keyring "$PWD/$KEYRING" --verify "${packagefile}.sig" "$packagefile"
+    then
+        printf 'bad\nCould not verify the signature for %s. Giving up.\n' "$packagefile" 1>&2
+        exit 1
+    fi
+
+    printf 'Extracting archive %s\n' "$file" 1>&2
+    if ! extract "$packagefile" "$WORKSPACEDIR/$package"
+    then
+        printf 'The package archive %s could not be extracted. Giving up.\n' "$packagefile" 1>&2
+        exit 1
+    fi
+
+    oldwd="$PWD"
+    export PREFIX="$PWD/$TOOLSROOTDIR"
+    cd "$WORKSPACEDIR/$package"
+    $recipe
+    errorcode=$?
+    cd "$oldwd"
+
+    if [ "$errorcode" -ne 0 ]
+    then
+        printf 'Errors occurred while building package %s. Giving up.\n' "$package" 1>&2
+        exit 1
+    fi
+done
+
+echo 'Done installing packages' 1>&2

BIN
tools/keyring.gpg


BIN
tools/packages/nasm-2.13.03.tar.bz2.sig


BIN
tools/packages/nasm-2.13.03.tar.gz.sig


BIN
tools/packages/nasm-2.13.03.tar.xz.sig


BIN
tools/packages/nasm-2.13.03.zip.sig