30th November 2008, 03:52 pm
# A Makefile to compile NXC code using NBC
# Copyright (C) 2008 Gary French
#
# 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 2 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.
#
INCLUDEDIR =../include
NBC=/usr/local/bin/nbc
NBC_FLAGS=-I=$(INCLUDEDIR)
#optional compiler optimizations
# NBC_FLAGS=-I=$(INCLUDEDIR) -Z1
# NBC_FLAGS=-I=$(INCLUDEDIR) -Z2
#this can also be explicitly set
# NXC_FILES := TheProgram.nxc
NXC_FILES := $(shell ls -1 -t -F *.nxc 2>/dev/null | grep '\.nxc')
RXE_FILES := $(NXC_FILES:.nxc=.rxe)
BYTECODE_FILES := $(NXC_FILES:.nxc=.bytecode)
LISTING_FILES := $(NXC_FILES:.nxc=.listing)
SYMTABLE_FILES := $(NXC_FILES:.nxc=.symtable)
#the targets can be called individually, or called from the "all" target
#all: compile bytecode listing symtable
all: compile
compile: $(RXE_FILES)
%.rxe: $(NXC_FILES)
@echo "compiling $<"
$(NBC) $(NBC_FLAGS) -O=$@ $<
@echo
bytecode: $(BYTECODE_FILES)
%.bytecode: $(NXC_FILES)
@echo "generating bytecode for $<"
$(NBC) $(NBC_FLAGS) -b -nbc=$@ $<
@echo
listing: $(LISTING_FILES)
%.listing: $(NXC_FILES)
@echo "generating code listing for $<"
$(NBC) $(NBC_FLAGS) -b -L=$@ $<
@echo
symtable: $(SYMTABLE_FILES)
%.symtable: $(NXC_FILES)
@echo "generating symbol table for $<"
$(NBC) $(NBC_FLAGS) -b -Y=$@ $<
@echo
clean:
@echo "cleaning up..."
-rm $(RXE_FILES)
-rm $(BYTECODE_FILES)
-rm $(LISTING_FILES)
-rm $(SYMTABLE_FILES)
@echo
.PHONY: clean bytecode listing symtable
23rd November 2008, 07:36 pm
you must be able to communicate with the NXT Brick for any of the following to be applicable. there are a few “how-to”s available, including this post.
I am using the compiler available at Next Byte Codes & Not eXactly C site. This is a simple package package to “install” (simply copying the executable from the tar/gzip to /usr/local/bin did it for me), and is wonderfully documented.
I am using a modified version of a script provided by Jan-Klaas Kollhof:
#!/bin/sh
set -e
_nbcpath=/PATH/TO/NBC/EXECUTABLE/DIRECTORY
_dirname=`dirname $1`
if [ "${_dirname}" == "." ]; then
_dirname=$(pwd)
fi
_basename=`basename $1 .nxc`
echo "compiling ${_basename}.rxe from ${_basename}.nxc..."
${_nbcpath}/nbc \
-O="${_dirname}/${_basename}.rxe" \
-nbc="${_dirname}/${_basename}.nbc" \
"${_dirname}/${_basename}.nxc"
echo "sending ${_basename}.rxe to brick..."
cd "${_dirname}"
nxt_push "${_basename}.rxe"
as should be apparent, /PATH/TO/NBC/EXECUTABLE/DIRECTORY will need to be altered to suit your environment.
the “-nbc” switch will save the generated “Next Byte Code” to YOUR_CODE_FILE_NAME.nbc. the resulting file is not only interesting to poke around in, but may help when optimizing for size.
currently, I am having some issues with nxt_python, documented here.
22nd November 2008, 12:56 pm
not much yet, but with two development forks we’ll probably have something workable soon.
as of 11/16/2008:
a few test ideas.
as of 11/22/2008:
some general refinements, and the software to raise and lower the whatever-the-hell-that-is is working.
PuzzleBot - 2008-11-28