Makefile 2.64 KB
Newer Older
Oscar Olsson's avatar
Oscar Olsson committed
1
## Macros
2

Oscar Olsson's avatar
Oscar Olsson committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Use LLVM clang if it's found.
CC = $(shell hash clang 2>/dev/null && echo clang || echo gcc)
CFLAGS = -g -Wall -I .
LDFLAGS = -L .
LDLIBS_TEST = -lcunit -llabcomm

OBJS= labcomm.o labcomm_fd_reader_writer.o labcomm_mem_reader.o labcomm_mem_writer.o
LABCOMMC_PATH=../../compiler
LABCOMMC_JAR=$(LABCOMMC_PATH)/labComm.jar

TEST_DIR=test
TESTDATA_DIR=$(TEST_DIR)/testdata
TEST_GEN_DIR=$(TESTDATA_DIR)/gen

CREATED_DIRS=$(TEST_DIR) $(TESTDATA_DIR) $(TEST_GEN_DIR)

19
20
# Enable experimental objects by invoking make like `make -e LABCOMM_EXPERIMENTAL=true`
ifeq ($(LABCOMM_EXPERIMENTAL),true)
Oscar Olsson's avatar
Oscar Olsson committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	OBJS += experimental/udp_hack.o experimental/ethaddr.o \
		experimental/labcomm_thr_reader_writer.o \
		experimental/ThrottleDrv/ethernet_drv.o \
		experimental/ThrottleDrv/throttle_drv.o \
		experimental/labcomm_udp_reader_writer.o
endif

## Targets

.PHONY: all run-test clean distclean

all: liblabcomm.a test/test_labcomm_errors

liblabcomm.a: $(OBJS)
Sven Robertz's avatar
Sven Robertz committed
35
	ar -r liblabcomm.a $^
Sven Robertz's avatar
Sven Robertz committed
36

Oscar Olsson's avatar
Oscar Olsson committed
37

Sven Robertz's avatar
Sven Robertz committed
38
39
40
labcomm.o : labcomm.c labcomm.h  labcomm_private.h

labcomm_fd_reader_writer.o : labcomm_fd_reader_writer.c  labcomm_fd_reader_writer.h  labcomm.h  labcomm_private.h
41

Oscar Olsson's avatar
Oscar Olsson committed
42
43
44
45
labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h

labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h

46
ethaddr.o: ethaddr.c
Sven Robertz's avatar
Sven Robertz committed
47

Oscar Olsson's avatar
Oscar Olsson committed
48
49
50
$(CREATED_DIRS):
	mkdir -p $@

51
52
53
## NB! the tests need CUnit to be installed
run-test: $(TEST_DIR)/test_labcomm $(TEST_DIR)/test_labcomm_errors |$(TEST_DIR)
	test/test_labcomm
Oscar Olsson's avatar
Oscar Olsson committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	test/test_labcomm_errors

$(TEST_DIR)/test_labcomm_errors: $(TEST_DIR)/test_labcomm_errors.o liblabcomm.a |$(TEST_DIR)
	$(CC) $(CFLAGS) $(LDFLAGS) -llabcomm -o $@ $^

$(TEST_DIR)/test_labcomm_errors.o: $(TEST_DIR)/test_labcomm_errors.c $(TEST_DIR)/test_labcomm_errors.h |$(TEST_DIR)
	cd test; $(CC) $(CFLAGS) -I .. -c $(patsubst $(TEST_DIR)/%, %, $^)

$(TEST_DIR)/test_labcomm.o: $(TEST_DIR)/test_labcomm.c $(TEST_GEN_DIR)/test_sample.h |$(TEST_DIR)
	$(CC) -c $(CFLAGS) -o $@ $<

$(TEST_DIR)/test_labcomm: $(TEST_DIR)/test_labcomm.o $(TEST_GEN_DIR)/test_sample.o liblabcomm.a
	$(CC) $(CFLAGS) $(LDFLAGS) $(filter-out %.a,$^) $(LDLIBS) $(LDLIBS_TEST) -o $@

$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc $(LABCOMMC_JAR) |$(TEST_GEN_DIR)
	java -jar $(LABCOMMC_JAR) --c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<

$(LABCOMMC_JAR):
	@echo "======Building LabComm compiler======"
	cd $(LABCOMMC_PATH); ant jar
	@echo "======End building LabComm compiler======"

%.o: %.c %.h
Sven Robertz's avatar
Sven Robertz committed
77

Sven Robertz's avatar
Sven Robertz committed
78
clean:
Oscar Olsson's avatar
Oscar Olsson committed
79
80
81
82
83
84
	$(RM) *.o
	$(RM) experimental/*.o experimental/ThrottleDrv/*.o
	$(RM) test/*.o
	$(RM) test/*.gch
	$(RM) test/test_labcomm_errors
	$(RM) $(TEST_DIR)/test_labcomm
Sven Robertz's avatar
Sven Robertz committed
85
86

distclean: clean
Oscar Olsson's avatar
Oscar Olsson committed
87
	$(RM) liblabcomm.a