Makefile 4.35 KB
Newer Older
Oscar Olsson's avatar
Oscar Olsson committed
1
## Macros
Anders Blomdell's avatar
Anders Blomdell committed
2
UNAME_S=$(shell uname -s)
3
4
ALL_DEPS=liblabcomm.a liblabcomm.so.1

Anders Blomdell's avatar
Anders Blomdell committed
5
ifeq ($(UNAME_S),Linux)
6
7
8
9
10
11
12
  CFLAGS=-std=c99 -g -Wall -Werror -O3  -I. -Itest
  ifndef TARGET
    CC=gcc	
  else ifeq ($(TARGET),vx)
    CC=i586-wrs-vxworks-gcc
    LD=i586-wrs-vxworks-ld
    ALL_DEPS:=$(filter-out %.so.1, $(ALL_DEPS))
13
    CFLAGS:=$(CFLAGS) -DLABCOMM_COMPAT=\"labcomm_compat_vxworks.h\"
14
15
16
  else
    @echo 'Invalid target.'
  endif
Anders Blomdell's avatar
Anders Blomdell committed
17
18
19
20
21
  LDFLAGS=-L.
  LDLIBS=-llabcomm -lrt
  MAKESHARED=gcc -o $1 -shared -Wl,-soname,$2 $3 -lc -lrt
else ifeq ($(UNAME_S),Darwin)
  CC=clang
Anders Blomdell's avatar
Anders Blomdell committed
22
  CFLAGS=-g -Wall -Werror -O3  -I. -Itest \
Anders Blomdell's avatar
Anders Blomdell committed
23
24
	 -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
	 -Wno-tautological-compare -Wno-unused-function
Anders Blomdell's avatar
Anders Blomdell committed
25
  LDFLAGS=-L.
Anders Blomdell's avatar
Anders Blomdell committed
26
27
28
29
30
  LDLIBS=-llabcomm
  MAKESHARED=clang -o $1 -shared -Wl,-install_name,$2 $3 -lc
else
  $(error Unknown system $(UNAME_S))
endif
31
32
33
34
35
36
37
38
39
40
41
42

OBJS=labcomm_memory.o \
     labcomm_error.o \
     labcomm_default_error_handler.o \
     labcomm_default_memory.o \
     labcomm_default_scheduler.o \
     labcomm_time.o labcomm_scheduler.o \
     labcomm_encoder.o labcomm_decoder.o \
     labcomm.o \
     labcomm_dynamic_buffer_writer.o \
     labcomm_fd_reader.o labcomm_fd_writer.o \
     labcomm_pthread_scheduler.o 
Oscar Olsson's avatar
Oscar Olsson committed
43

44
#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
Anders Blomdell's avatar
Anders Blomdell committed
45
46
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM=java -jar $(LABCOMM_JAR) 
Oscar Olsson's avatar
Oscar Olsson committed
47

48
TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
49
50
      test_signature_numbers \
      test_labcomm \
51
      test_labcomm_pthread_scheduler \
52
53
#
#FIXME: test_labcomm test_labcomm_errors
Oscar Olsson's avatar
Oscar Olsson committed
54
55
TEST_DIR=test

56
57
58
VPATH=$(TEST_DIR)

# Enable experimental objects by invoking make like `make LABCOMM_EXPERIMENTAL=true`
59
ifeq ($(LABCOMM_EXPERIMENTAL),true)
Oscar Olsson's avatar
Oscar Olsson committed
60
61
62
63
64
65
66
67
68
69
70
	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

71
all: $(ALL_DEPS)
Oscar Olsson's avatar
Oscar Olsson committed
72
73

liblabcomm.a: $(OBJS)
74
75
	ar -r $@ $^

76
liblabcomm.so.1: $(OBJS:%.o=%.pic.o)
Anders Blomdell's avatar
Anders Blomdell committed
77
	$(call MAKESHARED,$@,$@,$^)
Oscar Olsson's avatar
Oscar Olsson committed
78

Sven Robertz's avatar
Sven Robertz committed
79
80
81
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
82

83
#$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
Oscar Olsson's avatar
Oscar Olsson committed
84

85
#$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
Oscar Olsson's avatar
Oscar Olsson committed
86

87
ethaddr.o: ethaddr.c
Sven Robertz's avatar
Sven Robertz committed
88

89
90
91
92
run-test: $(TESTS:%=run-test-%)

run-test-%: $(TEST_DIR)/% | $(TEST_DIR)
	$<
Oscar Olsson's avatar
Oscar Olsson committed
93

94
95
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
	$(CC) $(CFLAGS) -o $@ -c $<
Oscar Olsson's avatar
Oscar Olsson committed
96

97
.PRECIOUS: $(TEST_DIR)/%
98
$(TEST_DIR)/%: $(TEST_DIR)/%.o 
Anders Blomdell's avatar
Anders Blomdell committed
99
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) 
Oscar Olsson's avatar
Oscar Olsson committed
100

101
102
103
$(TEST_DIR)/gen:
	mkdir -p $@

104
105
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
106
$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
Anders Blomdell's avatar
Anders Blomdell committed
107
	$(LABCOMM) \
108
109
110
111
		--c=$(TEST_DIR)/gen/$*.c \
		--h=$(TEST_DIR)/gen/$*.h \
		$<

112
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
Anders Blomdell's avatar
Anders Blomdell committed
113
114
					 $(LABCOMM_JAR) | $(TEST_GEN_DIR)
	$(LABCOMM) \
115
		--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
Oscar Olsson's avatar
Oscar Olsson committed
116

Anders Blomdell's avatar
Anders Blomdell committed
117
$(LABCOMM_JAR):
Oscar Olsson's avatar
Oscar Olsson committed
118
	@echo "======Building LabComm compiler======"
Anders Blomdell's avatar
Anders Blomdell committed
119
	cd $(shell dirname $(LABCOMM_JAR)); ant jar
Oscar Olsson's avatar
Oscar Olsson committed
120
121
	@echo "======End building LabComm compiler======"

122
123
124
%.pic.o:	%.c
	$(CC) -fPIC $(CFLAGS) -c -o $@ $<

Oscar Olsson's avatar
Oscar Olsson committed
125
%.o: %.c %.h
Sven Robertz's avatar
Sven Robertz committed
126

Sven Robertz's avatar
Sven Robertz committed
127
clean:
Oscar Olsson's avatar
Oscar Olsson committed
128
129
130
131
132
	$(RM) *.o
	$(RM) experimental/*.o experimental/ThrottleDrv/*.o
	$(RM) test/*.o
	$(RM) test/*.gch
	$(RM) test/test_labcomm_errors
133
	$(RM) test/testdata/gen/*.[cho]
134
	$(RM) test/gen/*.[cho]
Oscar Olsson's avatar
Oscar Olsson committed
135
	$(RM) $(TEST_DIR)/test_labcomm
Sven Robertz's avatar
Sven Robertz committed
136
137

distclean: clean
138
	$(RM) liblabcomm.so.1
Oscar Olsson's avatar
Oscar Olsson committed
139
	$(RM) liblabcomm.a
140
141

# Extra dependencies
142
$(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h
143
144
145

$(TEST_DIR)/test_labcomm_generated_encoding.o: labcomm_private.h
$(TEST_DIR)/test_labcomm_generated_encoding.o: $(TEST_DIR)/gen/generated_encoding.h
146
$(TEST_DIR)/test_labcomm_generated_encoding : $(TEST_DIR)/gen/generated_encoding.o
147

148
$(TEST_DIR)/test_labcomm:  $(TEST_DIR)/gen/test_sample.o
149
150
151
152
$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/another_encoding.h
$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/another_encoding.o
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/generated_encoding.o
153
154
155
labcomm_fd_reader.o: labcomm_private.h
labcomm_fd_writer.o: labcomm_private.h
labcomm_dynamic_buffer_writer.o: labcomm_private.h