Added a Bash script to increment or decrement build numbers.

This commit is contained in:
2020-03-08 22:58:37 -05:00
parent cd7efed090
commit b9f68c4348
4 changed files with 145 additions and 0 deletions
View File
+55
View File
@@ -0,0 +1,55 @@
CC = gcc
GCCPARAMS = -m32 -fno-pie -nostdlib -fstrength-reduce -fomit-frame-pointer -finline-functions -fno-builtin -nostdinc -fno-stack-protector
ASPARAMS = -f elf32
LDPARAMS = -m elf_i386
INCBULDNUM = sh make_buildnum.sh
SRC := kernel
OBJ := obj
SOURCES := $(wildcard $(SRC)/*.c)
ASMSOURCES := $(wildcard $(SRC)/*.asm)
OBJECTS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SOURCES))
ASMOBJECTS := $(patsubst $(SRC)/%.asm, $(OBJ)/%.o, $(ASMSOURCES))
run:kernel.iso
qemu-system-x86_64 -serial pipe:/tmp/guest -m 256M -cdrom kernel.iso &
$(OBJ)/%.o: $(SRC)/%.c
mkdir -p $(@D)
$(CC) $(GCCPARAMS) $(SRC) -c -o $@ $<
$(OBJ)/%.o: $(SRC)/%.asm
mkdir -p $(@D)
nasm $(ASPARAMS) -o $@ $<
kernel.bin: $(OBJECTS) $(ASMOBJECTS)
@#Crap way to increment the build number, but will do for now
@#thanks to my limited knowledge of Makefiles.
@#Sadly this number in the compiled code will always be off by one with this method....
@sh make_buildnum.sh
mkdir -p obj/bin
ld $(LDPARAMS) -T linker.ld -o obj/bin/$@ $(OBJECTS) $(ASMOBJECTS)
kernel.iso: kernel.bin
mkdir iso
mkdir iso/boot
mkdir iso/boot/grub
cp obj/bin/kernel.bin iso/boot/kernel.bin
echo 'set timeout=0' > iso/boot/grub/grub.cfg
echo 'set default=0' >> iso/boot/grub/grub.cfg
echo '' >> iso/boot/grub/grub.cfg
echo 'menuentry "SDOS" {' >> iso/boot/grub/grub.cfg
echo ' multiboot /boot/kernel.bin' >> iso/boot/grub/grub.cfg
echo ' boot' >> iso/boot/grub/grub.cfg
echo '}' >> iso/boot/grub/grub.cfg
grub-mkrescue --output=kernel.iso iso
rm -rf iso
.PHONY: clean
clean:
rm -rf obj/* kernel.iso
.PHONY: resetbuild
resetbuild:
echo 0 > build.number
+6
View File
@@ -0,0 +1,6 @@
#ifndef KERNEL_VERSION_NUMBER
#define KERNEL_VERSION_NUMBER "1.4.10-47"
#endif
#ifndef CONSOLE_VERSION_NUMBER
#define CONSOLE_VERSION_NUMBER "0.4.5-48"
#endif
+84
View File
@@ -0,0 +1,84 @@
#!/bin/bash
#Following the the spec set here https://semver.org/ (2.0.0)
#we have three parts to a version number:
major=0
minor=0
patch_level=0
#And there is a fourth additional label for the build metadata.
#These labels are for pre-release and build metadata.
meta=0
folder=$(dirname "$1")
parent_folder=$(basename "$folder")
#Capitalize the folder name so it matches the format in the C #define files.
parent_folder=${parent_folder^^}
define_count=0
file_contents=""
#Looping code from
#https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable
#Adding numbers in bash:
#https://stackoverflow.com/questions/6348902/how-can-i-add-numbers-in-a-bash-script
while IFS=' ' read -ra line; do
if [[ $line != \#define* ]]
then
continue
fi
#Lob off the quotes surrounding the version number.
#version_number="${line[2]:1:-1}"
version_number=($(echo ${line[2]:1:-1} | tr "-" "."))
#The symbol name that #define was setting (i.e. KERNEL_VERSION_NUMBER).
symbol=${line[1]}
for i in "${my_array[@]}"
do
echo $i
done
IFS='.' read -a chunks <<<$version_number
version_part_counter=0
for i in "${chunks[@]}"; do
case "$version_part_counter" in
"0")
major=$i
;;
"1")
minor=$i
;;
"2")
patch_level=$i
;;
"3")
#Check to see if a second parameter has been passed.
#It doesn't matter what its value is only that one is present.
#If there isn't a second parameter set, then we increment the meta build
#number, otherwise we decrement.
if [ "$2" == "" ]
then
meta=$(($i + 1))
else
if [ $meta > 0 ]
then
meta=$(($i - 1))
fi
fi
;;
esac
version_part_counter=$(($version_part_counter + 1))
done
ver="$major.$minor.$patch_level-$meta"
tmp="#ifndef ${symbol}\n#define ${symbol} \"$ver\"\n#endif\n"
file_contents="$file_contents$tmp"
define_count=$(($define_count + 1))
done < "$1"
printf "$file_contents"
echo "$1"
printf "$file_contents" > "$1"