configure: add a proper configure script

It's not very good, but it supports all of the options by the
previous far-worse Makefile configure targets, and also now supports
out-of-tree builds.

Also include the relevent updates to the .buildbot script and
.gitignore.
This commit is contained in:
2017-05-28 23:08:13 -07:00
parent ba534f81e4
commit 6a9e8b06a7
5 changed files with 137 additions and 58 deletions

View File

@@ -4,19 +4,25 @@ set -e
do_build() do_build()
{ {
make config-default mkdir build || true
cd build
../configure
make make
} }
do_test() do_test()
{ {
make config-debug mkdir build || true
cd build
../configure --debug
make check make check
} }
do_coverage() do_coverage()
{ {
make config-coverage mkdir build || true
cd build
../configure --coverage
make coverage-report make coverage-report
mkdir -p ./buildbot-upload/coverage/ mkdir -p ./buildbot-upload/coverage/
cp -r ./build/coverage/html/* ./buildbot-upload/coverage/ cp -r ./build/coverage/html/* ./buildbot-upload/coverage/

2
.gitignore vendored
View File

@@ -11,3 +11,5 @@ build/*
*[#]*[#] *[#]*[#]
doxygen/* doxygen/*
buildbot-upload/* buildbot-upload/*
*/config.mak
*\~

62
Makefile Executable file → Normal file
View File

@@ -1,82 +1,50 @@
build=OUT CONFIG = config.mak
COV_DIR=$(OUT)/coverage/
SRC_DIR=src
APP_DIR=src/apps/
OUT=build
include $(CONFIG)
CONFIGURE = $(SRC_DIR)/
COV_DIR=$(OUT)/coverage/
APP_DIR=$(SRC_DIR)/apps/
CC=gcc CC=gcc
CCFLAGS = -Wall -Werror CCFLAGS = -Wall -Werror
CCFLAGS += -std=c99 -D_POSIX_C_SOURCE=200809L CCFLAGS += -std=c99 -D_POSIX_C_SOURCE=200809L
CCFLAGS += -I$(SRC_DIR) CCFLAGS += -I$(SRC_DIR)
.PHONY: release debug
CONFIG = $(OUT)/.config.mk
-include $(CONFIG)
ifeq ($(DEBUG), 1)
CCFLAGS += -DLOG_LEVEL=5 -DDEBUG
CCFLAGS += -O0 -ggdb
endif
ifeq ($(COVERAGE), 1)
LDFLAGS += -lgcov --coverage
CCFLAGS += -O0 --coverage
CCFLAGS += -fprofile-arcs -ftest-coverage
endif
ifeq ($(RELEASE), 1)
CCFLAGS += -O3
endif
CCFLAGS += -I/usr/include/glib-2.0/ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include CCFLAGS += -I/usr/include/glib-2.0/ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
LDFLAGS += -lglib-2.0 LDFLAGS += -lglib-2.0
CCFLAGS += $(CCFLAGS_EXTRA)
LDFLAGS += $(LDFLAGS_EXTRA)
C_SOURCES = $(shell find $(SRC_DIR) -name "*.c") C_SOURCES = $(shell find $(SRC_DIR) -name "*.c")
ALL_OBJS = $(patsubst $(SRC_DIR)/%.c, $(OUT)/%.o, $(C_SOURCES)) ALL_OBJS = $(patsubst $(SRC_DIR)/%.c, $(OUT)/%.o, $(C_SOURCES))
APP_OBJS = $(filter $(OUT)/apps/%, $(ALL_OBJS)) APP_OBJS = $(filter $(OUT)/apps/%, $(ALL_OBJS))
TEST_OBJS = $(filter $(OUT)%test.o, $(ALL_OBJS)) TEST_OBJS = $(filter $(OUT)%test.o, $(ALL_OBJS))
OBJS = $(filter-out $(TEST_OBJS) $(APP_OBJS), $(ALL_OBJS)) OBJS = $(filter-out $(TEST_OBJS) $(APP_OBJS), $(ALL_OBJS))
APPS = $(patsubst %.o, %, $(APP_OBJS)) APPS = $(patsubst %.o, %, $(APP_OBJS))
.PHONY: all .PHONY: all
all: gbdb gbasm tests all: gbdb gbasm tests
.PHONY: config-debug config-release config-default config-coverage
$(CONFIG):
@mkdir -p $(OUT)
config-debug: $(CONFIG)
@echo "DEBUG=1" > $(CONFIG)
config-release: $(CONFIG)
@echo "RELEASE=1" > $(CONFIG)
config-coverage: $(CONFIG)
@echo "COVERAGE=1" > $(CONFIG)
config-default: $(CONFIG)
@echo "" > $(CONFIG)
.PHONY: gbdb gbasm .PHONY: gbdb gbasm
gbdb: $(OUT)/apps/gbdb gbdb: $(OUT)/apps/gbdb
gbasm: $(OUT)/apps/gbasm gbasm: $(OUT)/apps/gbasm
.PHONY: gbasm-test sample-test tests .PHONY: gbasm-test tests
TESTS = $(patsubst %.o, %, $(filter %/test.o, $(ALL_OBJS))) TESTS = $(patsubst %.o, %, $(filter %/test.o, $(ALL_OBJS)))
tests: $(TESTS) tests: $(TESTS)
$(ALL_APPS) $(ALL_OBJS): $(CONFIG) $(ALL_APPS) $(ALL_OBJS): $(CONFIG)
$(OUT)/%.o: $(SRC_DIR)/%.c $(OUT)/%.o: $(SRC_DIR)/%.c $(CONFIG)
@echo " CC $@" @echo " CC $@"
@$(shell mkdir -p $(@D)) @$(shell mkdir -p $(@D))
@$(CC) -c $(CCFLAGS) -o $@ $< @$(CC) -c $(CCFLAGS) -o $@ $<
.SECONDEXPANSION: .SECONDEXPANSION:
$(APPS) $(TESTS): $(OBJS) $$@.o $(APPS) $(TESTS): $(OBJS) $$@.o
@echo " LD $@" @echo " LD $@"
@@ -89,7 +57,7 @@ $(APPS) $(TESTS): $(OBJS) $$@.o
define run_tests = define run_tests =
@for i in $(TESTS); do \ @for i in $(TESTS); do \
echo " TEST $$i"; \ echo " TEST $$i"; \
$$i; \ $$i | sed 's/^/ /'; \
if [ $$? -ne 0 ]; then \ if [ $$? -ne 0 ]; then \
exit 1; \ exit 1; \
fi; \ fi; \

74
configure vendored Executable file
View File

@@ -0,0 +1,74 @@
#!/bin/bash
CONFIG_MAK=config.mak
MAKEFILE=Makefile
debug="no"
coverage="no"
release="no"
output_dir=$(pwd)
proj_dir=$(dirname "$BASH_SOURCE")
for arg in $@; do
case $arg in
--debug)
debug="yes"
;;
--release)
release="yes"
;;
--coverage)
coverage="yes"
;;
*)
echo "unknown option $arg"
exit 1
esac
done
add_define()
{
var=$1
shift
if [[ $# -gt 0 ]]; then
echo "$var=$@" >> $CONFIG_MAK
else
echo "# $var is not defined" >> CONFIG_MAK
fi
}
quiet()
{
$@ 2> /dev/null 1> /dev/null
}
quiet rm $CONFIG_MAK
if [[ ! -e $MAKEFILE ]]; then
quiet ln -s $proj_dir/$MAKEFILE $MAKEFILE
fi
ccflags_extra=""
ldflags_extra=""
if [[ "$debug" == "yes" ]]; then
ccflags_extra="$ccflags_extra -DLOG_LEVEL=5 -DDEBUG -O0 -ggdb"
fi
if [[ "$coverage" == "yes" ]]; then
ccflags_extra="$ccflags_extra --coverage -fprofile-arcs -ftest-coverage"
ldflags_extra="$ldflags_extra -lgcov --coverage"
fi
if [[ "$release" == "yes" ]]; then
ccflags_extra="$ccflags_extra -O3"
fi
add_define CCFLAGS_EXTRA "$ccflags_extra"
add_define LDFLAGS_EXTRA "$ldflags_extra"
add_define OUT "$output_dir"
add_define SRC_DIR "$proj_dir/src"
exit 0

View File

@@ -15,6 +15,11 @@ static bool gbasm_argtype_in_set(uint32_t argtype_set, uint32_t argtype)
return !!(argtype & argtype_set); return !!(argtype & argtype_set);
} }
static bool imm_is_8_bit(uint16_t val)
{
return (val <= 127) && (val >= -128);
}
static int check_no_args(const struct gbasm_parsed_inst *inst, static int check_no_args(const struct gbasm_parsed_inst *inst,
const struct gbasm_op_info *op_info) const struct gbasm_op_info *op_info)
{ {
@@ -89,6 +94,11 @@ static int ld_check(const struct gbasm_parsed_inst *inst,
gbasm_arg_wrong_type_error(inst, op_info); gbasm_arg_wrong_type_error(inst, op_info);
} }
if (inst->operands[0].type == GBASM_OPERAND_REG_8 &&
imm_is_8_bit(inst->operands[1].imm.value)) {
}
return 0; return 0;
} }
@@ -163,16 +173,33 @@ size_t dec_emit(struct emitter *emitter,
} }
size_t ld_emit(struct emitter *emitter, size_t ld_emit(struct emitter *emitter,
const struct gbasm_parsed_inst *inst) const struct gbasm_parsed_inst *inst)
{ {
uint64_t opcode = 0x40; uint8_t opcode;
uint8_t imm8;
opcode += inst->operands[0].r8.type * 8; if (inst->operands[0].type == GBASM_OPERAND_REG_8) {
opcode += inst->operands[1].r8.type; switch (inst->operands[1].type) {
case GBASM_OPERAND_REG_8:
opcode = 0x40;
opcode += inst->operands[0].r8.type * 8;
opcode += inst->operands[1].r8.type;
emit(emitter, &opcode, 1);
return 1;
case GBASM_OPERAND_IMM:
imm8 = inst->operands[1].imm.value;
opcode = 0x06;
opcode += inst->operands[0].r8.type * 8;
emit(emitter, &opcode, 1);
emit(emitter, &imm8, 1);
return 2;
default:
break;
}
emit(emitter, &opcode, 1); }
return 1; return -1;
} }
struct gbasm_op_info gbasm_op_infos[] = { struct gbasm_op_info gbasm_op_infos[] = {
@@ -293,7 +320,9 @@ struct gbasm_op_info gbasm_op_infos[] = {
{ {
.opcode = "ld", .opcode = "ld",
/* support all of the other operands */ /* support all of the other operands */
.operand_types = { GBASM_OPERAND_REG_8, GBASM_OPERAND_REG_8 }, .operand_types = { GBASM_OPERAND_REG_8,
GBASM_OPERAND_REG_8 |
GBASM_OPERAND_IMM },
.check = ld_check, .check = ld_check,
.length = length_one_byte, .length = length_one_byte,
.emit = ld_emit, .emit = ld_emit,