From 6c1154d80e7f7a04444d01d97942ac9e8138297a Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Fri, 29 Jan 2021 13:06:49 -0500 Subject: Cleaned up build system --- Makefile | 35 ++++++++++++++---------- README.md | 4 +-- do_buildroot.sh | 39 --------------------------- extract.sh | 69 ----------------------------------------------- resources/do_buildroot.sh | 36 +++++++++++++++++++++++++ resources/extract.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 124 deletions(-) delete mode 100755 do_buildroot.sh delete mode 100755 extract.sh create mode 100755 resources/do_buildroot.sh create mode 100755 resources/extract.sh diff --git a/Makefile b/Makefile index c488aa7..d2b5ce8 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,20 @@ +STRIP=strip + IDIR=include DEFINES=-DDETERMINISTIC CFLAGS=-O3 -Wall -Wextra -Wpedantic -std=c99 -D_DEFAULT_SOURCE $(DEFINES) -I$(IDIR) -lm LIBS= +CTAK=include/tak.c +CTAK_OBJS=$(CTAK:.c=.o) SRCS=$(wildcard include/*.c) OBJS=$(SRCS:.c=.o) BUILDROOT_DIR=buildroot-2020.11.1 +CROSS_CC=$(BUILDROOT_DIR)/output/host/bin/arm-linux-cc +CROSS_STRIP=$(BUILDROOT_DIR)/output/host/bin/arm-linux-strip -ifeq ($(PLATFORM), native) - STRIP=strip -else - STRIP=$(BUILDROOT_DIR)/output/host/bin/arm-linux-strip - CC=$(BUILDROOT_DIR)/output/host/bin/arm-linux-cc -endif +.DEFAULT_GOAL=native %.o: %.c $(CC) -c $< -o $@ $(CFLAGS) @@ -22,19 +23,25 @@ ctaklm: src/ctaklm.o $(OBJS) $(CC) $(CFLAGS) src/ctaklm.o $(OBJS) -o ctaklm $(STRIP) ctaklm -pptdb: src/pptdb.o $(OBJS) - $(CC) $(CFLAGS) src/pptdb.o $(OBJS) -o pptdb - ct1986: src/ct1986.o $(OBJS) $(CC) $(CFLAGS) src/ct1986.o $(OBJS) -o ct1986 $(STRIP) ct1986 -all: ctaklm ct1986 -ifneq ($(PLATFORM), native) - $(info Building the pi image) - ./do_buildroot.sh $(BUILDROOT_DIR) -endif +pptdb: src/pptdb.o $(CTAK_OBJS) + $(CC) $(CFLAGS) src/pptdb.o $(CTAK_OBJS) -o pptdb clean: rm -f ctaklm ct1986 pptdb rm -f src/*.o include/*.o + +native: clean ctaklm pptdb + +$(CROSS_CC): + ./resources/do_buildroot.sh $(BUILDROOT_DIR) + +pi: CC=$(CROSS_CC) +pi: STRIP=$(CROSS_STRIP) +pi: $(CROSS_CC) clean ctaklm ct1986 + cp ct1986 ctaklm $(BUILDROOT_DIR)/board/raspberrypi0/rootfs_overlay/ + make -C $(BUILDROOT_DIR) + $(info Image ready in $(BUILDROOT_DIR)/output/images/sdcard.img) diff --git a/README.md b/README.md index 0acbb9a..ea0e172 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Details forthcoming, but at a glance: ## Building for the native platform - PLATFORM=native make ctaklm + make native ## Building for the Raspberry Pi Zero @@ -20,7 +20,7 @@ Download and extract a recent version of buildroot into the working directory. Edit `BUILDROOT_DIR=buildroot-2020.11.1` in `Makefile` to point to the extracted directory. - make all + make pi ## The computer opponent diff --git a/do_buildroot.sh b/do_buildroot.sh deleted file mode 100755 index ee2e1d9..0000000 --- a/do_buildroot.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -# This file is part of ct1986 -# -# This program 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 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 -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Takwrap. If not, see . - -BR="$1" - -board="$BR/board/raspberrypi0/" -overlay="$board/rootfs_overlay/" - -# Build configuration -cp resources/buildroot.config "$BR/.config" -cp resources/linux.config resources/busybox.config "$board" # Causes recompile -cp resources/{post-build,ct1986}.sh resources/genimage-raspberrypi0.cfg "$board" - -# Overlay filesystem -dirs="/usr/bin" -for dir in $dirs; do - if [ ! -d "$overlay/$dir" ]; then - mkdir -p "$overlay/$dir" - fi -done - -cp ctaklm ct1986 "$overlay/usr/bin" -cp resources/ash-profile "$overlay/.profile" - -cd "$BR" && make diff --git a/extract.sh b/extract.sh deleted file mode 100755 index fb6f267..0000000 --- a/extract.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -db_file=games_anon.db - -chosen_players="fwwwwibib archvenison NohatCoder nqeron ManaT -SultanPepper orfane rabbitboy84 applemonkeyman Reid Tayacan Breeze -AaaarghBot" - -query() { - query="(size == $1) and (result != '1-0') and (result != '0-1') and (result != '0-0') and (result != '1/2-1/2')" - selct="" - for player in $chosen_players; do - selct="$selct(player_black == '$player') or (player_white == '$player') or " - done; - if [ -n "$selct" ]; then - query="$query and (${selct:0:-4})" - fi - echo "SELECT $2 FROM games WHERE $query;" -} - -extract() { - size="$1" - things="$2" - if [ ! -f "data/$db_file" ]; then - curl "https://www.playtak.com/games_anon.db" -o "data/$db_file" - fi - echo Extracing games of size "$size"... - sqlite3 "data/$db_file" "$(query $size $things)" | shuf > "data/playtak-$size" -} - -process() { - size=$1 - num_games=$2 - fn=$3 - - ./pptdb "$size" "data/playtak-$size" > "data/check-$size" - tail -n22 "data/check-$size" - echo -ne "\tStripping overflows and illegal games... " - grep -Fvxf "data/check-$size" "data/playtak-$size" > "data/good-playtak-$size" - - echo -en "Done.\n\tGenerating training data... " - ./pptdb "$size" "data/good-playtak-$size" generate - - echo -en "\tChoosing $num_games of $(wc -l data/training-$size.csv | cut -d\ -f1) samples... " - head -n 1 "data/training-$size.csv" > "data/shuf-$size.csv" - tail -n+2 "data/training-$size.csv" > "data/tmp" - shuf -n $num_games "data/tmp" >> "data/shuf-$size.csv" - rm data/tmp - - echo -en "Done.\n\tCompressing data... " - mv "data/shuf-$size.csv" "data/$fn-$size.csv" - if [ -f "data/$fn-$size.csv.gz" ]; then - rm "data/$fn-$size.csv.gz" - fi - gzip "data/$fn-$size.csv" - echo "Done, available in data/$fn-$size.csv.gz" -} - -if [ ! -d data ]; then - mkdir data -fi - -make pptdb - -for size in 5; do - echo - extract $size notation,result - process $size 400000 training -done diff --git a/resources/do_buildroot.sh b/resources/do_buildroot.sh new file mode 100755 index 0000000..2df2e76 --- /dev/null +++ b/resources/do_buildroot.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# This file is part of ct1986 +# +# This program 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 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 +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Takwrap. If not, see . + +BR="$1" + +board="$BR/board/raspberrypi0/" +overlay="$board/rootfs_overlay/" + +# Build configuration +cp resources/buildroot.config "$BR/.config" +cp resources/linux.config resources/busybox.config "$board" # Causes recompile +cp resources/post-build.sh resources/ct1986.sh resources/genimage-raspberrypi0.cfg "$board" + +# Overlay filesystem +dirs="/usr/bin" +for dir in $dirs; do + if [ ! -d "$overlay/$dir" ]; then + mkdir -p "$overlay/$dir" + fi +done + +cd "$BR" && make diff --git a/resources/extract.sh b/resources/extract.sh new file mode 100755 index 0000000..fb6f267 --- /dev/null +++ b/resources/extract.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +db_file=games_anon.db + +chosen_players="fwwwwibib archvenison NohatCoder nqeron ManaT +SultanPepper orfane rabbitboy84 applemonkeyman Reid Tayacan Breeze +AaaarghBot" + +query() { + query="(size == $1) and (result != '1-0') and (result != '0-1') and (result != '0-0') and (result != '1/2-1/2')" + selct="" + for player in $chosen_players; do + selct="$selct(player_black == '$player') or (player_white == '$player') or " + done; + if [ -n "$selct" ]; then + query="$query and (${selct:0:-4})" + fi + echo "SELECT $2 FROM games WHERE $query;" +} + +extract() { + size="$1" + things="$2" + if [ ! -f "data/$db_file" ]; then + curl "https://www.playtak.com/games_anon.db" -o "data/$db_file" + fi + echo Extracing games of size "$size"... + sqlite3 "data/$db_file" "$(query $size $things)" | shuf > "data/playtak-$size" +} + +process() { + size=$1 + num_games=$2 + fn=$3 + + ./pptdb "$size" "data/playtak-$size" > "data/check-$size" + tail -n22 "data/check-$size" + echo -ne "\tStripping overflows and illegal games... " + grep -Fvxf "data/check-$size" "data/playtak-$size" > "data/good-playtak-$size" + + echo -en "Done.\n\tGenerating training data... " + ./pptdb "$size" "data/good-playtak-$size" generate + + echo -en "\tChoosing $num_games of $(wc -l data/training-$size.csv | cut -d\ -f1) samples... " + head -n 1 "data/training-$size.csv" > "data/shuf-$size.csv" + tail -n+2 "data/training-$size.csv" > "data/tmp" + shuf -n $num_games "data/tmp" >> "data/shuf-$size.csv" + rm data/tmp + + echo -en "Done.\n\tCompressing data... " + mv "data/shuf-$size.csv" "data/$fn-$size.csv" + if [ -f "data/$fn-$size.csv.gz" ]; then + rm "data/$fn-$size.csv.gz" + fi + gzip "data/$fn-$size.csv" + echo "Done, available in data/$fn-$size.csv.gz" +} + +if [ ! -d data ]; then + mkdir data +fi + +make pptdb + +for size in 5; do + echo + extract $size notation,result + process $size 400000 training +done -- cgit v1.2.3