16 | 19 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,22 @@ |
1 |
+language: c |
|
2 |
+ |
|
3 |
+dist: precise |
|
4 |
+ |
|
5 |
+addons: |
|
6 |
+ apt: |
|
7 |
+ sources: |
|
8 |
+ - george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3 |
|
9 |
+ packages: |
|
10 |
+ - cmake |
|
11 |
+ - cmake-data |
|
12 |
+ |
|
13 |
+before_install: |
|
14 |
+ - git clone https://github.com/Linuxbrew/brew.git ~/.linuxbrew |
|
15 |
+ - PATH="$HOME/.linuxbrew/bin:$PATH" |
|
16 |
+ - brew update |
|
17 |
+ - brew tap mulle-kybernetik/software |
|
18 |
+ - brew install mulle-build |
|
19 |
+ |
|
20 |
+script: |
|
21 |
+ - mulle-build |
|
22 |
+ - mulle-test |
... | ... |
@@ -1,36 +1,79 @@ |
1 | 1 |
# mulle-vararg |
2 | 2 |
|
3 |
-A variable argument passing scheme used written in C (C11). |
|
3 |
+A variable argument passing scheme written in C (C11). |
|
4 |
+ |
|
4 | 5 |
|
5 | 6 |
## How it works |
6 | 7 |
|
7 |
-### Remember the C argument promotion rules |
|
8 |
+**mulle-vararg** assumes that the arguments are not layed out in stack |
|
9 |
+alignment fashion but like in a struct. The C promotion rules are still |
|
10 |
+observed though. |
|
8 | 11 |
|
9 |
-1. char and short to int/unsigned int |
|
10 |
-2. float to double |
|
12 |
+> Remember the C argument promotion rules are |
|
13 |
+> |
|
14 |
+> 1. char and short to int/unsigned int |
|
15 |
+> 2. float to double |
|
16 |
+> |
|
11 | 17 |
|
12 |
-### The arguments are layed out struct-like |
|
18 |
+Let's assume there is a compiler that does not use `<stdarg.h>` variable |
|
19 |
+arguments but **mulle-vararg** instead. It collects all arguments and packs |
|
20 |
+them into a struct, then passes this struct to the function. |
|
13 | 21 |
|
14 |
-A method like `stringWithFormat:(NSString *) format, ...` |
|
15 |
-which is called like this |
|
22 |
+A **printf** function being being called like this: |
|
16 | 23 |
|
17 | 24 |
``` |
18 |
-[NSString stringWithFormat:@"%d %f %lld", (char) 'x', (float) 0.2, 1848LL]; |
|
25 |
+printf( "%d %f %lld\n", (char) 'x', (float) 0.2, 1848LL; |
|
19 | 26 |
``` |
20 | 27 |
|
21 |
-could access the arguments as if they were embedded in a struct like this |
|
28 |
+would access the arguments, as if they were embedded in a struct like this |
|
22 | 29 |
|
23 | 30 |
``` |
24 | 31 |
struct |
25 | 32 |
{ |
26 |
- NSString *format; |
|
33 |
+ char *format; |
|
27 | 34 |
struct |
28 | 35 |
{ |
29 |
- int value1; |
|
30 |
- double value2; |
|
36 |
+ int value1; // standard char -> int promotion |
|
37 |
+ double value2; // standard float -> double promotion |
|
31 | 38 |
long long value3; |
32 | 39 |
} varargs; |
33 | 40 |
} _param; |
34 | 41 |
``` |
35 | 42 |
|
36 |
-But accessing those values, that's what mulle-vararg does for you. |
|
43 |
+**mulle-vararg** provides the necessary functions to read such a struct. It has |
|
44 |
+no code to create it. |
|
45 |
+ |
|
46 |
+ |
|
47 |
+## Install |
|
48 |
+ |
|
49 |
+On OS X and Linux you can use [homebrew](//brew.sh), respectively |
|
50 |
+[linuxbrew](//linuxbrew.sh) to install the library: |
|
51 |
+ |
|
52 |
+``` |
|
53 |
+brew tap mulle-kybernetik/software |
|
54 |
+brew install mulle-vararg |
|
55 |
+``` |
|
56 |
+ |
|
57 |
+On other platforms you can use **mulle-install** from |
|
58 |
+[mulle-build](//www.mulle-kybernetik.com/software/git/mulle-build) to install the library: |
|
59 |
+ |
|
60 |
+``` |
|
61 |
+mulle-install --prefix /usr/local --branch release https://www.mulle-kybernetik.com/repositories/mulle-vararg |
|
62 |
+``` |
|
63 |
+ |
|
64 |
+ |
|
65 |
+Otherwise read: |
|
66 |
+ |
|
67 |
+* [How to Build](dox/BUILD.md) |
|
68 |
+ |
|
69 |
+ |
|
70 |
+## API |
|
71 |
+ |
|
72 |
+* [Vararg](dox/API_VARARG.md) |
|
73 |
+ |
|
74 |
+ |
|
75 |
+### Platforms and Compilers |
|
76 |
+ |
|
77 |
+All platforms and compilers supported by |
|
78 |
+[mulle-c11](//www.mulle-kybernetik.com/software/git/mulle-c11/) |
|
79 |
+ |
37 | 80 |
deleted file mode 100755 |
... | ... |
@@ -1,68 +0,0 @@ |
1 |
-#! /bin/sh |
|
2 |
-# |
|
3 |
-# Generate a formula for mulle-thread |
|
4 |
-# |
|
5 |
-PROJECT=MulleVararg # ruby requires camel-case |
|
6 |
-TARGET=mulle-vararg |
|
7 |
-HOMEPAGE="http://www.mulle-kybernetik.com/software/git/${TARGET}" |
|
8 |
-DESC="Variable arguments using offset() and sizeof()" |
|
9 |
- |
|
10 |
-VERSION="$1" |
|
11 |
-[ $# -eq 0 ] || shift |
|
12 |
-ARCHIVEURL="${1:-http://www.mulle-kybernetik.com/software/git/${TARGET}/tarball/$VERSION}" |
|
13 |
-[ $# -eq 0 ] || shift |
|
14 |
- |
|
15 |
-set -e |
|
16 |
- |
|
17 |
-[ "$VERSION" = "" ] && exit 1 |
|
18 |
-[ "$ARCHIVEURL" = "" ] && exit 1 |
|
19 |
- |
|
20 |
- |
|
21 |
-TMPARCHIVE="/tmp/${TARGET}-${VERSION}-archive" |
|
22 |
- |
|
23 |
-if [ ! -f "${TMPARCHIVE}" ] |
|
24 |
-then |
|
25 |
- curl -L -o "${TMPARCHIVE}" "${ARCHIVEURL}" |
|
26 |
- if [ $? -ne 0 -o ! -f "${TMPARCHIVE}" ] |
|
27 |
- then |
|
28 |
- echo "Download failed" >&2 |
|
29 |
- exit 1 |
|
30 |
- fi |
|
31 |
-else |
|
32 |
- echo "using cached file ${TMPARCHIVE} instead of downloading again" >&2 |
|
33 |
-fi |
|
34 |
- |
|
35 |
-# |
|
36 |
-# anything less than 17 KB is wrong |
|
37 |
-# |
|
38 |
-size="`du -k "${TMPARCHIVE}" | awk '{ print $ 1}'`" |
|
39 |
-if [ $size -lt 17 ] |
|
40 |
-then |
|
41 |
- echo "Archive truncated or missing" >&2 |
|
42 |
- cat "${TMPARCHIVE}" >&2 |
|
43 |
- rm "${TMPARCHIVE}" |
|
44 |
- exit 1 |
|
45 |
-fi |
|
46 |
- |
|
47 |
-HASH="`shasum -p -a 256 "${TMPARCHIVE}" | awk '{ print $1 }'`" |
|
48 |
- |
|
49 |
-cat <<EOF |
|
50 |
-class ${PROJECT} < Formula |
|
51 |
- homepage "${HOMEPAGE}" |
|
52 |
- desc "${DESC}" |
|
53 |
- url "${ARCHIVEURL}" |
|
54 |
- version "${VERSION}" |
|
55 |
- sha256 "${HASH}" |
|
56 |
- |
|
57 |
- depends_on 'mulle-c11' |
|
58 |
- depends_on 'mulle-build' => :build |
|
59 |
- |
|
60 |
- def install |
|
61 |
- system "mulle-install", "-e", "--prefix", "#{prefix}" |
|
62 |
- end |
|
63 |
- |
|
64 |
- test do |
|
65 |
- end |
|
66 |
-end |
|
67 |
-# FORMULA ${TARGET}.rb |
|
68 |
-EOF |
69 | 0 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,231 @@ |
1 |
+#! /bin/sh |
|
2 |
+# |
|
3 |
+# |
|
4 |
+# |
|
5 |
+ |
|
6 |
+generate_brew_formula() |
|
7 |
+{ |
|
8 |
+ local project |
|
9 |
+ local target |
|
10 |
+ local homepage |
|
11 |
+ local desc |
|
12 |
+ local version |
|
13 |
+ local archiveurl |
|
14 |
+ local dependencies |
|
15 |
+ |
|
16 |
+ project="$1" |
|
17 |
+ shift |
|
18 |
+ target="$1" |
|
19 |
+ shift |
|
20 |
+ homepage="$1" |
|
21 |
+ shift |
|
22 |
+ desc="$1" |
|
23 |
+ shift |
|
24 |
+ version="$1" |
|
25 |
+ shift |
|
26 |
+ archiveurl="$1" |
|
27 |
+ shift |
|
28 |
+ dependencies="$1" |
|
29 |
+ shift |
|
30 |
+ |
|
31 |
+ [ -z "${version}" ] && exit 1 |
|
32 |
+ [ -z "${archiveurl}" ] && exit 1 |
|
33 |
+ |
|
34 |
+ local tmparchive |
|
35 |
+ |
|
36 |
+ tmparchive="/tmp/${target}-${version}-archive" |
|
37 |
+ |
|
38 |
+ if [ ! -f "${tmparchive}" ] |
|
39 |
+ then |
|
40 |
+ exekutor curl -L -o "${tmparchive}" "${archiveurl}" |
|
41 |
+ if [ $? -ne 0 -o ! -f "${tmparchive}" ] |
|
42 |
+ then |
|
43 |
+ echo "Download failed" >&2 |
|
44 |
+ exit 1 |
|
45 |
+ fi |
|
46 |
+ else |
|
47 |
+ echo "using cached file ${tmparchive} instead of downloading again" >&2 |
|
48 |
+ fi |
|
49 |
+ |
|
50 |
+ # |
|
51 |
+ # anything less than 17 KB is wrong |
|
52 |
+ # |
|
53 |
+ size="`exekutor du -k "${tmparchive}" | exekutor awk '{ print $ 1}'`" |
|
54 |
+ if [ $size -lt 17 ] |
|
55 |
+ then |
|
56 |
+ echo "Archive truncated or missing" >&2 |
|
57 |
+ cat "${tmparchive}" >&2 |
|
58 |
+ rm "${tmparchive}" |
|
59 |
+ exit 1 |
|
60 |
+ fi |
|
61 |
+ |
|
62 |
+ local hash |
|
63 |
+ |
|
64 |
+ hash="`exekutor shasum -p -a 256 "${tmparchive}" | exekutor awk '{ print $1 }'`" |
|
65 |
+ |
|
66 |
+ exekutor cat <<EOF |
|
67 |
+class ${project} < Formula |
|
68 |
+ homepage "${homepage}" |
|
69 |
+ desc "${desc}" |
|
70 |
+ url "${archiveurl}" |
|
71 |
+ version "${version}" |
|
72 |
+ sha256 "${hash}" |
|
73 |
+ |
|
74 |
+EOF |
|
75 |
+ |
|
76 |
+IFS=" |
|
77 |
+" |
|
78 |
+ for dependency in ${dependencies} |
|
79 |
+ do |
|
80 |
+ exekutor echo " depends_on '${dependency}'" |
|
81 |
+ shift |
|
82 |
+ done |
|
83 |
+ IFS="${DEFAULT_IFS}" |
|
84 |
+ |
|
85 |
+ exekutor cat <<EOF |
|
86 |
+ depends_on 'mulle-build' => :build |
|
87 |
+ |
|
88 |
+ def install |
|
89 |
+ system "mulle-install", "-e", "--prefix", "#{prefix}" |
|
90 |
+ end |
|
91 |
+ |
|
92 |
+ test do |
|
93 |
+ system "mulle-test" |
|
94 |
+ end |
|
95 |
+end |
|
96 |
+# FORMULA ${TARGET}.rb |
|
97 |
+EOF |
|
98 |
+} |
|
99 |
+ |
|
100 |
+ |
|
101 |
+# |
|
102 |
+# Boiler plate code from here on. Could put this into a convenient |
|
103 |
+# location somewhere (mulle-homebrew ?) |
|
104 |
+# From now on need: |
|
105 |
+# TAG |
|
106 |
+# HOMEBREWTAP |
|
107 |
+# RBFILE |
|
108 |
+# ORIGIN |
|
109 |
+get_header_version() |
|
110 |
+{ |
|
111 |
+ local filename |
|
112 |
+ |
|
113 |
+ filename="$1" |
|
114 |
+ fgrep "${VERSIONNAME}" "${filename}" | \ |
|
115 |
+ sed 's|(\([0-9]*\) \<\< [0-9]*)|\1|g' | \ |
|
116 |
+ sed 's|^.*(\(.*\))|\1|' | \ |
|
117 |
+ sed 's/ | /./g' |
|
118 |
+} |
|
119 |
+ |
|
120 |
+ |
|
121 |
+git_must_be_clean() |
|
122 |
+{ |
|
123 |
+ local name |
|
124 |
+ local clean |
|
125 |
+ |
|
126 |
+ name="${1:-${PWD}}" |
|
127 |
+ |
|
128 |
+ if [ ! -d .git ] |
|
129 |
+ then |
|
130 |
+ fail "\"${name}\" is not a git repository" |
|
131 |
+ fi |
|
132 |
+ |
|
133 |
+ clean=`git status -s --untracked-files=no` |
|
134 |
+ if [ "${clean}" != "" ] |
|
135 |
+ then |
|
136 |
+ fail "repository \"${name}\" is tainted" |
|
137 |
+ fi |
|
138 |
+} |
|
139 |
+ |
|
140 |
+ |
|
141 |
+# Parameters! |
|
142 |
+# |
|
143 |
+# ORIGIN |
|
144 |
+# TAG |
|
145 |
+# |
|
146 |
+git_main() |
|
147 |
+{ |
|
148 |
+ local origin |
|
149 |
+ local tag |
|
150 |
+ |
|
151 |
+ origin="$1" |
|
152 |
+ shift |
|
153 |
+ tag="$1" |
|
154 |
+ shift |
|
155 |
+ |
|
156 |
+ exekutor git_must_be_clean || exit 1 |
|
157 |
+ |
|
158 |
+ local branch |
|
159 |
+ |
|
160 |
+ branch="`exekutor git rev-parse --abbrev-ref HEAD`" |
|
161 |
+ |
|
162 |
+ # |
|
163 |
+ # make it a release |
|
164 |
+ # |
|
165 |
+ exekutor git checkout -B release || exit 1 |
|
166 |
+ exekutor git rebase "${branch}" || exit 1 |
|
167 |
+ |
|
168 |
+ # if rebase fails, we shouldn't be hitting tag now |
|
169 |
+ exekutor git tag "${tag}" || exit 1 |
|
170 |
+ |
|
171 |
+ exekutor git push "${origin}" release --tags || exit 1 |
|
172 |
+ exekutor git push github release --tags || exit 1 |
|
173 |
+ |
|
174 |
+ exekutor git checkout "${branch}" || exit 1 |
|
175 |
+ exekutor git push "${origin}" "${branch}" || exit 1 |
|
176 |
+} |
|
177 |
+ |
|
178 |
+ |
|
179 |
+# |
|
180 |
+# Expected environment! |
|
181 |
+# PROJECT |
|
182 |
+# NAME |
|
183 |
+# VERSION |
|
184 |
+# HOMEPAGE |
|
185 |
+# DESC |
|
186 |
+# DEPENDENCIES |
|
187 |
+# HOMEBREWTAP |
|
188 |
+# RBFILE |
|
189 |
+# |
|
190 |
+homebrew_main() |
|
191 |
+{ |
|
192 |
+ ARCHIVEURL="`eval echo "${ARCHIVEURL}"`" |
|
193 |
+ |
|
194 |
+ redirect_exekutor "${HOMEBREWTAP}/${RBFILE}" \ |
|
195 |
+ generate_brew_formula "${PROJECT}" \ |
|
196 |
+ "${NAME}" \ |
|
197 |
+ "${HOMEPAGE}" \ |
|
198 |
+ "${DESC}" \ |
|
199 |
+ "${VERSION}" \ |
|
200 |
+ "${ARCHIVEURL}" \ |
|
201 |
+ "${DEPENDENCIES}" || exit 1 |
|
202 |
+ ( |
|
203 |
+ exekutor cd "${HOMEBREWTAP}" ; |
|
204 |
+ exekutor git add "${RBFILE}" ; |
|
205 |
+ exekutor git commit -m "${VERSION} release of ${NAME}" "${RBFILE}" ; |
|
206 |
+ exekutor git push origin master |
|
207 |
+ ) || exit 1 |
|
208 |
+} |
|
209 |
+ |
|
210 |
+ |
|
211 |
+homebrew_initialize() |
|
212 |
+{ |
|
213 |
+ local directory |
|
214 |
+ |
|
215 |
+ if [ -z "${DEFAULT_IFS}" ] |
|
216 |
+ then |
|
217 |
+ DEFAULT_IFS="${IFS}" |
|
218 |
+ fi |
|
219 |
+ |
|
220 |
+ directory="`mulle-bootstrap library-path 2> /dev/null`" |
|
221 |
+ [ ! -d "${directory}" ] && echo "failed to locate mulle-bootstrap library" >&2 && exit 1 |
|
222 |
+ PATH="${directory}:$PATH" |
|
223 |
+ |
|
224 |
+ . "mulle-bootstrap-logging.sh" |
|
225 |
+ . "mulle-bootstrap-functions.sh" |
|
226 |
+ |
|
227 |
+ [ ! -d "${HOMEBREWTAP}" ] && fail "failed to locate \"${HOMEBREWTAP}\"" |
|
228 |
+} |
|
229 |
+ |
|
230 |
+homebrew_initialize |
|
231 |
+ |
... | ... |
@@ -1,79 +1,41 @@ |
1 |
-#! /bin/sh |
|
1 |
+#! /bin/sh -x |
|
2 | 2 |
|
3 |
+# |
|
4 |
+# These variables have to be configured on a by project basis |
|
5 |
+# |
|
3 | 6 |
NAME="mulle-vararg" # not the ruby name |
7 |
+DESC="Access variable arguments in struct layout fashion" |
|
8 |
+PROJECT=MulleVararg # ruby requires camel-case |
|
4 | 9 |
HEADER="src/mulle_vararg.h" |
5 | 10 |
VERSIONNAME="MULLE_VARARG_VERSION" |
6 | 11 |
ORIGIN=public |
12 |
+DEPENDENCIES= |
|
7 | 13 |
|
14 |
+HOMEPAGE="https://www.mulle-kybernetik.com/software/git/${NAME}" |
|
8 | 15 |
RBFILE="${NAME}.rb" |
9 | 16 |
HOMEBREWTAP="../homebrew-software" |
10 | 17 |
|
11 |
- |
|
12 |
-get_version() |
|
13 |
-{ |
|
14 |
- local filename |
|
15 |
- |
|
16 |
- filename="$1" |
|
17 |
- fgrep "${VERSIONNAME}" "${filename}" | \ |
|
18 |
- sed 's|(\([0-9]*\) \<\< [0-9]*)|\1|g' | \ |
|
19 |
- sed 's|^.*(\(.*\))|\1|' | \ |
|
20 |
- sed 's/ | /./g' |
|
21 |
-} |
|
22 |
- |
|
23 |
-VERSION="`get_version ${HEADER}`" |
|
24 |
-TAG="${1:-${VERSION}}" |
|
25 |
- |
|
26 |
- |
|
27 |
-directory="`mulle-bootstrap library-path 2> /dev/null`" |
|
28 |
-[ ! -d "${directory}" ] && echo "failed to locate mulle-bootstrap library" >&2 && exit 1 |
|
29 |
- |
|
30 |
-PATH="${directory}:$PATH" |
|
31 |
- |
|
32 |
-. "mulle-bootstrap-logging.sh" |
|
18 |
+# ARCHIVEURL will be evaled later! keep it in single quotes |
|
19 |
+ARCHIVEURL='https://www.mulle-kybernetik.com/software/git/${NAME}/tarball/${VERSION}' |
|
33 | 20 |
|
34 | 21 |
|
35 |
-git_must_be_clean() |
|
22 |
+main() |
|
36 | 23 |
{ |
37 |
- local name |
|
38 |
- local clean |
|
24 |
+ # source it |
|
25 |
+ . ./bin/mulle-homebrew/mulle-homebrew.sh |
|
39 | 26 |
|
40 |
- name="${1:-${PWD}}" |
|
27 |
+ local VERSION # upper case for consistency in eval |
|
28 |
+ local TAG |
|
41 | 29 |
|
42 |
- if [ ! -d .git ] |
|
43 |
- then |
|
44 |
- fail "\"${name}\" is not a git repository" |
|
45 |
- fi |
|
30 |
+ # |
|
31 |
+ # Version has to be figured out on a per project basis |
|
32 |
+ # get_header_version grabs the version from a header |
|
33 |
+ # |
|
34 |
+ VERSION="`get_header_version ${HEADER}`" |
|
35 |
+ TAG="${1:-${VERSION}}" |
|
46 | 36 |
|
47 |
- clean=`git status -s --untracked-files=no` |
|
48 |
- if [ "${clean}" != "" ] |
|
49 |
- then |
|
50 |
- fail "repository \"${name}\" is tainted" |
|
51 |
- fi |
|
37 |
+ git_main "${ORIGIN}" "${TAG}" || exit 1 |
|
38 |
+ homebrew_main || exit 1 |
|
52 | 39 |
} |
53 | 40 |
|
54 |
- |
|
55 |
-[ ! -d "${HOMEBREWTAP}" ] && fail "failed to locate \"${HOMEBREWTAP}\"" |
|
56 |
- |
|
57 |
-set -e |
|
58 |
- |
|
59 |
-git_must_be_clean |
|
60 |
- |
|
61 |
-branch="`git rev-parse --abbrev-ref HEAD`" |
|
62 |
- |
|
63 |
-git push "${ORIGIN}" "${branch}" |
|
64 |
- |
|
65 |
-# seperate step, as it's tedious to remove tag when |
|
66 |
-# previous push fails |
|
67 |
- |
|
68 |
-git tag "${TAG}" |
|
69 |
-git push "${ORIGIN}" "${branch}" --tags |
|
70 |
- |
|
71 |
-./bin/generate-brew-formula.sh "${VERSION}" > "${HOMEBREWTAP}/${RBFILE}" |
|
72 |
-( |
|
73 |
- cd "${HOMEBREWTAP}" ; |
|
74 |
- git add "${RBFILE}" ; |
|
75 |
- git commit -m "${TAG} release of ${NAME}" "${RBFILE}" ; |
|
76 |
- git push origin master |
|
77 |
-) |
|
78 |
- |
|
79 |
-git checkout "${branch}" |
|
41 |
+main "$@" |