summaryrefslogtreecommitdiff
path: root/web/glasgow/lit2x-0.16/mkworld/jmkmf.prl
blob: fe4dcd2edfd0f80fb61681565bc3ce57c649bda6 (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
# this *.prl file is shoved through "msub"
#
# generate a Makefile from a Jmakefile from _outside_ [only] the GHC
# sources!
#
# based on X11R4 xmkmf /bin/sh script via Paul DuBois
#
# uses:
# (1) a new project with no special jmake requirements; want to use
#     installed "none"-project stuff:
#	type% cd top-of-project-sources
#	type% jmkmf
#
# (2) a new project with a "project-label" (and maybe a "setup-label")
#
#	type% cd top-of-project-sources
#   	type% jmkmf -P project-label -S setup-label [-C project-config-dir]
#
# (3) for a project using installed utils, jmkmf will be invoked when
#     "make Makefile" happens:
#
#      jmkmf -P <proj-label> -S <setup-label> - -DTopDir=<foo> -DTopDirPwd=<bar> -DCurDir=<baz>
#
#     The "-" separates the getopt-able options from the rest.
#
# The -S option may be omitted if "setup-label" is "std" and -C option
# may be omitted if the project's config files happen to live in the
# std place (see -A).
#
# The "-A allprojects-config-dir" option may be used to override
# jmkmf's built-in idea of where the jmake config files are installed.
#
# don't let people fiddle with TopDir and CurDir
#
$Pgm = $0; $Pgm =~ s/.*\/([^\/]+)$/\1/;
$Status    = 0;
do 'getopts.pl' || die "Giant error 'do'ing getopts.pl: $@";
$Usage  = "usage: $Pgm ".
	  '[-v] '.
	  '[-P project-label] '.
	  '[-S setup-label] '.
	  '[-C project-config-dir] '.
	  '[-A alternate-installed-config-dir] '.
	  "[- args to pass on to jmake]\n";

$TopDir = '.';
$CurDir = '.';
$jmake_extra_args = '';

chop($TopDirPwd = `pwd`);
$TopDirPwd =~ s/^\/tmp_mnt//; # anti-NFS attack

if ( ! &Getopts('A:C:P:S:v')) {
    print STDERR $Usage;
    exit 1;
} else {
    while ($#ARGV >= 0) {
	$_ = $ARGV[0]; shift(@ARGV);
	next               if /^-$/;
	$TopDir    = $1, next if /^-DTopDir=(.*)$/;
	$TopDirPwd = $1, next if /^-DTopDirPwd=(.*)$/;
	$CurDir    = $1, next if /^-DCurDir=(.*)$/;
	$jmake_extra_args .= " $_";
    }
}

$Verbose	    = ($opt_v) ?      1 :  0;
$Project_label	    = ($opt_P) ? $opt_P : 'none';
$Setup_label	    = ($opt_S) ? $opt_S : 'std';
$Project_config_dir = ($opt_C) ? $opt_C : '';
# the next line fixed up by msub
$Std_config_dir     = ($opt_A) ? $opt_A
			       : (( $(INSTALLING) ) ? '$(INSTDATADIR_MKWORLD)'
						    : '$(TOP_PWD)/$(CURRENT_DIR)');

# chk that all the config and dirs files will be there if needed?

# relative-ise Project_config_dir
$Have_project_config_dir = '';
$Project_config_dir_is_relative = '';
if ($Project_config_dir) {
    $Have_project_config_dir = '-DHaveProjectConfigDir';
    $Real_project_config_dir = $Project_config_dir;
    if ($Project_config_dir !~ /^\//) {
	$Project_config_dir_is_relative = '-DRelativeProjectConfigDir';
	if (! $TopDir) {
	    print STDERR "$Pgm: I don't know what TopDir is\n";
	} else {
	    $Real_project_config_dir= "$TopDir/$Project_config_dir";
	}
    }
    # tidy the name
    $Project_config_dir =~ s/^(\.\/)+/\.\//;
}

# do it
if ( -f Makefile ) {
    print STDERR "mv Makefile Makefile.bak\n";
    $Makefile_moved = 1;
    (system('mv -f Makefile Makefile.bak') >> 8) && die "$Pgm: mv -f Makefile Makefile.bak: failed\n";
} else {
    $Makefile_moved = 0;
}

# should this always -DUseInstalledUtils?

$jmake_args  = "-DUseInstalledUtils -P $Project_label -S $Setup_label";

$jmake_args .= " $Have_project_config_dir";
$jmake_args .= " $Project_config_dir_is_relative";
if ($Project_config_dir) {
    $jmake_args .= " -DProjectConfigDir=$Project_config_dir -I$Real_project_config_dir";
}
$jmake_args .= " -I$Std_config_dir";
$jmake_args .= " -DTopDir=$TopDir -DTopDirPwd=$TopDirPwd -DCurDir=$CurDir";
$jmake_args .= $jmake_extra_args;

print STDERR "jmake $jmake_args\n";
if (system("jmake $jmake_args") >> 8) {
    if ($Makefile_moved) {
	print STDERR "$Pgm: trying to restore Makefile...\n";
	rename('Makefile.bak','Makefile') || die "$Pgm: mv Makefile.bak Makefile: failed\n";
    } else {
	unlink('Makefile'); # don't want to confuse the issue
    }
    exit(1);
}
# chmod 0444, 'Makefile';
exit 0;