-
Notifications
You must be signed in to change notification settings - Fork 5
/
femto.mk
125 lines (106 loc) · 4.15 KB
/
femto.mk
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
# Femto - FEmto's a Makefile TOol
# Copyright (C) 2018 Romain GARBI
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
ifneq (,$(wildcard ./femto-config.mk))
include femto-config.mk
endif
USEOPTIONS =$(addprefix use-,$(OPTIONS))
USEOPTIONSX = $(addsuffix .no-gen,$(USEOPTIONS))
NOOPTIONS =$(addprefix no-,$(OPTIONS))
NOOPTIONSX = $(addsuffix .no-gen,$(NOOPTIONS))
DEFAULTOPTIONSX = $(addsuffix .no-gen,$(DEFAULTOPTIONS))
SUBCONF =$(addsuffix .config,$(SUBCONFIG))
SUBCLEAN =$(addsuffix .femto-clean,$(SUBCONFIG))
CONFIGVARS = $(addprefix prg_,$(PROGRAMS)) \
$(addprefix path_,$(PROGRAMS)) \
$(addprefix fn_,$(FUNCTIONS)) \
$(addprefix lib_,$(LIBS)) \
$(addprefix use_,$(OPTIONS)) \
$(ADDITIONALVARS)
$(PROGRAMS):
@echo "Looking for program : $@ ..."
@if which $@ 2> /dev/null; then \
echo prg_$@=1 >> femto-config.mk; \
echo path_$@=`which $@` >> femto-config.mk; \
echo " found"; \
else \
echo " none"; \
echo prg_$@=0 >> femto-config.mk; \
echo path_$@=0 >> femto-config.mk; \
fi;
$(LIBS):
@echo "Looking for lib : $@ ..."
@echo "int main() { return 0;}" > config.c
@if $(CC) -o femto-test.out config.c $(CFLAGS) $(LDFLAGS) -l$@ -O0 -s 2> /dev/null; then \
echo "lib_$@ = 1" >> femto-config.mk; \
echo " found"; \
else \
echo " none"; \
echo "lib_$@ = 0" >> femto-config.mk; \
fi;
$(FUNCTIONS):
@echo "Looking for : $@ ..."
@sed -e 's,[@]fn[@],$@,g' -e 's,[@]fnp[@],$(shell echo $@ | sed -e 's,/,_,g' -e 's,[.],_,g'),g'< config.c.in > config.c
@if $(CC) -o femto-test.out config.c $(CFLAGS) $(LDFLAGS) -O0 -s 2> /dev/null; then \
echo "fn_$@ = 1" >> femto-config.mk; \
echo " found"; \
else \
echo "fn_$@ = 0" >> femto-config.mk; \
echo " none"; \
fi;
$(FLAGS):
@echo "Looking for flag $@ ..."
@sed -e 's,[@]fn[@],$@,g' -e 's,[@]fnp[@],$(shell echo $@ | sed -e 's,/,_,g' -e 's,[.],_,g'),g'< config.c.in > config.c
@if $(CC) -o femto-test.out config.c $(CFLAGS) $(LDFLAGS) -f$@ -O0 -s 2> /dev/null; then \
echo "flag_$@ = 1" >> femto-config.mk; \
echo " supported"; \
else \
echo "flag_$@ = 0" >> femto-config.mk; \
echo " not supported"; \
fi;
$(USEOPTIONS):
@echo "$(subst use-,use_,$@)=1" >> femto-config.mk
$(MAKE) config.h
$(NOOPTIONS):
@echo "$(subst no-,use_,$@)=0" >> femto-config.mk
$(MAKE) config.h
$(USEOPTIONSX):
@echo "$(subst use-,use_,$(basename $@))=1" >> femto-config.mk
$(NOOPTIONSX):
@echo "$(subst no-,use_,$(basename $@))=0" >> femto-config.mk
localmk:
@echo Removing femto-config.mk
@echo "" > femto-config.mk;
$(SUBCONF):
$(MAKE) -C $(basename $@) config
config: localmk $(PROGRAMS) $(LIBS) $(FUNCTIONS) $(FLAGS) $(DEFAULTOPTIONSX) $(SUBCONF)
$(MAKE) config.h
config.h: femto-subst
./femto-subst < config.h.in > config.h
$(SUBCLEAN):
$(MAKE) -C $(basename $@) femto-clean
femto-clean: $(SUBCLEAN)
rm -f femto-test.out femto-subst femto-config.mk config.h config.c
femto-subst: femto-config.mk
echo \#!/bin/sh > femto-subst
echo sed $(foreach v,$(CONFIGVARS),-e 's,[@]$(v)[@],$($(v)),g') >> femto-subst
chmod +x femto-subst
.PHONY: config config.h femto-clean localmk $(SUBCONF) $(FUNCTIONS) $(PROGRAMS) $(LIBS) \
$(FLAGS) $(NOOPTIONS) $(NOOPTIONSX) $(USEOPTIONS) $(USEOPTIONSX) femto-subst