source: git/ppcc/auto.def @ 1edbe2f

fieker-DuValspielwiese
Last change on this file since 1edbe2f was 1edbe2f, checked in by Hans Schoenemann <hannes@…>, 5 years ago
format
  • 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 works [cctest -cflags $flags]
120  if {$works} {
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  define OPT ""
195  foreach opt {{-g -O2} {-g -O} {-g}} {
196    if {[check-tmp-flags $opt]} {
197      define OPT $opt
198      break
199    }
200  }
201  msg-checking "Checking for isatty()..."
202  if {[cctest -code {isatty(0);} -includes unistd.h]} {
203    msg-result yes
204    define HAVE_ISATTY 1
205  } else {
206    msg-result no
207  }
208}
209
210define RULES ""
211
212global rules
213set rules ""
214
215proc add-rule {rule} {
216  global rules
217  append rules $rule\n
218}
219
220proc objpath {path} {
221  global builddir
222  return [regsub {[a-z]+/(.*)\.[a-z]+} $path "\$(BUILDDIR)/\\1.o"]
223}
224
225proc libobjpath {path} {
226  global builddir
227  return [regsub {[a-z]+/(.*)\.[a-z]+} $path "\$(BUILDDIR)/lib\\1.o"]
228}
229
230proc make-lib-rule {src} {
231  set obj [libobjpath $src]
232  add-rule "$obj: $src \$(LIBHDR)"
233  add-rule "\t\$(MKDIR) \$(BUILDDIR)"
234  switch -glob -- $src {
235    *.c {
236      add-rule "\t\$(CC) \$(CFLAGS) \$(GCFLAGS) \$(INCLUDES) -c -o $obj $src"
237    }
238    * {
239      add-rule "\t\$(CXX) \$(CXXFLAGS) \$(INCLUDES) -c -o $obj $src"
240    }
241  }
242}
243
244proc make-prog-rule {src} {
245  set obj [objpath $src]
246  add-rule "$obj: $src \$(LIBHDR) \$(PROGHDR)"
247  add-rule "\t\$(MKDIR) \$(BUILDDIR)"
248  add-rule "\t\$(CXX) \$(CXXFLAGS) \$(INCLUDES) -c -o $obj $src"
249}
250
251proc test-rule {src} {
252  global builddir
253  set obj [objpath $src]
254  set name [localname $src]
255  set test "$builddir/$name"
256  add-rule "$test: $obj \$(ADLIB)"
257  add-rule "\t\$(MKDIR) \$(BUILDDIR)"
258  add-rule "\t\$(CXX) \$(OPT) -o $test $obj \$(ADLIB) \$(LIBS)"
259  add-rule "$name: $test .FORCE"
260  add-rule "\t@echo === $test ==="
261  add-rule "\t@$test"
262}
263
264def-int-type Word unsigned $csize(voidp)
265def-int-type Word8 unsigned 1
266def-int-type Word16 unsigned 2
267def-int-type Word32 unsigned 4
268def-int-type Word64 unsigned 8
269def-int-type Int signed $csize(voidp)
270def-int-type Int8 signed 1
271def-int-type Int16 signed 2
272def-int-type Int32 signed 4
273def-int-type Int64 signed 8
274
275if {$have_off_t} {
276  def-int-type Offset signed $csize(off_t)
277}
278
279define BUILDDIR $builddir
280define BINDIR $bindir
281set testsrc {}
282set testobj {}
283set libsrc {}
284set libobj {}
285set adlibsrc [glob adlib/*.cc]
286if {!$boehm} {
287  lappend adlibsrc "gclib/gc.c"
288}
289
290foreach file $adlibsrc {
291  switch -glob -- $file {
292    */test?* {
293      lappend testsrc $file
294      lappend testobj [objpath $file]
295    }
296    * {
297      lappend libsrc $file
298      lappend libobj [libobjpath $file]
299    }
300  }
301}
302
303set progsrc {}
304set progobj {}
305
306foreach file [glob -nocomplain src/*.cc] {
307  switch -glob -- $file {
308    */test?* {
309      lappend testsrc $file
310      lappend testobj [objpath $file]
311    }
312    * {
313      lappend progsrc $file
314      lappend progobj [objpath $file]
315    }
316  }
317}
318
319set libhdr "[glob adlib/*.h] [glob gclib/*.h] adlib/config.h"
320set libhdr [lsort -unique $libhdr]
321set progre [glob -nocomplain src/*.re]
322set proghdr [glob -nocomplain src/*.h]
323set testsrc [lsort -unique $testsrc]
324set gensrc {}
325foreach file $progre {
326  lappend progsrc "[file rootname $file].cc"
327  lappend gensrc "[file rootname $file].cc"
328  lappend progobj [objpath $file]
329}
330
331set progsrc [lsort -unique $progsrc]
332set progobj [lsort -unique $progobj]
333
334define LIBSRC [fmt-files $libsrc]
335define LIBHDR [fmt-files $libhdr]
336define LIBOBJ [fmt-files $libobj]
337define PROGSRC [fmt-files $progsrc]
338define PROGOBJ [fmt-files $progobj]
339define PROGHDR [fmt-files $proghdr]
340define TESTOBJ [fmt-files $testobj]
341define GENSRC [fmt-files $gensrc]
342
343set targets "\$(BINDIR)/\$(PROGNAME)"
344
345set tests {}
346foreach file $testsrc {
347  lappend tests "$builddir/[localname $file]"
348  lappend targets "$builddir/[localname $file]"
349  test-rule $file
350}
351
352define TESTS [fmt-files $tests]
353
354foreach file $progsrc {
355  make-prog-rule $file
356}
357
358if {$re2c} {
359  foreach file $progre {
360    set ccfile "[file rootname $file].cc"
361    add-rule "$ccfile: $file"
362    add-rule "\t\$(RE2C) \$(RE2CFLAGS) -o $ccfile $file"
363  }
364}
365
366foreach file $libsrc {
367  make-lib-rule $file
368}
369
370foreach file $testsrc {
371  make-prog-rule $file
372}
373
374define EXTRA [readfile $makeextra]
375
376define RULES $rules
377define LIBS [join $libs]
378define INCLUDES [join $includes]
379
380define CONFIGITEMS "adlib/config.h adlib/config-defs.h"
381
382if {[file exists $postconf]} {
383  source $postconf
384}
385
386make-config-header adlib/config-defs.h -auto USE_*
387make-template cnf/config.h.in adlib/config.h
388make-template cnf/Makefile.in Makefile
389
390if {[file exists $postsetup]} {
391  source $postsetup
392}
393
Note: See TracBrowser for help on using the repository browser.