source: git/ppcc/auto.def @ 54b24c

spielwiese
Last change on this file since 54b24c was 54b24c, checked in by Reimer Behrends <behrends@…>, 5 years ago
Finalizing thread support.
  • Property mode set to 100644
File size: 8.3 KB
Line 
1# vim:set ft=tcl:
2
3global builddir bindir
4
5set builddir "build"
6set bindir "bin"
7
8define CONFIG_ARGS $::argv
9
10use cc cc-lib cc-db cc-shared
11
12set preconf "src/preconf.tcl"
13set postconf "src/postconf.tcl"
14set postsetup "src/postsetup.tcl"
15set makeextra "src/Makefile.extra"
16
17if {[file exists $preconf]} {
18  source $preconf
19}
20
21options {
22  with-boehm-gc:=yes => "Use the Boehm GC; the argument can be yes, no, or a path to the GC's installation directory."
23  without-re2c => "Do not use re2c."
24  adlibdev => "Change Makefile defaults for AdLib core development."
25  devel => "Enable debug mode by default (implied by --adlibdev)."
26}
27
28set includes "-I."
29set libs {}
30
31set boehmarg "no"
32opt-str with-boehm-gc boehmarg
33
34if {[opt-bool adlibdev]} {
35  define DEFAULT_TARGET "\$(TARGETS)"
36  define DEBUG 1
37} else {
38  define DEFAULT_TARGET "prog"
39  define DEBUG 0
40}
41
42if {[opt-bool devel]} {
43  define DEBUG 1
44}
45
46switch -glob -- $boehmarg {
47  yes -
48  1 -
49  on {
50    set boehm 1
51    set libs "-lgc"
52  }
53  no -
54  0 -
55  "" -
56  off {
57    set boehm 0
58  }
59  * {
60    set boehm 1
61    if {![file isdirectory $boehmarg]} {
62      user-error "Boehm GC option does not specify a valid directory"
63    }
64    lappend includes "-I$boehmarg/include"
65    lappend libs "-L$boehmarg/lib" "-lgc"
66  }
67}
68
69define USE_BOEHM_GC $boehm
70
71proc localname {path} {
72  return [regsub {[a-z]+/(.*)\.[a-z]+} $path "\\1"]
73}
74
75proc fmt-files {files} {
76  set output [join $files]
77  if {[string length $output] < 60} {
78    return $output
79  }
80  set output " \\"
81  set line "  "
82  foreach file $files {
83    if {[string length $line] > 2 && [string length "$line $file"] > 72} {
84      append line "\\"
85      append output "\n" $line
86      set line "  "
87    }
88    append line $file " "
89  }
90  if {[string length $line] > 2} {
91    append output "\n" [string trimright $line]
92  }
93  return $output
94}
95
96global inttypes csize iquote
97set inttypes {char short int long}
98
99proc def-int-type {name prefix size} {
100  global inttypes csize have_long_long
101  foreach type $inttypes {
102    if {$csize($type) == $size} {
103      define $name "$prefix $type"
104      define SIZEOF_[string toupper $name] $size
105      return
106    }
107  }
108  if {$have_long_long} {
109    define $name "$prefix long long"
110    define SIZEOF_[string toupper $name] $csize(long long)
111  } else {
112    define $name "$prefix long"
113    define SIZEOF_[string toupper $name] $csize(long)
114  }
115}
116
117proc check-tmp-flags {flags} {
118  msg-checking "Checking whether the C++ compiler accepts $flags..."
119  set iquote [cctest -cflags "-iquote ."]
120  if {$iquote} {
121    msg-result yes
122    return 1
123  } else {
124    msg-result no
125    return 0
126  }
127}
128
129cc-check-tools ar
130if {[opt-bool without-re2c]} {
131  set re2c 0
132} else {
133  cc-check-progs re2c
134  msg-checking "Checking re2c version..."
135  if {[catch {exec re2c --version} re2cout]} {
136    set re2c 0
137    msg-result "unknown (disable re2c)"
138  } else {
139    set re2c 1
140    switch -glob -- $re2cout {
141      "re2c 1.*.*" {
142        msg-result "($re2cout) ok"
143      }
144      * {
145        msg-result "($re2cout) outdated"
146      }
147    }
148  }
149}
150
151define RE2CFLAGS ""
152if {![is-defined RE2C]} {
153  define RE2C false
154}
155cc-with {-lang c++} {
156  # Does long long exist as a type?
157  global have_long_long
158  set have_long_long [cc-check-types "long long"]
159  if {$have_long_long} {
160    lappend inttypes "long long"
161    define LongWord "unsigned long long"
162    define LongInt "long long"
163    define LONG_FMT "ll"
164  } else {
165    define LongWord "unsigned long"
166    define LongInt "long"
167    define LONG_FMT "l"
168  }
169  # Check all int sizes
170  foreach type $inttypes {
171    set csize($type) [cc-check-sizeof $type]
172  }
173  set csize(voidp) [cc-check-sizeof "void *"]
174  if {$have_long_long && $csize(long long) >= 8} {
175    define HAVE_64BIT_SUPPORT 2
176  }
177  if {$csize(long) >= 8} {
178    define HAVE_64BIT_SUPPORT 1
179  }
180  cc-with {-includes sys/types.h} {
181    set have_off_t [cc-check-types "off_t"]
182    if {$have_off_t} {
183      set csize(off_t) [cc-check-sizeof "off_t"]
184    }
185  }
186  if {$csize(long) == $csize(voidp)} {
187    define WORD_FMT "l"
188  } elseif {$have_long_long && $csize(long long) == $csize(voidp)} {
189    define WORD_FMT "ll"
190  } else {
191    define WORD_FMT ""
192  }
193  cc-check-includes dirent.h
194  # -iquote vs. -I
195  set iquote [check-tmp-flags "-iquote"]
196  define OPT ""
197  foreach opt {{-g -O2} {-g -O} {-g}} {
198    if {[check-tmp-flags $opt]} {
199      define OPT $opt
200      break
201    }
202  }
203  msg-checking "Checking for isatty()..."
204  if {[cctest -code {isatty(0);} -includes unistd.h]} {
205    msg-result yes
206    define HAVE_ISATTY 1
207  } else {
208    msg-result no
209  }
210}
211
212define RULES ""
213
214global rules
215set rules ""
216
217proc add-rule {rule} {
218  global rules
219  append rules $rule\n
220}
221
222proc objpath {path} {
223  global builddir
224  return [regsub {[a-z]+/(.*)\.[a-z]+} $path "\$(BUILDDIR)/\\1.o"]
225}
226
227proc libobjpath {path} {
228  global builddir
229  return [regsub {[a-z]+/(.*)\.[a-z]+} $path "\$(BUILDDIR)/lib\\1.o"]
230}
231
232proc make-lib-rule {src} {
233  set obj [libobjpath $src]
234  add-rule "$obj: $src \$(LIBHDR)"
235  add-rule "\t\$(MKDIR) \$(BUILDDIR)"
236  switch -glob -- $src {
237    *.c {
238      add-rule "\t\$(CC) \$(CFLAGS) \$(GCFLAGS) \$(INCLUDES) -c -o $obj $src"
239    }
240    * {
241      add-rule "\t\$(CXX) \$(CXXFLAGS) \$(INCLUDES) -c -o $obj $src"
242    }
243  }
244}
245
246proc make-prog-rule {src} {
247  set obj [objpath $src]
248  add-rule "$obj: $src \$(LIBHDR) \$(PROGHDR)"
249  add-rule "\t\$(MKDIR) \$(BUILDDIR)"
250  add-rule "\t\$(CXX) \$(CXXFLAGS) \$(INCLUDES) -c -o $obj $src"
251}
252
253proc test-rule {src} {
254  global builddir
255  set obj [objpath $src]
256  set name [localname $src]
257  set test "$builddir/$name"
258  add-rule "$test: $obj \$(ADLIB)"
259  add-rule "\t\$(MKDIR) \$(BUILDDIR)"
260  add-rule "\t\$(CXX) \$(OPT) -o $test $obj \$(ADLIB) \$(LIBS)"
261  add-rule "$name: $test .FORCE"
262  add-rule "\t@echo === $test ==="
263  add-rule "\t@$test"
264}
265
266def-int-type Word unsigned $csize(voidp)
267def-int-type Word8 unsigned 1
268def-int-type Word16 unsigned 2
269def-int-type Word32 unsigned 4
270def-int-type Word64 unsigned 8
271def-int-type Int signed $csize(voidp)
272def-int-type Int8 signed 1
273def-int-type Int16 signed 2
274def-int-type Int32 signed 4
275def-int-type Int64 signed 8
276
277if {$have_off_t} {
278  def-int-type Offset signed $csize(off_t)
279}
280
281define BUILDDIR $builddir
282define BINDIR $bindir
283set testsrc {}
284set testobj {}
285set libsrc {}
286set libobj {}
287set adlibsrc [glob adlib/*.cc]
288if {!$boehm} {
289  lappend adlibsrc "gclib/tinygc.c"
290}
291
292foreach file $adlibsrc {
293  switch -glob -- $file {
294    */test?* {
295      lappend testsrc $file
296      lappend testobj [objpath $file]
297    }
298    * {
299      lappend libsrc $file
300      lappend libobj [libobjpath $file]
301    }
302  }
303}
304
305set progsrc {}
306set progobj {}
307
308foreach file [glob -nocomplain src/*.cc] {
309  switch -glob -- $file {
310    */test?* {
311      lappend testsrc $file
312      lappend testobj [objpath $file]
313    }
314    * {
315      lappend progsrc $file
316      lappend progobj [objpath $file]
317    }
318  }
319}
320
321set libhdr "[glob adlib/*.h] [glob gclib/*.h] adlib/config.h"
322set libhdr [lsort -unique $libhdr]
323set progre [glob -nocomplain src/*.re]
324set proghdr [glob -nocomplain src/*.h]
325set gensrc {}
326foreach file $progre {
327  lappend progsrc "[file rootname $file].cc"
328  lappend gensrc "[file rootname $file].cc"
329  lappend progobj [objpath $file]
330}
331
332set progsrc [lsort -unique $progsrc]
333set progobj [lsort -unique $progobj]
334
335define LIBSRC [fmt-files $libsrc]
336define LIBHDR [fmt-files $libhdr]
337define LIBOBJ [fmt-files $libobj]
338define PROGSRC [fmt-files $progsrc]
339define PROGOBJ [fmt-files $progobj]
340define PROGHDR [fmt-files $proghdr]
341define TESTOBJ [fmt-files $testobj]
342define GENSRC [fmt-files $gensrc]
343
344set targets "\$(BINDIR)/\$(PROGNAME)"
345
346set tests {}
347foreach file $testsrc {
348  lappend tests "$builddir/[localname $file]"
349  lappend targets "$builddir/[localname $file]"
350  test-rule $file
351}
352
353define TESTS [fmt-files $tests]
354
355foreach file $progsrc {
356  make-prog-rule $file
357}
358
359if {$re2c} {
360  foreach file $progre {
361    set ccfile "[file rootname $file].cc"
362    add-rule "$ccfile: $file"
363    add-rule "\t\$(RE2C) \$(RE2CFLAGS) -o $ccfile $file"
364  }
365}
366
367foreach file $libsrc {
368  make-lib-rule $file
369}
370
371foreach file $testsrc {
372  make-prog-rule $file
373}
374
375define EXTRA [readfile $makeextra]
376
377define RULES $rules
378define LIBS [join $libs]
379define INCLUDES [join $includes]
380
381define CONFIGITEMS "adlib/config.h adlib/config-defs.h"
382
383if {[file exists $postconf]} {
384  source $postconf
385}
386
387make-config-header adlib/config-defs.h -auto USE_* 
388make-template cnf/config.h.in adlib/config.h
389make-template cnf/Makefile.in Makefile
390
391if {[file exists $postsetup]} {
392  source $postsetup
393}
394
Note: See TracBrowser for help on using the repository browser.