Add install target
[tmk.git] / TMakefile
blobd814da26a01998ee88cbcb7ada7de139453b1226
1 param CC gcc
2 param CFLAGS "-g -O2 -ansi -Wall -Wextra"
4 param JIM_CFLAGS [options { -D_GNU_SOURCE
5                             -Wall
6                             -I.
7                             -g
8                             -O2
9                             -fno-unwind-tables
10                             -fno-asynchronous-unwind-tables
11                           }]
13 param JIM_STATIC_EXTS [list aio array clock exec file namespace pack \
14                             package posix readdir regexp signal tclprefix \
15                             binary glob nshelper oo stdlib tclcompat tree \
16                       ]
18 param SQLITE_CFLAGS [options { -DSQLITE_OMIT_LOAD_EXTENSION=1
19                                -DSQLITE_THREADSAFE=0
20                                -DSQLITE_DEFAULT_FILE_FORMAT=4
21                                -DSQLITE_ENABLE_STAT3
22                                -DSQLITE_ENABLE_LOCKING_STYLE=0
23                                -DSQLITE_OMIT_INCRBLOB
24                              }]
26 param TCL "jimsh0"
27 param MAKE_C_EXT "make-c-ext.tcl"
28 param MAKE_LOAD_STATIC_EXTS "make-load-static-exts.tcl"
30 param PREFIX "/usr/local"
31 param DESTDIR ""
33 proc cc args {
34         global CC
36         exec $CC {*}$args
39 proc tclgen {script tclfile cfile} {
40         global TCL
42         set tcl ""
43         if {![file exists $TCL]} {
44                 set tcl "jimtcl/$TCL"
45         } else {
46                 set tcl "./$TCL"
47         }
49         set cmd $script
50         if {![file exists $script]} {
51                 set cmd "jimtcl/$script"
52         }
54         exec -flags @ echo "#define JIM_EMBEDDED" > $cfile
55         exec $tcl $cmd {*}$tclfile >> $cfile
58 rule all {tmk}
60 set JIM_CSRC {_load-static-exts.c jim-subcmd.c jim-interactive.c jim-format.c
61               jim.c utf8.c jimregexp.c jim-aio.c jim-array.c jim-clock.c
62               jim-exec.c jim-file.c jim-namespace.c jim-pack.c jim-package.c
63               jim-posix.c jim-readdir.c jim-regexp.c jim-signal.c
64               jim-tclprefix.c _binary.c _glob.c _nshelper.c _oo.c _stdlib.c
65               _tclcompat.c _tree.c}
67 set JIM_TCLSRC {binary.tcl glob.tcl nshelper.tcl oo.tcl stdlib.tcl
68                 tclcompat.tcl tree.tcl initjimsh.tcl}
70 set JIMSH_SRC {jimsh.c _initjimsh.c}
72 if {[defined NO_BUILD_JIMTCL]} {
73         rule jim {}
74 } else {
75         rule jim_bootstrap {[in-dir jimtcl/autosetup jimsh0.c]} {
76                 global JIM_CFLAGS
77                 cc -o jimtcl/jimsh0 $INPUTS 2>/dev/null
78         }
80         rule jim_exts {jim_bootstrap [in-dir jimtcl $JIM_TCLSRC]} {
81                 global JIM_TCLSRC MAKE_C_EXT
83                 cd jimtcl
84                 foreach tclfile $JIM_TCLSRC {
85                         tclgen $MAKE_C_EXT $tclfile _[replace-ext $tclfile .tcl .c]
86                 }
87                 cd ..
88         }
90         rule _load-static-exts.c {jim_exts} {
91                 global MAKE_LOAD_STATIC_EXTS JIM_STATIC_EXTS
92                 
93                 cd jimtcl
94                 tclgen $MAKE_LOAD_STATIC_EXTS $JIM_STATIC_EXTS _load-static-exts.c
95                 cd ..
96         }
98         rule jim_lib {jim_exts _load-static-exts.c [in-dir jimtcl $JIM_CSRC]} {
99                 global JIM_CSRC JIM_CFLAGS
101                 cd jimtcl
102                 foreach cfile $JIM_CSRC {
103                         cc {*}$JIM_CFLAGS -o [replace-ext $cfile .c .o] -c $cfile
104                 }
106                 exec ar cr libjim.a {*}[replace-ext $JIM_CSRC .c .o]
107                 exec ranlib libjim.a
109                 cd ..
110         }
112         rule jimsh {jim_lib [in-dir jimtcl $JIMSH_SRC]} {
113                 global JIMSH_SRC JIM_CFLAGS
115                 cd jimtcl
116                 cc {*}$JIM_CFLAGS -o $TARGET {*}$JIMSH_SRC libjim.a -lm
117                 cd ..
118         }
120         rule jim {jimsh}
123 rule sqlite3.o {[in-dir jimtcl/sqlite3 sqlite3.c]} {
124         global CC SQLITE_CFLAGS
125         cc -o $TARGET -c $INPUTS {*}$SQLITE_CFLAGS
128 rule config.h {[glob build/checks/*.c]} {
129         foreach i [glob build/checks/*.c] {
130                 cc -o [file rootname $i] $i
131         }
133         set TM_WORD [tcl::exec build/checks/wordsize]
135         tcl::exec echo "typedef $TM_WORD WORD;"  > config.h
139 set H_SRC "tmake.h tm_crypto.h tm_target.h tm_update.h tm_core_cmds.h tm_ext_cmds.h"
140 set C_SRC "tmake.c tm_crypto.c tm_target.c tm_update.c tm_core_cmds.c tm_ext_cmds.c"
142 rule tm_ext_cmds.c {tm_ext_cmds.tcl} {
143         global MAKE_C_EXT
144         tclgen $MAKE_C_EXT $INPUTS $TARGET
147 rule tmk {config.h jim sqlite3.o $C_SRC $H_SRC} {
148         global C_SRC CFLAGS
150         set OPSYS [tcl::exec uname -s]
151         set ARCH  [tcl::exec uname -m]
153         cc {*}$CFLAGS -o $TARGET -Ijimtcl -Ijimtcl/sqlite3 \
154            -DTM_OPSYS="$OPSYS" -DTM_MACHINE_ARCH="$ARCH" \
155            {*}$C_SRC jimtcl/libjim.a sqlite3.o -lm
160 rule install {all} {
161         global PREFIX DESTDIR
162         param BINDIR "$PREFIX/bin"
163         #param LIBDIR "$PREFIX/lib"
164         param MANDIR "$PREFIX/share/man"
166         file mkdir "$DESTDIR/$BINDIR"
167         #file mkdir "$DESTDIR/$LIBDIR"
168         file mkdir "$DESTDIR/$MANDIR/man1"
170         exec install -m 755 tmk "$DESTDIR/$BINDIR"
171         exec install -m 644 doc/tmk.1 "$DESTDIR/$MANDIR/man1"
175 # ----------------------------------------------------------------------------
176 set DOCS {jimtcl/Tcl_shipped.html doc/refman.md}
178 rule doc-html {$DOCS doc/template.html} {
179         file copy -force jimtcl/Tcl_shipped.html doc/Jim_Tcl.html
180         exec pandoc -S -s --toc --template=./doc/template.html \
181                -f markdown_github -t html -o doc/refman.html doc/refman.md
184 rule doc-pdf $DOCS {
185         exec pandoc -f html -t latex -o doc/Jim_Tcl.pdf jimtcl/Tcl_shipped.html
186         exec pandoc -S -s --toc \
187                 -f markdown_github -t latex -o doc/refman.pdf doc/refman.md
190 rule doc-all {doc-html doc-pdf}
192 rule install-doc {doc-all} {
193         global PREFIX DESTDIR
194         param DOCDIR "$PREFIX/share/doc/tmk"
196         file mkdir "$DESTDIR/$DOCDIR"
198         exec install -m 644 doc/*.html "$DESTDIR/$DOCDIR"
199         exec install -m 644 doc/*.pdf "$DESTDIR/$DOCDIR"
202 #-----------------------------------------------------------------------------