1CC = gcc
2AR=ar cr
3DEFINES = -DTX_LINUX_DEBUG_ENABLE -D_GNU_SOURCE -DTX_LINUX_MULTI_CORE -DTX_ENABLE_EVENT_TRACE
4ifdef NO_IDLE
5DEFINES += -DTX_LINUX_NO_IDLE_ENABLE
6TITLE = "No idle"
7else
8TITLE = "TX"
9endif
10ifdef ARCH64
11TITLE+=":64"
12else
13TITLE+=":32"
14ARCH = -m32
15endif
16COMMON_PATH=$(DIR)/../../../../common
17INCLUDES = -I$(COMMON_PATH)/inc -I$(DIR)/../inc
18CFLAGS = -g3 $(ARCH) -g3 -fPIC -gdwarf-2 -std=c99 $(DEFINES) $(INCLUDES)
19LINK = gcc $(ARCH)
20LIBS = -lpthread -lrt
21FILE_LIST = file_list.mk
22DEPEND_LIST = $(OUTPUT_FOLDER)/*.d
23OUTPUT_FOLDER= .tmp
24DIR=$(shell pwd)
25
26include $(FILE_LIST)
27
28all: $(OUTPUT_FOLDER) sample_threadx tx.so
29	echo $(TITLE) build done
30
31$(OUTPUT_FOLDER):
32	mkdir -p $@
33	mkdir -p $@/generic/
34
35sample_threadx: $(OUTPUT_FOLDER)/sample_threadx.o tx.a
36	echo LD $@
37	$(LINK) -o $@ $^ $(LIBS)
38
39tx.a: $(OUTPUT_FOLDER) $(LINUX_OBJS) $(GENERIC_OBJS)
40	echo AR $@
41	$(AR) $@ $(LINUX_OBJS) $(GENERIC_OBJS)
42
43tx.so: $(OUTPUT_FOLDER) $(LINUX_OBJS) $(GENERIC_OBJS)
44	cc -fPIC -shared -Wl,-soname,$@ -o $@ $(LINUX_OBJS) $(GENERIC_OBJS) $(LIBS) $(ARCH)
45
46$(OUTPUT_FOLDER)/sample_threadx.o: sample_threadx.c $(DIR)/Makefile
47	filename=`basename $<`; \
48	echo CC $$filename; \
49	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $(OUTPUT_FOLDER)/$$filename.d -c -o $@ $<
50
51$(OUTPUT_FOLDER)/%.o: ../src/%.c $(DIR)/Makefile
52	filename=`basename $<`; \
53	echo CC $$filename; \
54	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $(OUTPUT_FOLDER)/$$filename.d -c -o $@ $<
55
56$(OUTPUT_FOLDER)/generic/%.o: $(COMMON_PATH)/src/%.c $(DIR)/Makefile
57	filename=`basename $<`; \
58	echo CC $$filename; \
59	$(CC) $(CFLAGS) -MT $@ -MD -MP -MF $(OUTPUT_FOLDER)/$$filename.d -c -o $@ $<
60
61-include $(DEPEND_LIST)
62
63.SILENT:
64.PHONY: files clean
65files:
66	@echo "LINUX_SRCS = \\" > $(FILE_LIST);
67	-@for file in *.c; \
68	do \
69		filename=`basename $$file`; \
70		[ "$$file" == "sample_threadx.c" ] || echo "$$filename \\" >> $(FILE_LIST); \
71	done;
72	@printf "\n" >> $(FILE_LIST);
73	@echo 'LINUX_OBJS = $$(LINUX_SRCS:%.c=$(OUTPUT_FOLDER)/%.o)' >> $(FILE_LIST);
74	@printf "\n\n" >> $(FILE_LIST);
75	@echo "GENERIC_SRCS = \\" >> $(FILE_LIST);
76	-@for file in $(COMMON_PATH)/src/*.c; \
77	do \
78		filename=`basename $$file`; \
79		[ "$$file" == "sample_threadx.c" ] || echo "$$filename \\" >> $(FILE_LIST); \
80	done;
81	@printf "\n" >> $(FILE_LIST);
82	@echo 'GENERIC_OBJS = $$(GENERIC_SRCS:%.c=$(OUTPUT_FOLDER)/generic/%.o)' >> $(FILE_LIST);
83
84clean:
85	-rm -f -r $(OUTPUT_FOLDER) tx.a sample_threadx tx.so
86