-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
128 lines (104 loc) · 4.02 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Makefile for simple modules in the Oscar Framework.
# Copyright (C) 2008 Supercomputing Systems AG
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty. This file is offered as-is,
# without any warranty.
# Disable make's built-in rules.
MAKE += -RL --no-print-directory
SHELL := $(shell which bash)
# Generic flags for the C compiler.
CFLAGS := -c -std=gnu99 -Wall -Ioscar/include
# Include the file generated by te configuration process.
-include .config
ifeq '$(filter .config, $(MAKEFILE_LIST))' ''
$(error Please configure the application using './configure' prior to compilation.)
endif
# Name for the application to produce.
APP_NAME := template
# Binary executables to generate.
PRODUCTS := app cgi/cgi
# Listings of source files for the different executables.
SOURCES_app := $(wildcard *.c)
SOURCES_cgi/cgi := $(wildcard cgi/*.c)
ifeq '$(CONFIG_ENABLE_DEBUG)' 'y'
CC_host := gcc $(CFLAGS) -DOSC_HOST -g
CC_target := bfin-uclinux-gcc $(CFLAGS) -DOSC_TARGET -ggdb3
else
CC_host := gcc $(CFLAGS) -DOSC_HOST -O2
CC_target := bfin-uclinux-gcc $(CFLAGS) -DOSC_TARGET -O2
endif
ifeq '$(CONFIG_ENABLE_SIMULATION)' 'y'
CC_host += -DOSC_SIM
CC_target += -DOSC_SIM
endif
LD_host := gcc -fPIC
LD_target := bfin-uclinux-gcc -elf2flt="-s 1048576"
# Listings of source files for the different applications.
SOURCES_$(APP_NAME) := $(wildcard *.c)
SOURCES_cgi/template.cgi := $(wildcard cgi/*.c)
APPS := $(patsubst SOURCES_%, %, $(filter SOURCES_%, $(.VARIABLES)))
LIBS_host := oscar/library/libosc_host
LIBS_target := oscar/library/libosc_target
ifeq '$(CONFIG_ENABLE_SIMULATION)' 'y'
LIBS_target := $(LIBS_target)_sim
endif
ifeq '$(CONFIG_ENABLE_DEBUG)' 'y'
LIBS_host := $(LIBS_host)_dbg
LIBS_target := $(LIBS_target)_dbg
endif
LIBS_host := $(LIBS_host).a
LIBS_target := $(LIBS_target).a
BINARIES := $(addsuffix _host, $(PRODUCTS)) $(addsuffix _target, $(PRODUCTS))
.PHONY: all clean host target install deploy run reconfigure
all: $(BINARIES)
host target: %: $(addsuffix _%, $(PRODUCTS))
deploy: $(APP_NAME).app
tar c $< | ssh root@$(CONFIG_TARGET_IP) 'rm -rf $< && tar x' || true
run:
ssh root@$(CONFIG_TARGET_IP) /mnt/app/$(APP_NAME).app/run.sh || true
install: cgi/cgi_host
cp -RL cgi/www/* /var/www
cp $< /var/www/cgi-bin/cgi
chmod -Rf a+rX /var/www/ || true
reconfigure:
ifeq '$(CONFIG_PRIVATE_FRAMEWORK)' 'n'
@ ! [ -e "oscar" ] || [ -h "oscar" ] && ln -sfn $(CONFIG_FRAMEWORK_PATH) oscar || echo "The symlink to the lgx module could not be created as the file ./lgx already exists and is something other than a symlink. Pleas remove it and run 'make reconfigure' to create the symlink."
endif
@ ! [ -d "oscar" ] || $(MAKE) -C oscar config
oscar/%:
$(MAKE) -C oscar $*
# Including depency files and optional local Makefile.
-include build/*.d
# Build targets.
build/%_host.o: %.c $(filter-out %.d, $(MAKEFILE_LIST))
@ mkdir -p $(dir $@)
$(CC_host) -MD $< -o $@
@ grep -oE '[^ \\]+' < $(@:.o=.d) | sed -r '/:$$/d; s|^.*$$|$@: \0\n\0:|' > $(@:.o=.d~) && mv -f $(@:.o=.d){~,}
build/%_target.o: %.c $(filter-out %.d, $(MAKEFILE_LIST))
@ mkdir -p $(dir $@)
$(CC_target) -MD $< -o $@
@ grep -oE '[^ \\]+' < $(@:.o=.d) | sed -r '/:$$/d; s|^.*$$|$@: \0\n\0:|' > $(@:.o=.d~) && mv -f $(@:.o=.d){~,}
# Link targets.
define LINK
$(1)_host: $(patsubst %.c, build/%_host.o, $(SOURCES_$(1))) $(LIBS_host)
$(LD_host) -o $$@ $$^ -lm
$(1)_target: $(patsubst %.c, build/%_target.o, $(SOURCES_$(1))) $(LIBS_target)
$(LD_target) -o $$@ $$^ -lm -lbfdsp
endef
$(foreach i, $(PRODUCTS), $(eval $(call LINK,$i)))
.PHONY: $(APP_NAME).app
$(APP_NAME).app: $(addsuffix _target, $(PRODUCTS))
rm -rf $@
cp -rL app $@
tar c -h -C cgi/www . | gzip > $@/www.tar.gz
# Controlling the gdbserver on target
.PHONY : gdbserver-start
gdbserver-start:
uxterm -e ssh root@$(CONFIG_TARGET_IP) "killall app; gdbserver :7777 /mnt/app/$(APP_NAME).app/app"
.PHONY : gdbserver-kill
gdbserver-kill:
uxterm -e ssh root@$(CONFIG_TARGET_IP) killall gdbserver
# Cleans the module.
clean:
rm -rf build *.gdb $(BINARIES) $(APP_NAME).app cgi/cgi_target.gdb