tmp commit
[libex.git] / Jamrules.configure
blobdda85eb1202b15160de5bd8e8e3d4c77d15b7ea9
1 #Copyright (c) Brian B.
3 #Permission to use, copy, modify, and/or distribute this software for any purpose
4 #with or without fee is hereby granted.
6 #THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
7 #REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
8 #FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
9 #INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
10 #OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
11 #TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
12 rule -configure-options-help- {
13     Echo "jam configure supports" ;
14     Echo "  --prefix=dir       [/usr/local]" ;
15     Echo "  --debug            build with debug symbols" ;
16     Echo "  --tests            build tests" ;
17     Echo "  --multiarch        multiarch support" ;
18     Echo "  --shared           build with shared library" ;
19     Exit "" ;
22 rule -configure-options-debug- {
23     BUILDDEBUG = tan ;
26 rule -configure-options-tests- {
27     BUILDTESTS = tan ;
30 rule -configure-options-multiarch- {
31     MULTIARCH = tan ;
34 rule -configure-options-shared- {
35     BUILDSO = tan ;
38 # $(1) -- program, string list
39 # $(2) -- additional compiler flags (optional)
40 # $(3) -- additional linker flags (optional)
41 rule -configure-try-exec-cc- {
42   local rc = ;
43   local res = ;
44   if $(CC) && $(LINK) {
45     local tfn = [ RandName ] ;
46     tfn = $(tfn:S=.c) ;
47     if [ ListWrite $(tfn) : $(1) ] {
48       rc = [ Command $(CC) -c $(tfn:Q) -o $(tfn:S=.o:Q) $(2) '2>/dev/null' : exit-code no-output ] ;
49       if $(rc) = '0' {
50         rc = [ Command $(LINK) $(tfn:S=.o:Q) -o $(tfn:S=.elf:Q) $(3) '2>/dev/null' : exit-code no-output ] ;
51         if $(rc) = '0' {
52             res = [ Command $(tfn:S=.elf:Q) : parse-output no-space-break no-tab-break no-cr-break ] ;
53         }
54       }
55       Command rm $(tfn:Q) $(tfn:S=.o:Q) $(tfn:S=.elf:Q) '2>/dev/null' ;
56     }
57   }
58   return $(res) ;
61 # $(1) -- test name
62 # $(2) -- program, string list
63 # $(3) -- additional compiler flags (optional)
64 # $(4) -- additional linker flags (optional)
65 rule -configure-test-exec-cc- {
66   local r ;
67   Echo 'generate code for' $(1) '... ' : -n ;
68   r = [ -configure-try-exec-cc- $(2) : $(3) : $(4) ] ;
69   if $(r) {
70     if ( $(r) = "-D__m32__" ) {
71         Echo "32 bit" : -n ;
72     } else if ( $(r) = "-D__m64__" ) {
73         Echo "64 bit" : -n ;
74     } else {
75         Echo "unknown" : -n ;
76     }
77     Echo ' mode' ;
78   }
79   return $(r);
82 rule -configure-test-arch- {
83     return [
84         -configure-test-exec-cc- "" :
85         "#include <stdio.h>"
86         "int main () {"
87         "switch (sizeof(void*)) {"
88         "case 4: printf(\"-D__m32__\"); break;"
89         "case 8: printf(\"-D__m64__\"); break;"
90         "}"
91         "return 0;"
92         "}"
93         : :
94     ];
97 rule -pkg-find- {
98     local r ;
99     Echo 'checking for' $(1) '... ' : -n ;
100     if [ Command pkg-config --exists $(1) : exit-code no-output ] == 0 {
101         Echo 'found' ;
102         return 1 ;
103     }
104     Echo ' not found' ;
105     return 0 ;
108 rule -configure- {
109     if ! $(PREFIX) {
110         PREFIX = /usr/local ;
111     }
112     local arch = [ -configure-test-arch- ] ;
113     -configure-add-line- "CFLAGS.all += $(arch) ;" ;
114     switch $(OS) {
115         case LINUX :
116             if ( $(arch) = '-D__m32__' ) {
117                 ARCH_LIB = "/i386-linux-gnu" ;
118             } else {
119                 ARCH_LIB = "/x86_64-linux-gnu" ;
120             }
121         case AIX :
122             if ( $(arch) = '-D__m32__' ) {
123                 ARCH_LIB = "/powerpc-aix-ibm" ;
124             } else {
125                 ARCH_LIB = "/powerpc64-aix-ibm" ;
126             }
127     }
128     if ! $(MULTIARCH) {
129         ARCH_LIB = ;
130     } else {
131         if ! $(ARCH_LIB) {
132             Exit "Architecture not supported" ;
133         }
134     }
135     local pl = [ Command "echo $(ARCH_LIB) | sed \"s/\\//\\\\\\\\\\\//g\"" : dummy ] ;
136     local pp = [ Command "echo $(PREFIX) | sed \"s/\\//\\\\\\\\\\\//g\"" : dummy ] ;
137     local estack = "" ;
138     local sslflags = "" ;
139     local sslibs = "" ;
140     local isdl = 1 ;
141     local ispthread = 1 ;
142     -configure-add-line- "ARCH_LIB = $(ARCH_LIB) ;" ;
143     if ( 'gcc' in $(CC) ) && $(OS) != 'AIX' {
144         estack = "-Wl,-z,execstack" ;
145     }
146     if [ -pkg-find- libcrypto ] && [ -pkg-find- libssl ] == 1 {
147         sslflags = [ Command pkg-config --cflags libssl : parse-output no-space-break no-tab-break no-cr-break ] ;
148         sslflags = "-DUSE_SSL $(sslflags) $(crpflags)" ;
149         if $(BUILDSO) {
150             sslibs = [ Command pkg-config --libs libssl : parse-output no-space-break no-tab-break no-cr-break ] ;
151         } else {
152             sslibs = [ Command pkg-config --libs --static libssl : parse-output no-space-break no-tab-break no-cr-break ] ;
153         }
154         -configure-add-line- "CFLAGS.all += $(sslflags) ;" ;
155         -configure-add-line- "LINKLIBS.all += $(sslibs) ;" ;
156         isdl = 0 ;
157         ispthread = 0 ;
158     }
159     switch $(OS) {
160         case LINUX :
161             -configure-add-line- "LINKLIBS.all += -lm -lrt ;" ;
162             if $(isdl) == 1 {
163                 -configure-add-line- "LINKLIBS.all += -ldl ;" ;
164             }
165             if $(ispthread) == 1 {
166                 -configure-add-line- "LINKLIBS.all += -pthread ;" ;
167             }
168             if $(ARCH_LIB) {
169                 Command "sed -e \"s/@prefix/\\$(pp)/\" -e \"s/@arch_lib/\\$(pl)/g\" -e \"s/@ext_libs/-pthread/\" -e \"s/@cflags/$(arch)/\" -e \"s/@estack/$(estack)/\" -e \"s/@sslflags/$(sslflags)/\" -e \"s/@sslibs/$(sslibs)/\" ./libex.pc.in > ./libex.pc" ;
170             } else {
171                 Command "sed -e \"s/@prefix/\\$(pp)/\" -e \"s/@arch_lib//g\" -e \"s/@ext_libs/-pthread/\" -e \"s/@cflags/$(arch)/\" -e \"s/@estack/$(estack)/\" -e \"s/@sslflags/$(sslflags)/\" -e \"s/@sslibs/$(sslibs)/\" ./libex.pc.in > ./libex.pc" ;
172             }
173         case AIX :
174             -configure-add-line- "LINKLIBS.all += -blibpath\\:/usr/lib\\:/usr/local/lib\\:/lib -lbsd -lm -lrt ;" ;
175             if $(isdl) == 1 {
176                 -configure-add-line- "LINKLIBS.all += -ldl ;" ;
177             }
178             if $(ispthread) == 1 {
179                 -configure-add-line- "LINKLIBS.all += -pthread ;" ;
180             }
181             if $(ARCH_LIB) {
182                 Command "sed -e \"s/@prefix/\\$(pp)/\" -e \"s/@arch_lib/\\$(pl)/g\" -e \"s/@ext_libs/-lpthread -lbsd/\" -e \"s/@cflags/$(arch)/\" -e \"s/@estack/$(estack)/\" -e \"s/@sslflags/$(sslflags)/\" -e \"s/@sslibs/$(sslibs)/\" ./libex.pc.in > ./libex.pc" ;
183             } else {
184                 Command "sed -e \"s/@prefix/\\$(pp)/\" -e \"s/@arch_lib//g\" -e \"s/@ext_libs/-lpthread -lbsd/\" -e \"s/@cflags/$(arch)/\" -e \"s/@estack/$(estack)/\" -e \"s/@sslflags/$(sslflags)/\" -e \"s/@sslibs/$(sslibs)/\" ./libex.pc.in > ./libex.pc" ;
185             }
186     }
187     if $(windoze) {
188          -configure-add-line- "CFLAGS.all += -D__WINDOWS__ ;" ;
189     }
190     if $(BUILDDEBUG) {
191         if $(CC) == "gcc" {
192             -configure-add-line- "CFLAGS.all += -O0 -g3 -DDEBUG ;" ;
193         } else {
194             -configure-add-line- "CFLAGS.all += -O0 -g -DDEBUG ;" ;
195         }
196     } else {
197         -configure-add-line- "set-profile ;" ;
198     }
199     -configure-add-line- "BUILDDEBUG =" "$(BUILDDEBUG)" ";" ;
200     -configure-add-line- "BUILDTESTS =" "$(BUILDTESTS)" ";" ;
201     -configure-add-line- "MULTIARCH =" "$(MULTIARCH)" ";" ;
202     -configure-add-line- "BUILDSO =" "$(BUILDSO)" ";" ;
205 rule -configure-preinit- {
206     BUILDDEBUG = ;
207     BUILDTESTS = ;
208     MULTIARCH = ;
209     BUILDSO = ;
210     USESSL = ;
213 configure ;