Add top-level makefile

Build output is now in ./build

Fixed compiler warnings in ec_uartd, ec_console

BUG=none
TEST=make

Change-Id: I9a46ab6b9d4e912e59a60c669e95dc0c6f8485df
This commit is contained in:
Randall Spangler
2011-10-24 11:00:33 -07:00
parent 7860a64e42
commit ee3d25fa92
10 changed files with 206 additions and 25 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
board/
build/
vendor/

72
Makefile Normal file
View File

@@ -0,0 +1,72 @@
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
export FIRMWARE_ARCH
export CC ?= gcc
export CXX ?= g++
export CFLAGS = -Wall -Werror
ifeq (${DEBUG},)
CFLAGS += -O3
else
CFLAGS += -O0 -g
endif
# Fix compiling directly on host (outside of emake)
ifeq ($(ARCH),)
export ARCH=amd64
endif
ifneq (${DEBUG},)
CFLAGS += -DVBOOT_DEBUG
endif
ifeq (${DISABLE_NDEBUG},)
CFLAGS += -DNDEBUG
endif
export TOP = $(shell pwd)
export CROS_EC_DIR=$(TOP)/cros_ec
export CHIP_STUB_DIR=$(CROS_EC_DIR)/chip_stub
INCLUDES = -I$(TOP)/chip_interface -I$(CROS_EC_DIR)/include
ifeq ($(FIRMWARE_ARCH),)
INCLUDES += -I$(CHIP_STUB_DIR)/include
endif
export INCLUDES
export BUILD = ${TOP}/build
export CROS_EC_LIB = ${BUILD}/cros_ec.a
export CHIP_STUB_LIB = ${BUILD}/chip_stub.a
ifeq ($(FIRMWARE_ARCH),)
SUBDIRS = cros_ec cros_ec/test utility
else
SUBDIRS = cros_ec
endif
all:
set -e; \
for d in $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; |\
sort -u); do \
newdir=${BUILD}/$$d; \
if [ ! -d $$newdir ]; then \
mkdir -p $$newdir; \
fi; \
done; \
for i in $(SUBDIRS); do \
make -C $$i; \
done
clean:
/bin/rm -rf ${BUILD}
install:
$(MAKE) -C utility install
runtests:
$(MAKE) -C cros_ec/test runtests

20
common.mk Normal file
View File

@@ -0,0 +1,20 @@
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
ALL_OBJS = $(ALL_SRCS:%.c=${BUILD_ROOT}/%.o)
ALL_DEPS = $(ALL_OBJS:%.o=%.o.d)
#
# For this target (all) to be built by default, the including file must not
# define any other targets above the line including this file.
#
# This all: rule must be above the %.o: %.c rule below, otherwise the
# rule below becomes the default target.
#
all: ${ALL_OBJS}
${BUILD_ROOT}/%.o : %.c
$(CC) $(CFLAGS) $(INCLUDES) -MMD -MF $@.d -c -o $@ $<
-include ${ALL_DEPS}

View File

@@ -2,26 +2,50 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
LIB_SRCS=\
lib/ec_console.c
CROS_EC_TOP := $(shell pwd)
LIBDIR = $(CROS_EC_TOP)/lib
STUBDIR = $(CROS_EC_TOP)/chip_stub
TESTDIR = $(CROS_EC_TOP)/test
BUILD_ROOT := ${BUILD}/$(shell basename ${CROS_EC_TOP})
LIBS = $(CROS_EC_LIB) # Firmware library must be self-contained
STUB_SRCS=\
chip_stub/ec_os.c \
chip_stub/ec_uart.c
INCLUDES = \
-I$(CROS_EC_TOP)/include \
-I$(LIBDIR)/include
TESTPROGS=fakemain ec_os_test
ifeq ($(FIRMWARE_ARCH),)
INCLUDES += -I$(STUBDIR)/include
else
INCLUDES += -I$(FWDIR)/arch/$(FIRMWARE_ARCH)/include
endif
CFLAGS=-Wall -I include -I chip_stub -pthread
# find ./lib -iname '*.c' | sort
LIB_SRCS = \
./lib/ec_console.c \
./lib/ec_host_command.c
all: $(TESTPROGS)
LIB_OBJS = $(LIB_SRCS:%.c=${BUILD_ROOT}/%.o)
clean:
rm -f $(TESTPROGS)
STUB_SRCS = \
./chip_stub/ec_os.c \
./chip_stub/ec_uart.c
ec_os_test: test/ec_os_test.c chip_stub/ec_os.c chip_stub/ec_uart.c
gcc $(CFLAGS) -o ec_os_test \
test/ec_os_test.c chip_stub/ec_os.c chip_stub/ec_uart.c
STUB_OBJS = $(STUB_SRCS:%.c=${BUILD_ROOT}/%.o)
fakemain: test/fakemain.c $(LIB_SRCS) $(STUB_SRCS)
gcc $(CFLAGS) -o fakemain test/fakemain.c \
$(LIB_SRCS) $(STUB_SRCS)
ALL_SRCS = ${LIB_SRCS} ${STUB_SRCS}
ifeq ($(FIRMWARE_ARCH),)
all : $(CROS_EC_LIB) $(CHIP_STUB_LIB)
else
all : $(CROS_EC_LIB)
endif
include ../common.mk
$(CROS_EC_LIB) : $(LIB_OBJS)
rm -f $@
ar qc $@ $^
$(CHIP_STUB_LIB) : $(STUB_OBJS)
rm -f $@
ar qc $@ $^

View File

@@ -396,7 +396,7 @@ EcError EcEventPost(EcEvent* event, uint32_t bits) {
EcError EcEventWaitAll(EcEvent* event, uint32_t bits, int timeout_usec) {
EcEventInternal* ei = (EcEventInternal*)event;
int rv;
int rv = 0;
pthread_mutex_lock(&ei->mutex);
@@ -429,7 +429,7 @@ EcError EcEventWaitAll(EcEvent* event, uint32_t bits, int timeout_usec) {
EcError EcEventWaitAny(EcEvent* event, uint32_t bits, uint32_t* got_bits_ptr,
int timeout_usec) {
EcEventInternal* ei = (EcEventInternal*)event;
int rv;
int rv = 0;
pthread_mutex_lock(&ei->mutex);

View File

@@ -129,7 +129,7 @@ const EcConsoleCommand* FindCommand(char* name) {
EcError ConsoleHandleCommand(char* input) {
char* argv[MAX_ARGS_PER_COMMAND];
const EcConsoleCommand *cmd;
int argc;
int argc = 0;
/* Split input into words. Ignore words past our limit. */
SplitWords(input, MAX_ARGS_PER_COMMAND, &argc, argv);

45
cros_ec/test/Makefile Normal file
View File

@@ -0,0 +1,45 @@
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
INCLUDES += -I./include \
-I$(CROS_EC_DIR)/lib/include
BUILD_ROOT = ${BUILD}/cros_ec/test
TEST_NAMES = ec_os_test
TEST_BINS = $(addprefix ${BUILD_ROOT}/,$(TEST_NAMES))
# TODO: port over test lib from vboot_reference
# TEST_LIB = ${BUILD_ROOT}/test.a
# TEST_LIB_SRCS = test_common.c timer_utils.c
# TEST_LIB_OBJS = $(TEST_LIB_SRCS:%.c=${BUILD_ROOT}/%.o)
# ALL_DEPS = $(addsuffix .d,${TEST_BINS} ${TEST_LIB_OBJS})
# Allow multiple definitions, so tests can mock functions from other libraries
CFLAGS += -MMD -MF $@.d -Xlinker --allow-multiple-definition
LIBS := ${TEST_LIB} $(CROS_EC_LIB) $(CHIP_STUB_LIB)
ifneq (${RUNTESTS},)
EXTRA_TARGET = runtests
endif
all: $(TEST_BINS) ${EXTRA_TARGET}
# ${TEST_LIB}: ${TEST_LIB_OBJS}
# rm -f $@
# ar qc $@ $^
${BUILD_ROOT}/%.o : %.c
$(CC) $(CFLAGS) $(INCLUDES) -MMD -MF $@.d -c -o $@ $<
${BUILD_ROOT}/% : %.c ${LIBS}
$(CC) $(CFLAGS) $(INCLUDES) $< ${LIBS} -o $@ -lrt
ALLTESTS = ec_os_test
runtests:
${BUILD_ROOT}/ec_os_test
-include ${ALL_DEPS}

View File

@@ -2,10 +2,27 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
all: ec_uartd
CFLAGS += $(INCLUDES)
CFLAGS += -MMD -MF $@.d
HOSTCC = cc
clean:
rm -f ec_uartd
BUILD_ROOT = ${BUILD}/utility
ec_uartd: ec_uartd.c
gcc -o ec_uartd -lftdi ec_uartd.c
DESTDIR ?= /usr/bin
TARGET_NAMES = ec_uartd
TARGET_BINS = $(addprefix ${BUILD_ROOT}/,$(TARGET_NAMES))
ALL_DEPS = $(addsuffix .d,${TARGET_BINS})
all: $(TARGET_BINS)
${BUILD_ROOT}/ec_uartd: ec_uartd.c $(LIBS)
$(CC) $(CFLAGS) $< -o $@ $(LIBS) -lftdi
install: $(TARGET_BINS)
mkdir -p $(DESTDIR)
cp -f $(TARGET_BINS) $(DESTDIR)
chmod a+rx $(patsubst %,$(DESTDIR)/%,$(TARGET_NAMES))
-include ${ALL_DEPS}

View File

@@ -15,6 +15,7 @@
#include <ftdi.h>
#include <getopt.h>
#include <stdio.h>
#include <sys/stat.h>
#include <termios.h>
#include <unistd.h>
@@ -69,7 +70,7 @@ int openpty(const char* desc) {
int main(int argc, char **argv) {
struct ftdi_context fcontext;
char buf[1024], buf_ec[1024], buf_x86[1024];
unsigned char buf[1024], buf_ec[1024], buf_x86[1024];
int fd_ec, fd_x86;
int rv, i;
@@ -180,4 +181,5 @@ int main(int argc, char **argv) {
close(fd_x86);
ftdi_usb_close(&fcontext);
ftdi_deinit(&fcontext);
return 0;
}