summaryrefslogtreecommitdiff
path: root/src/main.aap
blob: bedbbb5e3a951739f936acd756732d2416de7c94 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
# A-A-P recipe for building Vim
#
# There are no user choices in here!
# Put configure arguments in the file config.arg.
# Later there will be a config.txt file that contains examples and
# explanations.
#
# Optional arguments:
#  PREFIX=dir           Overrules the install directory.
#                       Can be specified when installing only.
#                       Example: aap install PREFIX=$HOME
#
@if os.name != "posix":
    :error Sorry, this recipe only works for Unix-like systems.

# Skip the configure stuff when "link.sh" is executing this recipe recursively
# to build pathdef.c or not building something and auto/config.aap does exist.
@if ((_no.TARGETARG != "pathdef" and has_build_target())
@       or not os.path.exists("auto/config.aap")):

    #
    # A U T O C O N F
    #

    # Run autoconf when configure.in has been changed since it was last run.
    # This is skipped when the signatures in "mysign" are up-to-date.  When
    # there is no autoconf program skip this (the signature is often the only
    # thing that's outdated)
    auto/configure {signfile = mysign} : configure.in
        @if not program_path("autoconf"):
            :print Can't find autoconf, using existing configure script.
        @else:
            # Move configure aside, autoconf would overwrite it
            :move {exist} configure configure.save
            :sys autoconf
            :cat configure | :eval re.sub('\\./config.log', 'auto/config.log', stdin) | :eval re.sub('>config.log', '>auto/config.log', stdin) >! auto/configure
            :chmod 755 auto/configure
            :move configure.save configure
            :del {force} auto/config.cache auto/config.status

    # Change the configure script to produce config.aap instead of config.mk.
    auto/configure.aap : auto/configure
        :print Adjusting auto/configure for A-A-P.
        :cat auto/configure | :eval re.sub("config.mk", "config.aap", stdin)
                                                        >! auto/configure.aap
        :chmod 755 auto/configure.aap

    # The configure script uses the directory where it's located, use a link.
    configure.aap:  {buildcheck=}
        :symlink {f} auto/configure.aap configure.aap

    # Dependency: run configure.aap to update config.h and config.aap in the
    # "auto" directory.
    # NOTE: we can only build for one architecture, because -MM doesn't work
    # when building for both.
    config {virtual} auto/config.h auto/config.aap :
                         auto/configure.aap configure.aap
                         config.arg config.h.in config.aap.in
        # Use "uname -a" to detect the architecture of the system.
        @ok, uname = redir_system('uname -a', 0)
        @if string.find(uname, "i386") >= 0:
        @   arch = "i386"
        @else:
        @   arch = "ppc"
        :print Building for $arch system
        config_args = `file2string("config.arg")`
        :sys CONFIG_STATUS=auto/config.status
                ./configure.aap $config_args
                    --with-mac-arch=$arch
                    --cache-file=auto/config.cache

    # Configure arguments: create an empty "config.arg" file when it's missing
    config.arg:
        :touch {exist} config.arg

    # "auto/config.aap" contains a lot of settings, such as the name of the
    # executable "Target".
    # First update it, forcefully if the "reconfig" target was used.
    @if _no.TARGETARG != "comment" and _no.TARGETARG != "make":
        @if "reconfig" in var2list(_no.TARGETARG):
            :del {force} auto/config.cache auto/config.status
            :update {force} auto/config.aap
        @else:
            :update auto/config.aap

# Include the recipe that autoconf generated.
:include auto/config.aap

# Unfortunately "-M" doesn't work when building for two architectures.  Switch
# back to PPC only.
@if string.find(_no.CPPFLAGS, "-arch i386 -arch ppc") >= 0:
    CPPFLAGS = `string.replace(_no.CPPFLAGS, "-arch i386 -arch ppc", "-arch ppc")`

# A "PREFIX=dir" argument overrules the value of $prefix
# But don't use the default "/usr/local".
@if _no.get("PREFIX") and _no.get("PREFIX") != '/usr/local':
    prefix = $PREFIX

# Don't want "~/" in prefix.
prefix = `os.path.expanduser(prefix)`

# For Mac.
APPDIR = $(VIMNAME).app

### Names of the programs and targets
VIMTARGET       = $VIMNAME$EXESUF
EXTARGET        = $EXNAME$LNKSUF
VIEWTARGET      = $VIEWNAME$LNKSUF
GVIMNAME        = g$VIMNAME
GVIMTARGET      = $GVIMNAME$LNKSUF
GVIEWNAME       = g$VIEWNAME
GVIEWTARGET     = $GVIEWNAME$LNKSUF
RVIMNAME        = r$VIMNAME
RVIMTARGET      = $RVIMNAME$LNKSUF
RVIEWNAME       = r$VIEWNAME
RVIEWTARGET     = $RVIEWNAME$LNKSUF
RGVIMNAME       = r$GVIMNAME
RGVIMTARGET     = $RGVIMNAME$LNKSUF
RGVIEWNAME      = r$GVIEWNAME
RGVIEWTARGET    = $RGVIEWNAME$LNKSUF
VIMDIFFNAME     = $(VIMNAME)diff
GVIMDIFFNAME    = g$VIMDIFFNAME
VIMDIFFTARGET   = $VIMDIFFNAME$LNKSUF
GVIMDIFFTARGET  = $GVIMDIFFNAME$LNKSUF
EVIMNAME        = e$VIMNAME
EVIMTARGET      = $EVIMNAME$LNKSUF
EVIEWNAME       = e$VIEWNAME
EVIEWTARGET     = $EVIEWNAME$LNKSUF

#
# G U I  variant
#
# The GUI is selected by configure, a lot of other things depend on it.
#
:variant GUI
    GTK
        GUI_SRC         = gui.c gui_gtk.c gui_gtk_x11.c pty.c gui_beval.c
                            gui_gtk_f.c
        GUI_OBJ         =
        GUI_DEFS        = -DFEAT_GUI_GTK $NARROW_PROTO
        GUI_IPATH       = $GUI_INC_LOC
        GUI_LIBS_DIR    = $GUI_LIB_LOC
        GUI_LIBS1       =
        GUI_LIBS2       = $GTK_LIBNAME
        GUI_INSTALL     = install_normal
        GUI_TARGETS     = installglinks
        GUI_MAN_TARGETS = yes
        GUI_TESTTARGET  = gui
        GUI_BUNDLE      =
        GUI_TESTARG     =
    MOTIF
        GUI_SRC         = gui.c gui_motif.c gui_x11.c pty.c gui_beval.c
                          gui_xmdlg.c gui_xmebw.c
        GUI_OBJ         =
        GUI_DEFS        = -DFEAT_GUI_MOTIF $NARROW_PROTO
        GUI_IPATH       = $GUI_INC_LOC
        GUI_LIBS_DIR    = $GUI_LIB_LOC
        GUI_LIBS1       =
        GUI_LIBS2       = $MOTIF_LIBNAME -lXt
        GUI_INSTALL     = install_normal
        GUI_TARGETS     = installglinks
        GUI_MAN_TARGETS = yes
        GUI_TESTTARGET  = gui
        GUI_BUNDLE      =
        GUI_TESTARG     =
    ATHENA
        # XAW_LIB et al. can be overruled to use Xaw3d widgets
        XAW_LIB         ?= -lXaw
        GUI_SRC         =  gui.c gui_athena.c gui_x11.c pty.c gui_beval.c \
                            gui_at_sb.c gui_at_fs.c
        GUI_OBJ         =
        GUI_DEFS        = -DFEAT_GUI_ATHENA $NARROW_PROTO
        GUI_IPATH       = $GUI_INC_LOC
        GUI_LIBS_DIR    = $GUI_LIB_LOC
        GUI_LIBS1       = $XAW_LIB
        GUI_LIBS2       = -lXt
        GUI_INSTALL     = install_normal
        GUI_TARGETS     = installglinks
        GUI_MAN_TARGETS = yes
        GUI_TESTTARGET  = gui
        GUI_BUNDLE      =
        GUI_TESTARG     =
    NEXTAW
        # XAW_LIB et al. can be overruled to use Xaw3d widgets
        XAW_LIB         ?= -lXaw
        GUI_SRC         =  gui.c gui_athena.c gui_x11.c pty.c gui_beval.c
                            gui_at_fs.c
        GUI_OBJ         =
        GUI_DEFS        = -DFEAT_GUI_ATHENA -DFEAT_GUI_NEXTAW $NARROW_PROTO
        GUI_IPATH       = $GUI_INC_LOC
        GUI_LIBS_DIR    = $GUI_LIB_LOC
        GUI_LIBS1       = $NEXTAW_LIB
        GUI_LIBS2       = -lXt
        GUI_INSTALL     = install_normal
        GUI_TARGETS     = installglinks
        GUI_MAN_TARGETS = yes
        GUI_TESTTARGET  = gui
        GUI_BUNDLE      =
        GUI_TESTARG     =
    CARBONGUI
        GUI_SRC         =  gui.c gui_mac.c pty.c
        GUI_OBJ         =
        GUI_DEFS        = -DFEAT_GUI_MAC -fno-common -fpascal-strings \
                            -Wall -Wno-unknown-pragmas -mdynamic-no-pic -pipe
        GUI_IPATH       = $GUI_INC_LOC
        GUI_LIBS_DIR    = $GUI_LIB_LOC
        GUI_LIBS1       = -framework Carbon
        GUI_LIBS2       =
        GUI_INSTALL     = install_macosx
        GUI_TARGETS     = installglinks
        GUI_MAN_TARGETS = yes
        GUI_TESTTARGET  = gui
        GUI_BUNDLE      = gui_bundle
        GUI_TESTARG     = VIMPROG=../$(APPDIR)/Contents/MacOS/$(VIMTARGET)
    PHOTONGUI
        GUI_SRC         = gui.c gui_photon.c pty.c
        GUI_OBJ         =
        GUI_DEFS        = -DFEAT_GUI_PHOTON
        GUI_IPATH       =
        GUI_LIBS_DIR    =
        GUI_LIBS1       = -lph -lphexlib
        GUI_LIBS2       =
        GUI_INSTALL     = install_normal
        GUI_TARGETS     = installglinks
        GUI_MAN_TARGETS = yes
        GUI_TESTTARGET  = gui
        GUI_BUNDLE      =
        GUI_TESTARG     =
    *
        GUI_SRC         =
        GUI_OBJ         =
        GUI_DEFS        =
        GUI_IPATH       =
        GUI_LIBS_DIR    =
        GUI_LIBS1       =
        GUI_LIBS2       =
        GUI_INSTALL     = install_normal
        GUI_TARGETS     =
        GUI_MAN_TARGETS =
        GUI_TESTTARGET  =
        GUI_BUNDLE      =
        GUI_TESTARG     =


PRE_DEFS = -Iproto -I. $DEFS $GUI_DEFS $GUI_IPATH $CPPFLAGS $?(EXTRA_IPATHS)
POST_DEFS = $X_CFLAGS $LUA_CFLAGS $MZSCHEME_CFLAGS $PERL_CFLAGS $PYTHON_CFLAGS $TCL_CFLAGS $RUBY_CFLAGS $?(EXTRA_DEFS)
CFLAGS = $PRE_DEFS $CONF_CFLAGS $?(PROFILE_CFLAGS) $POST_DEFS
CPPFLAGS =

ALL_LIB_DIRS = $GUI_LIBS_DIR $X_LIBS_DIR
LDFLAGS = $ALL_LIB_DIRS $CONF_LDFLAGS
LIBS = $GUI_LIBS1 $GUI_X_LIBS $GUI_LIBS2 $X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS $CONF_LIBS $?(EXTRA_LIBS) $LUA_LIBS $MZSCHEME_LIBS $PERL_LIBS $PYTHON_LIBS $TCL_LIBS $RUBY_LIBS $?(PROFILE_LIBS)

Target = $VIMNAME

# reconfig target also builds Vim (reconfiguration is handled above).
reconfig {virtual}: $Target

distclean: clean
    :del {force} auto/config.h auto/config.aap
    :del {force} auto/config.cache auto/config.status


# Execute the test scripts.  Run these after compiling Vim, before installing.
#
# This will produce a lot of garbage on your screen, including a few error
# messages.  Don't worry about that.
# If there is a real error, there will be a difference between "test.out" and
# a "test99.ok" file.
# If everything is alright, the final message will be "ALL DONE".  If not you
# get "TEST FAILURE".
#
test check:
    VimProg = ../$Target
    :execute testdir/main.aap $GUI_TESTTARGET $GUI_TESTARG

testclean {virtual}:
    :del {force} testdir/*.out testdir/test.log

# When no fetch target exists we are not a child of the ../main.aap recipe,
# Use ../main.aap to do the fetching.
# --- If you get an error here for wrong number of arguments, you need to
#     update to a newer version of A-A-P.
@if not has_target("fetch"):
    fetch:
        :execute ../main.aap fetch


# All the source files that need to be compiled.
# Some are optional and depend on configure.
# "version.c" is missing, it's always compiled (see below).
Source =
        blowfish.c
        buffer.c
        charset.c
        diff.c
        digraph.c
        edit.c
        eval.c
        ex_cmds.c
        ex_cmds2.c
        ex_docmd.c
        ex_eval.c
        ex_getln.c
        fileio.c
        fold.c
        getchar.c
        hardcopy.c
        hashtab.c
        if_cscope.c
        if_xcmdsrv.c
        main.c
        mark.c
        memfile.c
        memline.c
        menu.c
        message.c
        misc1.c
        misc2.c
        move.c
        mbyte.c
        normal.c
        ops.c
        option.c
        os_unix.c
        auto/pathdef.c
        popupmnu.c
        quickfix.c
        regexp.c
        screen.c
        search.c
        sha256.c
        spell.c
        syntax.c
        tag.c
        term.c
        ui.c
        undo.c
        window.c
        $OS_EXTRA_SRC
        $GUI_SRC
        $HANGULIN_SRC
        $LUA_SRC
        $MZSCHEME_SRC
        $PERL_SRC
        $NETBEANS_SRC
        $PYTHON_SRC
        $TCL_SRC
        $RUBY_SRC
        $WORKSHOP_SRC

Objects =
        $GUI_OBJ

# TODO: make is still used for subdirectories, need to write a recipe.
MAKE ?= make

all: $Target $GUI_BUNDLE

# This dependency is required to build auto/osdef.h before automatic
# dependencies are generated.
$Source version.c : auto/osdef.h

# Need to mention that the target also depends on version.c, since it's not
# included in $Source
$Target : version.c

# Some sources are to be found in the "auto" directory.
SRCPATH += auto

# When building Vim always compile version.c to get the timestamp.
:filetype
    declare my_prog
:attr {filetype = my_prog} $Target

:program $Target : $Source $Objects

:action build my_prog object
        version_obj = `src2obj("version.c")`
        :do compile {target = $version_obj} version.c
        #:do build {target = $target {filetype = program}} $source $version_obj
        link_sed = $BDIR/link.sed
        @if os.path.exists(link_sed):
            :move {force} $link_sed auto/link.sed
        @else:
            :del {force} auto/link.sed
        :update link2.sh
        :sys LINK="$?(PURIFY) $?(SHRPENV) $CC $LDFLAGS \
                -o $target $source $version_obj $LIBS" \
                MAKE="aap" sh ./link2.sh
        :copy {force} auto/link.sed $BDIR/link.sed

# "link.sh" must be modified for A-A-P
link2.sh : link.sh
    :print Adjusting $-source for A-A-P.
    :cat $source | :eval re.sub("objects/pathdef.o", "pathdef", stdin)
                                                                      >! $target

xxd/xxd$EXESUF: xxd/xxd.c
    :sys cd xxd; CC="$CC" CFLAGS="$CPPFLAGS $CFLAGS" \
            $MAKE -f Makefile

# Build the language specific files if they were unpacked.
# Generate the converted .mo files separately, it's no problem if this fails.
languages {virtual}:
        @if _no.MAKEMO:
            :sys cd $PODIR; CC="$CC" $MAKE prefix=$DESTDIR$prefix
            @try:
                :sys cd $PODIR; CC="$CC" $MAKE prefix=$DESTDIR$prefix converted
            @except:
                :print Generated converted language files failed, continuing

# Update the *.po files for changes in the sources.  Only run manually.
update-po {virtual}:
        cd $PODIR; CC="$CC" $MAKE prefix=$DESTDIR$prefix update-po

auto/if_perl.c: if_perl.xs
        :sys $PERL -e 'unless ( $$] >= 5.005 ) { for (qw(na defgv errgv)) { print "#define PL_$$_ $$_\n" }}' > $target
        :sys $PERL $PERLLIB/ExtUtils/xsubpp -prototypes -typemap \
            $PERLLIB/ExtUtils/typemap if_perl.xs >> $target

auto/osdef.h: auto/config.h osdef.sh osdef1.h.in osdef2.h.in
        :sys CC="$CC $CFLAGS" srcdir=$srcdir sh $srcdir/osdef.sh

pathdef {virtual} : $BDIR/auto/pathdef$OBJSUF

auto/pathdef.c: auto/config.aap
        :print Creating $target
        :print >! $target /* pathdef.c */
        :print >> $target /* This file is automatically created by main.aap */
        :print >> $target /* DO NOT EDIT!  Change main.aap only. */
        :print >> $target $#include "vim.h"
        :print >> $target char_u *default_vim_dir = (char_u *)"$VIMRCLOC";
        :print >> $target char_u *default_vimruntime_dir = (char_u *)"$?VIMRUNTIMEDIR";
        v = $CC -c -I$srcdir $CFLAGS
        @v = string.replace(v, '"', '\\"')
        :print >> $target char_u *all_cflags = (char_u *)"$v";
        linkcmd = $CC $LDFLAGS -o $VIMTARGET $LIBS
        link_sed = $BDIR/link.sed
        @if os.path.exists(link_sed):
            # filter $linkcmd through $BDIR/link.sed
            :print $linkcmd | :syseval sed -f $link_sed | :eval re.sub("\n", "", stdin) | :assign linkcmd
        @linkcmd = string.replace(linkcmd, '"', '\\"')
        :print >> $target char_u *all_lflags = (char_u *)"$linkcmd";
        @if _no.get("COMPILEDBY"):
            who = $COMPILEDBY
            where =
        @else:
            :syseval whoami | :eval re.sub("\n", "", stdin) | :assign who

            :syseval hostname | :eval re.sub("\n", "", stdin) | :assign where
        @who = string.replace(who, '"', '\\"')
        @where = string.replace(where, '"', '\\"')
        :print >> $target char_u *compiled_user = (char_u *)"$who";
        :print >> $target char_u *compiled_sys = (char_u *)"$where";


### Names of the tools that are also made
TOOLS = xxd/xxd$EXESUF

# Root of the installation tree.  Empty for a normal install, set to an
# existing path to install into a special place (for generating a package).
DESTDIR ?=

### Location of man pages under $MANTOPDIR
MAN1DIR = /man1

### Location of Vim files (should not need to be changed, and
### some things might not work when they are changed!)
VIMDIR = /vim
@r = re.compile('.*VIM_VERSION_NODOT\\s*"(vim\\d\\d[^"]*)".*', re.S)
VIMRTDIR = /`r.match(open("version.h").read()).group(1)`
HELPSUBDIR = /doc
COLSUBDIR = /colors
SYNSUBDIR = /syntax
INDSUBDIR = /indent
AUTOSUBDIR = /autoload
PLUGSUBDIR = /plugin
FTPLUGSUBDIR = /ftplugin
LANGSUBDIR = /lang
COMPSUBDIR = /compiler
KMAPSUBDIR = /keymap
MACROSUBDIR = /macros
TOOLSSUBDIR = /tools
TUTORSUBDIR = /tutor
SPELLSUBDIR = /spell
PRINTSUBDIR = /print
PODIR = po

### VIMLOC      common root of the Vim files (all versions)
### VIMRTLOC    common root of the runtime Vim files (this version)
### VIMRCLOC    compiled-in location for global [g]vimrc files (all versions)
### VIMRUNTIMEDIR  compiled-in location for runtime files (optional)
### HELPSUBLOC  location for help files
### COLSUBLOC   location for colorscheme files
### SYNSUBLOC   location for syntax files
### INDSUBLOC   location for indent files
### AUTOSUBLOC  location for standard autoload files
### PLUGSUBLOC  location for standard plugin files
### FTPLUGSUBLOC  location for ftplugin files
### LANGSUBLOC  location for language files
### COMPSUBLOC  location for compiler files
### KMAPSUBLOC  location for keymap files
### MACROSUBLOC location for macro files
### TOOLSSUBLOC location for tools files
### TUTORSUBLOC location for tutor files
### PRINTSUBLOC location for print files
### SCRIPTLOC   location for script files (menu.vim, bugreport.vim, ..)
### You can override these if you want to install them somewhere else.
### Edit feature.h for compile-time settings.
VIMLOC          = $DATADIR$VIMDIR
@if not _no.get("VIMRTLOC"):
    VIMRTLOC        = $DATADIR$VIMDIR$VIMRTDIR
VIMRCLOC        = $VIMLOC
HELPSUBLOC      = $VIMRTLOC$HELPSUBDIR
COLSUBLOC       = $VIMRTLOC$COLSUBDIR
SYNSUBLOC       = $VIMRTLOC$SYNSUBDIR
INDSUBLOC       = $VIMRTLOC$INDSUBDIR
AUTOSUBLOC      = $VIMRTLOC$AUTOSUBDIR
PLUGSUBLOC      = $VIMRTLOC$PLUGSUBDIR
FTPLUGSUBLOC    = $VIMRTLOC$FTPLUGSUBDIR
LANGSUBLOC      = $VIMRTLOC$LANGSUBDIR
COMPSUBLOC      = $VIMRTLOC$COMPSUBDIR
KMAPSUBLOC      = $VIMRTLOC$KMAPSUBDIR
MACROSUBLOC     = $VIMRTLOC$MACROSUBDIR
TOOLSSUBLOC     = $VIMRTLOC$TOOLSSUBDIR
TUTORSUBLOC     = $VIMRTLOC$TUTORSUBDIR
SPELLSUBLOC	= $VIMRTLOC$SPELLSUBDIR
PRINTSUBLOC     = $VIMRTLOC$PRINTSUBDIR
SCRIPTLOC       = $VIMRTLOC

### Only set VIMRUNTIMEDIR when VIMRTLOC is set to a different location and
### the runtime directory is not below it.
#VIMRUNTIMEDIR = $VIMRTLOC

### Name of the evim file target.
EVIM_FILE       = $DESTDIR$SCRIPTLOC/evim.vim
MSWIN_FILE      = $DESTDIR$SCRIPTLOC/mswin.vim

### Name of the menu file target.
SYS_MENU_FILE   = $DESTDIR$SCRIPTLOC/menu.vim
SYS_SYNMENU_FILE = $DESTDIR$SCRIPTLOC/synmenu.vim
SYS_DELMENU_FILE = $DESTDIR$SCRIPTLOC/delmenu.vim

### Name of the bugreport file target.
SYS_BUGR_FILE   = $DESTDIR$SCRIPTLOC/bugreport.vim

### Name of the file type detection file target.
SYS_FILETYPE_FILE = $DESTDIR$SCRIPTLOC/filetype.vim

### Name of the file type detection file target.
SYS_FTOFF_FILE  = $DESTDIR$SCRIPTLOC/ftoff.vim

### Name of the file type detection script file target.
SYS_SCRIPTS_FILE = $DESTDIR$SCRIPTLOC/scripts.vim

### Name of the ftplugin-on file target.
SYS_FTPLUGIN_FILE = $DESTDIR$SCRIPTLOC/ftplugin.vim

### Name of the ftplugin-off file target.
SYS_FTPLUGOF_FILE = $DESTDIR$SCRIPTLOC/ftplugof.vim

### Name of the indent-on file target.
SYS_INDENT_FILE = $DESTDIR$SCRIPTLOC/indent.vim

### Name of the indent-off file target.
SYS_INDOFF_FILE = $DESTDIR$SCRIPTLOC/indoff.vim

### Name of the option window script file target.
SYS_OPTWIN_FILE = $DESTDIR$SCRIPTLOC/optwin.vim

### Permissions for binaries
BINMOD = 755

### Permissions for man page
MANMOD = 644

### Permissions for help files
HELPMOD = 644

### Permissions for Perl and shell scripts
SCRIPTMOD = 755

### Permission for Vim script files (menu.vim, bugreport.vim, ..)
VIMSCRIPTMOD = 644

### Permissions for all directories that are created
DIRMOD = 755

### Permissions for all other files that are created
FILEMOD = 644

# Where to copy the man and help files from
HELPSOURCE = ../runtime/doc

# Where to copy the script files from (menu, bugreport)
SCRIPTSOURCE = ../runtime

# Where to copy the colorscheme files from
COLSOURCE = ../runtime/colors

# Where to copy the syntax files from
SYNSOURCE = ../runtime/syntax

# Where to copy the indent files from
INDSOURCE = ../runtime/indent

# Where to copy the standard plugin files from
AUTOSOURCE = ../runtime/autoload

# Where to copy the standard plugin files from
PLUGSOURCE = ../runtime/plugin

# Where to copy the ftplugin files from
FTPLUGSOURCE = ../runtime/ftplugin

# Where to copy the macro files from
MACROSOURCE = ../runtime/macros

# Where to copy the tools files from
TOOLSSOURCE = ../runtime/tools

# Where to copy the tutor files from
TUTORSOURCE = ../runtime/tutor

# Where to copy the spell files from
SPELLSOURCE = ../runtime/spell

# Where to look for language specific files
LANGSOURCE = ../runtime/lang

# Where to look for compiler files
COMPSOURCE = ../runtime/compiler

# Where to look for keymap files
KMAPSOURCE = ../runtime/keymap

# Where to look for print resource files
PRINTSOURCE = ../runtime/print

# abbreviations
DEST_BIN = $DESTDIR$BINDIR
DEST_VIM = $DESTDIR$VIMLOC
DEST_RT = $DESTDIR$VIMRTLOC
DEST_HELP = $DESTDIR$HELPSUBLOC
DEST_COL = $DESTDIR$COLSUBLOC
DEST_SYN = $DESTDIR$SYNSUBLOC
DEST_IND = $DESTDIR$INDSUBLOC
DEST_AUTO = $DESTDIR$AUTOSUBLOC
DEST_PLUG = $DESTDIR$PLUGSUBLOC
DEST_FTP = $DESTDIR$FTPLUGSUBLOC
DEST_LANG = $DESTDIR$LANGSUBLOC
DEST_COMP = $DESTDIR$COMPSUBLOC
DEST_KMAP = $DESTDIR$KMAPSUBLOC
DEST_MACRO = $DESTDIR$MACROSUBLOC
DEST_TOOLS = $DESTDIR$TOOLSSUBLOC
DEST_TUTOR = $DESTDIR$TUTORSUBLOC
DEST_SPELL = $DESTDIR$SPELLSUBLOC
DEST_SCRIPT = $DESTDIR$SCRIPTLOC
DEST_PRINT = $DESTDIR$PRINTSUBLOC
DEST_MAN_TOP = $DESTDIR$?(MANDIR)

# We assume that the ".../man/xx/man1/" directory is for latin1 manual pages.
# Some systems use UTF-8, but these should find the ".../man/xx.UTF-8/man1/"
# directory first.
# FreeBSD uses ".../man/xx.ISO8859-1/man1" for latin1, use that one too.
DEST_MAN = $(DEST_MAN_TOP)$(MAN1DIR)
DEST_MAN_FR = $(DEST_MAN_TOP)/fr$(MAN1DIR)
DEST_MAN_FR_I = $(DEST_MAN_TOP)/fr.ISO8859-1$(MAN1DIR)
DEST_MAN_FR_U = $(DEST_MAN_TOP)/fr.UTF-8$(MAN1DIR)
DEST_MAN_IT = $(DEST_MAN_TOP)/it$(MAN1DIR)
DEST_MAN_IT_I = $(DEST_MAN_TOP)/it.ISO8859-1$(MAN1DIR)
DEST_MAN_IT_U = $(DEST_MAN_TOP)/it.UTF-8$(MAN1DIR)
DEST_MAN_PL = $(DEST_MAN_TOP)/pl.ISO8859-2$(MAN1DIR)
DEST_MAN_PL_U = $(DEST_MAN_TOP)/pl.UTF-8$(MAN1DIR)
DEST_MAN_RU = $(DEST_MAN_TOP)/ru.KOI8-R$(MAN1DIR)
DEST_MAN_RU_U = $(DEST_MAN_TOP)/ru.UTF-8$(MAN1DIR)

# These are directories, create them when needed.
:attr {directory = $DIRMOD} $DEST_BIN $DEST_VIM $DEST_RT $DEST_HELP $DEST_COL
                $DEST_SYN $DEST_IND $DEST_AUTO $DEST_AUTO/xml $DEST_PLUG
                $DEST_FTP $DEST_LANG
                $DEST_COMP $DEST_KMAP $DEST_MACRO $DEST_TOOLS $DEST_TUTOR
                $DEST_SCRIPT $DEST_PRINT $DEST_MAN $DEST_SPELL
                $DEST_MAN_FR $DEST_MAN_FR_I $DEST_MAN_FR_U $DEST_MAN_IT
                $DEST_MAN_IT_I $DEST_MAN_IT_U
                $DEST_MAN_PL $DEST_MAN_PL_U
                $DEST_MAN_RU $DEST_MAN_RU_U

#
# I N S T A L L
#
install: $GUI_INSTALL

install_normal:
    @if not os.path.isdir(_no.DEST_BIN):
        @try:
            :mkdir $DEST_BIN
        @except:
        @   pass
    @if os.access(_no.DEST_BIN, os.W_OK):
        # Bin directory is writable, install directly.
        :update installvim installtools $INSTALL_LANGS install-icons
    @else:
        # Bin directory is not writable, need to become root.
        :print The destination directory "$DEST_BIN" is not writable.
        :print If this is the wrong directory, use PREFIX to specify another one.
        :print Otherwise, type the root password to continue installing.
        :asroot $AAP install

installvim {virtual}: installvimbin  installtutorbin \
                        installruntime installlinks installmanlinks

installvimbin {virtual}{force}: $Target $DEST_BIN
        exe = $DEST_BIN/$VIMTARGET
        @if os.path.exists(exe):
            # Move the old executable aside and delete it.  Any other method
            # may cause a crash if the executable is currently being used.
            :move {force} $exe $(exe).rm
            :del {force} $(exe).rm
        :copy $VIMTARGET $DEST_BIN
        :do strip $exe
        :chmod $BINMOD $DEST_BIN/$VIMTARGET
# may create a link to the new executable from /usr/bin/vi
        @if _no.get("LINKIT"):
            :sys $LINKIT

# Long list of arguments for the shell script that installs the manual pages
# for one language.
INSTALLMANARGS = $(VIMLOC) $(SCRIPTLOC) $(VIMRCLOC) $(HELPSOURCE) $(MANMOD) \
		$(VIMNAME) $(VIMDIFFNAME) $(EVIMNAME)

# Install most of the runtime files
installruntime {virtual}: installrtbase installmacros installtutor installspell

# install the help files; first adjust the contents for the location
installrtbase {virtual}{force}: $HELPSOURCE/vim.1 $DEST_VIM
                $DEST_RT $DEST_HELP $DEST_COL $DEST_SYN $DEST_IND
                $DEST_FTP $DEST_AUTO $DEST_AUTO/xml $DEST_PLUG $DEST_TUTOR
                $DEST_COMP $DEST_SPELL $DEST_PRINT
        :chmod 755 installman.sh
        :sys ./installman.sh install $(DEST_MAN) "" $(INSTALLMANARGS)

        :cd $HELPSOURCE
        @try:
            XTRA = `glob.glob("*.??x")` `glob.glob("tags-??")`
        @except:
            XTRA =       # It's OK if there are no matches.
        :copy *.txt tags $XTRA $DEST_HELP
        :cd -
        :cd $DEST_HELP
        :chmod $HELPMOD *.txt tags $XTRA
        :cd -
        :copy  $HELPSOURCE/*.pl $DEST_HELP
        :chmod $SCRIPTMOD $DEST_HELP/*.pl
# install the menu files
        :copy $SCRIPTSOURCE/menu.vim $SYS_MENU_FILE
        :chmod $VIMSCRIPTMOD $SYS_MENU_FILE
        :copy $SCRIPTSOURCE/synmenu.vim $SYS_SYNMENU_FILE
        :chmod $VIMSCRIPTMOD $SYS_SYNMENU_FILE
        :copy $SCRIPTSOURCE/delmenu.vim $SYS_DELMENU_FILE
        :chmod $VIMSCRIPTMOD $SYS_DELMENU_FILE
# install the evim file
        :copy $SCRIPTSOURCE/mswin.vim $MSWIN_FILE
        :chmod $VIMSCRIPTMOD $MSWIN_FILE
        :copy $SCRIPTSOURCE/evim.vim $EVIM_FILE
        :chmod $VIMSCRIPTMOD $EVIM_FILE
# install the bugreport file
        :copy $SCRIPTSOURCE/bugreport.vim $SYS_BUGR_FILE
        :chmod $VIMSCRIPTMOD $SYS_BUGR_FILE
# install the example vimrc files
        :copy $SCRIPTSOURCE/vimrc_example.vim $DEST_SCRIPT
        :chmod $VIMSCRIPTMOD $DEST_SCRIPT/vimrc_example.vim
        :copy $SCRIPTSOURCE/gvimrc_example.vim $DEST_SCRIPT
        :chmod $VIMSCRIPTMOD $DEST_SCRIPT/gvimrc_example.vim
# install the file type detection files
        :copy $SCRIPTSOURCE/filetype.vim $SYS_FILETYPE_FILE
        :chmod $VIMSCRIPTMOD $SYS_FILETYPE_FILE
        :copy $SCRIPTSOURCE/ftoff.vim $SYS_FTOFF_FILE
        :chmod $VIMSCRIPTMOD $SYS_FTOFF_FILE
        :copy $SCRIPTSOURCE/scripts.vim $SYS_SCRIPTS_FILE
        :chmod $VIMSCRIPTMOD $SYS_SCRIPTS_FILE
        :copy $SCRIPTSOURCE/ftplugin.vim $SYS_FTPLUGIN_FILE
        :chmod $VIMSCRIPTMOD $SYS_FTPLUGIN_FILE
        :copy $SCRIPTSOURCE/ftplugof.vim $SYS_FTPLUGOF_FILE
        :chmod $VIMSCRIPTMOD $SYS_FTPLUGOF_FILE
        :copy $SCRIPTSOURCE/indent.vim $SYS_INDENT_FILE
        :chmod $VIMSCRIPTMOD $SYS_INDENT_FILE
        :copy $SCRIPTSOURCE/indoff.vim $SYS_INDOFF_FILE
        :chmod $VIMSCRIPTMOD $SYS_INDOFF_FILE
        :copy $SCRIPTSOURCE/optwin.vim $SYS_OPTWIN_FILE
        :chmod $VIMSCRIPTMOD $SYS_OPTWIN_FILE
# install the print resource files
        :copy $PRINTSOURCE/*.ps $DEST_PRINT
        :chmod $FILEMOD $DEST_PRINT/*.ps
# install the colorscheme files
        :copy $COLSOURCE/*.vim $COLSOURCE/README.txt $DEST_COL
        :chmod $HELPMOD $DEST_COL/*.vim $DEST_COL/README.txt
# install the syntax files
        :copy $SYNSOURCE/*.vim $SYNSOURCE/README.txt $DEST_SYN
        :chmod $HELPMOD $DEST_SYN/*.vim $DEST_SYN/README.txt
# install the indent files
        :copy $INDSOURCE/*.vim $INDSOURCE/README.txt $DEST_IND
        :chmod $HELPMOD $DEST_IND/*.vim
# install the standard autoload files
        :copy $AUTOSOURCE/*.vim $AUTOSOURCE/README.txt $DEST_AUTO
        :chmod $HELPMOD $DEST_AUTO/*.vim $DEST_AUTO/README.txt
        :copy $AUTOSOURCE/xml/*.vim $DEST_AUTO/xml
        :chmod $HELPMOD $DEST_AUTO/xml/*.vim
# install the standard plugin files
        :copy $PLUGSOURCE/*.vim $PLUGSOURCE/README.txt $DEST_PLUG
        :chmod $HELPMOD $DEST_PLUG/*.vim $DEST_PLUG/README.txt
# install the ftplugin files
        :copy $FTPLUGSOURCE/*.vim $FTPLUGSOURCE/README.txt $DEST_FTP
        :chmod $HELPMOD $DEST_FTP/*.vim $DEST_FTP/README.txt
# install the compiler files
        :copy $COMPSOURCE/*.vim $COMPSOURCE/README.txt $DEST_COMP
        :chmod $HELPMOD $DEST_COMP/*.vim $DEST_COMP/README.txt

installmacros {virtual}{force}: $MACROSOURCE $DEST_VIM $DEST_RT $DEST_MACRO
        :copy {recursive}{force} $MACROSOURCE/* $DEST_MACRO
        # Delete any CVS and AAPDIR directories.
        # Use the ":tree" command if possible.  It was added later, fall back
        # to using "find" when it doesn't work.
        @try:
           :tree $DEST_MACRO {dirname = CVS}
              :del {recursive} $name
           :tree $DEST_MACRO {dirname = AAPDIR}
              :del {recursive} $name
           :tree $DEST_MACRO {dirname = .*}
              :chmod $DIRMOD $name
           :tree $DEST_MACRO {filename = .*}
              :chmod $FILEMOD $name
        @except:
        @  ok, cvsdirs = redir_system('find %s -name CVS -print' % _no.DEST_MACRO)
        @  if ok and cvsdirs:
             :del {recursive} $cvsdirs
           :sys chmod $DIRMOD ``find $DEST_MACRO -type d -print``
           :sys chmod $FILEMOD ``find $DEST_MACRO -type f -print``
        :chmod $SCRIPTMOD $DEST_MACRO/less.sh

# install the tutor files
installtutorbin {virtual}{force}: $DEST_VIM
        :copy vimtutor $DEST_BIN/$(VIMNAME)tutor
        :chmod $SCRIPTMOD $DEST_BIN/$(VIMNAME)tutor

installtutor {virtual}{force}: $DEST_RT $DEST_TUTOR
        :copy $TUTORSOURCE/tutor* $TUTORSOURCE/README* $DEST_TUTOR
        :chmod $HELPMOD $DEST_TUTOR/*

# Install the spell files, if they exist.  This assumes at least the English
# spell file is there.
installspell {virtual}: $(DEST_VIM) $(DEST_RT) $(DEST_SPELL)
	enspl = $(SPELLSOURCE)/en.latin1.spl
        @if os.path.exists(enspl):
            :copy $(SPELLSOURCE)/*.spl $(SPELLSOURCE)/*.vim $(DEST_SPELL)
            :chmod $(HELPMOD) $(DEST_SPELL)/*.spl $(DEST_SPELL)/*.vim
            @try:
                :copy $(SPELLSOURCE)/*.sug $(DEST_SPELL)
                :chmod $(HELPMOD) $(DEST_SPELL)/*.sug
            @except:
            @   pass

# install helper program xxd
installtools {virtual}{force}: $TOOLS $DEST_BIN $DEST_MAN \
                $TOOLSSOURCE $DEST_VIM $DEST_RT $DEST_TOOLS \
                $INSTALL_TOOL_LANGS
        xxd = $DEST_BIN/xxd$EXESUF
        @if os.path.exists(xxd):
          :move {force} $xxd $(xxd).rm
          :del $(xxd).rm
        :copy xxd/xxd$EXESUF $DEST_BIN
        :do strip $DEST_BIN/xxd$EXESUF
        :chmod $BINMOD $DEST_BIN/xxd$EXESUF
        :chmod 755 installman.sh
        :sys ./installman.sh xxd $(DEST_MAN) "" $(INSTALLMANARGS)
#
# install the runtime tools
        @try:
        @  if aap_has(":tree"):
              # New method: copy everything and delete CVS and AAPDIR dirs
              :copy {recursive} $TOOLSSOURCE/* $DEST_TOOLS
              :tree $DEST_TOOLS {dirname = CVS}
                 :delete {recursive} $name
              :tree $DEST_TOOLS {dirname = AAPDIR}
                 :delete {recursive} $name
        @except:
            # Old method: copy only specific files and directories.
            :copy {recursive} $TOOLSSOURCE/README.txt $TOOLSSOURCE/[a-z]* $DEST_TOOLS
        :chmod $FILEMOD $DEST_TOOLS/*
# replace the path in some tools
        :progsearch perlpath perl
        @if perlpath:
            :cat $TOOLSSOURCE/efm_perl.pl |
                    :eval re.sub("/usr/bin/perl", perlpath, stdin)
                    >! $DEST_TOOLS/efm_perl.pl
        @else:
            :copy $TOOLSSOURCE/efm_perl.pl $DEST_TOOLS

        :progsearch awkpath nawk gawk awk
        @if awkpath:
            :cat $TOOLSSOURCE/mve.awk |
                    :eval re.sub("/usr/bin/nawk", awkpath, stdin)
                    >! $DEST_TOOLS/mve.awk
        @else:
            :copy $TOOLSSOURCE/mve.awk $DEST_TOOLS

        :sys chmod $SCRIPTMOD ``grep -l "^#!" $DEST_TOOLS/*``

# install the language specific files for tools, if they were unpacked
install-tool-languages:
        :chmod 755 installman.sh
        :sys ./installman.sh xxd $(DEST_MAN_FR) "-fr" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_FR_I) "-fr" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_FR_U) "-fr.UTF-8" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_IT) "-it" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_IT_I) "-it" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_IT_U) "-it.UTF-8" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_PL) "-pl" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_PL_U) "-pl.UTF-8" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_RU) "-ru" $(INSTALLMANARGS)
	:sys ./installman.sh xxd $(DEST_MAN_RU_U) "-ru.UTF-8" $(INSTALLMANARGS)

# install the language specific files, if they were unpacked
install-languages {virtual}{force}: languages $DEST_LANG $DEST_KMAP
        :chmod 755 installman.sh
        :sys ./installman.sh install $(DEST_MAN_FR) "-fr" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_FR_I) "-fr" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_FR_U) "-fr.UTF-8" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_IT) "-it" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_IT_I) "-it" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_IT_U) "-it.UTF-8" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_PL) "-pl" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_PL_U) "-pl.UTF-8" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_RU) "-ru" $(INSTALLMANARGS)
	:sys ./installman.sh install $(DEST_MAN_RU_U) "-ru.UTF-8" $(INSTALLMANARGS)
        :chmod 755 installml.sh
	:sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_FR) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_FR_I) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_FR_U) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_IT) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_IT_I) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_IT_U) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_PL) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_PL_U) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_RU) $(INSTALLMLARGS)
        :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN_RU_U) $(INSTALLMLARGS)

        @if _no.MAKEMO:
           :sys cd $PODIR; $MAKE prefix=$DESTDIR$prefix \
                    LOCALEDIR=$DEST_LANG INSTALL_DATA=cp FILEMOD=$FILEMOD install
        @if os.path.exists(_no.LANGSOURCE):
           :print installing language files
           :copy $LANGSOURCE/README.txt $LANGSOURCE/*.vim $DEST_LANG
           :chmod $FILEMOD $DEST_LANG/*.vim
        @if os.path.exists(_no.KMAPSOURCE):
           :copy $KMAPSOURCE/README.txt $KMAPSOURCE/*.vim $DEST_KMAP
           :chmod $FILEMOD $DEST_KMAP/*.vim

# install the icons for KDE, if the directory exists and the icon doesn't.
ICON48PATH = $DESTDIR$DATADIR/icons/hicolor/48x48/apps
ICON32PATH = $DESTDIR$DATADIR/icons/locolor/32x32/apps
ICON16PATH = $DESTDIR$DATADIR/icons/locolor/16x16/apps
KDEPATH = $HOME/.kde/share/icons
install-icons {virtual}:
        gp = $ICON48PATH/gvim.png
        @if os.path.isdir(_no.ICON48PATH) and not os.path.exists(gp):
           :copy $SCRIPTSOURCE/vim48x48.png $gp
        gp = $ICON32PATH/gvim.png
        @if os.path.isdir(_no.ICON32PATH) and not os.path.exists(gp):
           :copy $SCRIPTSOURCE/vim32x32.png $gp
        gp = $ICON16PATH/gvim.png
        @if os.path.isdir(_no.ICON16PATH) and not os.path.exists(gp):
           :copy $SCRIPTSOURCE/vim16x16.png $gp


$HELPSOURCE/vim.1 $MACROSOURCE $TOOLSSOURCE:
        @if not os.path.exists(_no.TOOLSSOURCE):
            :print Runtime files not found.
            :error You need to unpack the runtime archive before running "make install".

# create links from various names to vim.  This is only done when the links
# (or executables with the same name) don't exist yet.
installlinks {virtual}: $GUI_TARGETS \
                        $DEST_BIN/$EXTARGET \
                        $DEST_BIN/$VIEWTARGET \
                        $DEST_BIN/$RVIMTARGET \
                        $DEST_BIN/$RVIEWTARGET \
                        $INSTALLVIMDIFF

installglinks {virtual}: $DEST_BIN/$GVIMTARGET \
                        $DEST_BIN/$GVIEWTARGET \
                        $DEST_BIN/$RGVIMTARGET \
                        $DEST_BIN/$RGVIEWTARGET \
                        $DEST_BIN/$EVIMTARGET \
                        $DEST_BIN/$EVIEWTARGET \
                        $INSTALLGVIMDIFF

installvimdiff {virtual}: $DEST_BIN/$VIMDIFFTARGET
installgvimdiff {virtual}: $DEST_BIN/$GVIMDIFFTARGET

# These dependencies use an empty buildcheck so that they are only done when
# the target doesn't exist.
$DEST_BIN/$EXTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $EXTARGET

$DEST_BIN/$VIEWTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $VIEWTARGET

$DEST_BIN/$GVIMTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $GVIMTARGET

$DEST_BIN/$GVIEWTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $GVIEWTARGET

$DEST_BIN/$RVIMTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $RVIMTARGET

$DEST_BIN/$RVIEWTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $RVIEWTARGET

$DEST_BIN/$RGVIMTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $RGVIMTARGET

$DEST_BIN/$RGVIEWTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $RGVIEWTARGET

$DEST_BIN/$VIMDIFFTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $VIMDIFFTARGET

$DEST_BIN/$GVIMDIFFTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $GVIMDIFFTARGET

$DEST_BIN/$EVIMTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $EVIMTARGET

$DEST_BIN/$EVIEWTARGET: {buildcheck = }
    :sys cd $DEST_BIN; ln -s $VIMTARGET $EVIEWTARGET

# create links for the manual pages with various names to vim.  This is only
# done when the links (or manpages with the same name) don't exist yet.
INSTALLMLARGS = $(VIMNAME) $(VIMDIFFNAME) $(EVIMNAME) \
		$(EXNAME) $(VIEWNAME) $(RVIMNAME) $(RVIEWNAME) \
		$(GVIMNAME) $(GVIEWNAME) $(RGVIMNAME) $(RGVIEWNAME) \
		$(GVIMDIFFNAME) $(EVIEWNAME)

installmanlinks {virtual}:
    :chmod 755 installml.sh
    :sys ./installml.sh install "$(GUI_MAN_TARGETS)" \
		$(DEST_MAN) $(INSTALLMLARGS)

#
# U N I N S T A L L
#
uninstall {virtual}{force}: uninstall_runtime
    :del {force} $DEST_BIN/$VIMTARGET
    :del {force} $DEST_BIN/vimtutor
    :del {force} $DEST_BIN/$EXTARGET $DEST_BIN/$VIEWTARGET
    :del {force} $DEST_BIN/$GVIMTARGET $DEST_BIN/$GVIEWTARGET
    :del {force} $DEST_BIN/$RVIMTARGET $DEST_BIN/$RVIEWTARGET
    :del {force} $DEST_BIN/$RGVIMTARGET $DEST_BIN/$RGVIEWTARGET
    :del {force} $DEST_BIN/$VIMDIFFTARGET $DEST_BIN/$GVIMDIFFTARGET
    :del {force} $DEST_BIN/$EVIMTARGET $DEST_BIN/$EVIEWTARGET
    :del {force} $DEST_BIN/xxd$EXESUF

# Note: "deldir" will fail if any files were added after "make install", that
# is intentionally: Keep files the user added.
uninstall_runtime {virtual}{force}:
    :chmod 755 installman.sh
    :sys ./installman.sh uninstall $(DEST_MAN) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_FR) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_FR_I) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_FR_U) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_IT) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_IT_I) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_IT_U) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_PL) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_PL_U) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_RU) "" $(INSTALLMANARGS)
    :sys ./installman.sh uninstall $(DEST_MAN_RU_U) "" $(INSTALLMANARGS)
    :chmod 755 installml.sh
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_FR) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_FR_I) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_FR_U) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_IT) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_IT_I) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_IT_U) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_PL) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_PL_U) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_RU) $(INSTALLMLARGS)
    :sys ./installml.sh uninstall "$(GUI_MAN_TARGETS)" \
            $(DEST_MAN_RU_U) $(INSTALLMLARGS)
    :del {force} $DEST_MAN/xxd.1
    :del {force} $(DEST_MAN_FR)/xxd.1 $(DEST_MAN_FR_I)/xxd.1 $(DEST_MAN_FR_U)/xxd.1
    :del {force} $(DEST_MAN_IT)/xxd.1 $(DEST_MAN_IT_I)/xxd.1 $(DEST_MAN_IT_U)/xxd.1
    :del {force} $(DEST_MAN_PL)/xxd.1 $(DEST_MAN_PL_U)/xxd.1
    :del {force} $(DEST_MAN_RU)/xxd.1 $(DEST_MAN_RU_U)/xxd.1

    :del {force} $DEST_HELP/*.txt $DEST_HELP/tags $DEST_HELP/*.pl
    :del {force} $SYS_MENU_FILE $SYS_SYNMENU_FILE $SYS_DELMENU_FILE
    :del {force} $SYS_BUGR_FILE $EVIM_FILE $MSWIN_FILE
    :del {force} $DEST_SCRIPT/gvimrc_example.vim $DEST_SCRIPT/vimrc_example.vim
    :del {force} $SYS_FILETYPE_FILE $SYS_FTOFF_FILE $SYS_SCRIPTS_FILE
    :del {force} $SYS_INDOFF_FILE $SYS_INDENT_FILE
    :del {force} $SYS_FTPLUGOF_FILE $SYS_FTPLUGIN_FILE
    :del {force} $SYS_OPTWIN_FILE
    :del {force} $DEST_COL/*.vim $DEST_COL/README.txt
    :del {force} $DEST_SYN/*.vim $DEST_SYN/README.txt
    :del {force} $DEST_IND/*.vim $DEST_IND/README.txt
    :del {force} $DEST_PRINT/*.ps
    :del {force}{recursive} $DEST_MACRO
    :del {force}{recursive} $DEST_TUTOR
    :del {force}{recursive} $DEST_SPELL
    :del {force}{recursive} $DEST_TOOLS
    :del {force}{recursive} $DEST_LANG
    :del {force}{recursive} $DEST_KMAP
    :del {force}{recursive} $DEST_COMP
    :deldir {force} $DEST_HELP $DEST_COL $DEST_SYN $DEST_IND
    :del {force}{recursive} $DEST_FTP/*.vim $DEST_FTP/README.txt
    :del {force} $DEST_AUTO/*.vim $DEST_AUTO/README.txt $DEST_AUTO/xml/*.vim
    :del {force} $DEST_PLUG/*.vim $DEST_PLUG/README.txt
    :deldir {force} $DEST_FTP $DEST_AUTO/xml $DEST_AUTO $DEST_PLUG $DEST_PRINT $DEST_RT
#       This will fail when other Vim versions are installed, no worries.
    @try:
        :deldir $DEST_VIM
    @except:
        :print Cannot delete $DEST_VIM

###############################################################################
### MacOS X installation
###
### This installs a runnable Vim.app in $(prefix)

REZ    = /Developer/Tools/Rez
RESDIR = $(APPDIR)/Contents/Resources
@r = re.compile('.*VIM_VERSION_SHORT\\s*"(\\d[^"]*)".*', re.S)
VERSION = /`r.match(open("version.h").read()).group(1)`

### Common flags
M4FLAGSX = $?(M4FLAGS) -DAPP_EXE=$(VIMNAME) -DAPP_NAME=$(VIMNAME) \
		-DAPP_VER=$(VERSION)

# Resources used for the Mac are in one directory.
RSRC_DIR = os_mac_rsrc

:attr {directory = $DIRMOD} $RESDIR

install_macosx {virtual}: gui_bundle
# Remove the link to the runtime dir, don't want to copy all of that.
        :delete {force} $(RESDIR)/vim/runtime
        :copy {r} $APPDIR $DESTDIR$prefix
        :tree $DESTDIR$prefix {dirname = AAPDIR}
             :delete {recursive} $name
# Install the runtime files.  Recursive!
	:mkdir {r}{f} $DESTDIR$prefix/$RESDIR/vim/runtime
#	:mkdir $(DESTDIR)$(prefix)/$(APPDIR)/bin
        :execute main.aap PREFIX=$DESTDIR$prefix/$RESDIR/vim VIMRTLOC=$DESTDIR$prefix/$RESDIR/vim/runtime installruntime
# Put the link back.
        :symlink `os.getcwd()`/../runtime $RESDIR/vim/runtime
# TODO: Create the vimtutor application.

gui_bundle {virtual}: $(RESDIR) bundle-dir bundle-executable bundle-info \
                        bundle-resource bundle-language

bundle-dir {virtual}: $(APPDIR)/Contents $(VIMTARGET)
# Make a link to the runtime directory, so that we can try out the executable
# without installing it.
        :mkdir {r}{f} $(RESDIR)/vim
        :symlink {quiet} `os.getcwd()`/../runtime $(RESDIR)/vim/runtime

bundle-executable {virtual}: $(VIMTARGET)
        :mkdir {r}{f} $(APPDIR)/Contents/MacOS
        :copy $(VIMTARGET) $(APPDIR)/Contents/MacOS/$(VIMTARGET)

bundle-info {virtual}:  bundle-dir
        :print Creating PkgInfo
        :print "APPLVIM!" >! $(APPDIR)/Contents/PkgInfo
        :print Creating Info.plist
        :sys m4 $(M4FLAGSX) infplist.xml > $(APPDIR)/Contents/Info.plist

bundle-resource {virtual}: bundle-dir bundle-rsrc
        :copy {force} $(RSRC_DIR)/*.icns $(RESDIR)

### Classic resources
# Resource fork (in the form of a .rsrc file) for Classic Vim (Mac OS 9)
# This file is also required for OS X Vim.
bundle-rsrc {virtual}: os_mac.rsr.hqx
    :print Creating resource fork
    :sys python dehqx.py $source
    :del {force} gui_mac.rsrc
    :move gui_mac.rsrc.rsrcfork $(RESDIR)/$(VIMNAME).rsrc

# po/Make_osx.pl says something about generating a Mac message file
# for Ukrainian.  Would somebody using Mac OS X in Ukrainian
# *really* be upset that Carbon Vim was not localised in
# Ukrainian?
#
#bundle-language: bundle-dir po/Make_osx.pl
#	cd po && perl Make_osx.pl --outdir ../$(RESDIR) $(MULTILANG)
bundle-language {virtual}: bundle-dir

$(APPDIR)/Contents:
    :mkdir {r} $(APPDIR)/Contents/MacOS
    :mkdir {r} $(RESDIR)/English.lproj


# vim: sts=4 sw=4 :