File: mkstublib

package info (click to toggle)
ocamlnet 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 51,764 kB
  • ctags: 16,446
  • sloc: ml: 148,419; ansic: 10,989; sh: 1,885; makefile: 1,355
file content (123 lines) | stat: -rwxr-xr-x 2,120 bytes parent folder | download | duplicates (5)
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
#! /bin/sh

# usage: like ocamlmklib. This is only to be used until O'Caml 3.10.
# O'Caml 3.11 supports ocamlmklib on mingw!

mingw_mklib () {
	libname=""
	clibname=""
	cmo=""
	cmx=""
	o=""
	dyno=""
	libopts=""
	ldopts=""
	ccopts=""

	while [ $# -gt 0 ]; do
		case "$1" in
			-o)
				libname="$2"; shift 2 ;;
			-oc)
				clibname="$2"; shift 2 ;;
			*.o)
				file="$1"
				o="$o $file"
				if [ -f "${file%*.o}".d.o ]; then
					dyno="$dyno ${file%*.o}.d.o"
				fi
				shift ;;
			*.a)
				echo "Archives not supported: $1" >&2
				exit 1 ;;
			*.cmo)
				cmo="$cmo $1"; shift ;;
			*.cmx)
				cmx="$cmx $1"; shift ;;
			-cclib)
				libopts="$libopts $2"; shift 2 ;;
			-ccopt)
				ccopts="$ccopts $2"; shift 2 ;;
			-ldopt)
				ldopts="$ldopts $2"; shift 2 ;;
			-L)
				ccopts="$ccopts -L$2"; shift 2 ;;
			-L*)
				ccopts="$ccopts $1"; shift ;;
			-l)
				libopts="$libopts -l$2"; shift 2 ;;
			-l*)
				libopts="$libopts $1"; shift ;;
			*)
				: ;;
		esac
	done

	if [ -z "$clibname" ]; then
		clibname="$libname"
	fi

	if [ -z "$libname" ]; then
		echo "Missing -o option!" >&2
		exit 1
	fi

	# Create static archive:
	if [ -n "$o" ]; then
		set -x
		rm -f "lib$clibname.a"
		ar cr "lib$clibname.a" $o
		ranlib "lib$clibname.a"	
		set +x
	fi

	# Create DLL:
	if [ -n "$dyno" -a -n "$cmo" ]; then
		stdlib=`ocamlc -where | sed -e 's/\r//'`
		set -x
		gcc -mno-cygwin -shared -o "dll$clibname.dll" \
			$dyno $ccopts $ldopts $libopts $stdlib/ocamlrun.a
		set +x
	fi

	# Create ocaml archive(s):
	if [ -n "$cmo" ]; then
		set -x
		ocamlc -a -o "$libname.cma" $cmo -dllib "-l$clibname" \
			-cclib "-l$clibname" -ccopt "$ccopts" \
			-cclib "$cclibs"
		set +x
	fi
	if [ -n "$cmx" ]; then
		set -x
		ocamlopt -a -o "$libname.cmxa" $cmx \
			-cclib "-l$clibname" -ccopt "$ccopts" \
			-cclib "$cclibs"
		set +x
	fi
}





set -e
system=`ocamlc -config | grep system | sed -e 's/system: //'`
version=`ocamlc -version`

case "$version" in
	3.09|3.09.*|3.10|3.10.*|3.11.0*)
		case "$system" in
			mingw*)
				mingw_mklib "$@" ;;
			*)
				set +x
				ocamlmklib "$@" ;;
		esac
		;;
	*)
		set +x
		ocamlmklib "$@"
		;;
esac