Build external dependencies local to tree

This commit is contained in:
Peter Johnson
2018-12-03 00:04:18 -08:00
parent 4632d11a1e
commit 1768bdaa4c
13 changed files with 238 additions and 104 deletions
+21
View File
@@ -0,0 +1,21 @@
COMPILER=../02-extract/raspbian9/bin/arm-raspbian9-linux-gnueabihf-
ALL: setuidgids _cscore.so
setuidgids: setuidgids.c
${COMPILER}gcc -O -Wall -D_GNU_SOURCE -o $@ $<
_cscore.so: ../robotpy-cscore/src/_cscore.cpp ../robotpy-cscore/src/ndarray_converter.cpp
${COMPILER}g++ -O -Wall -fvisibility=hidden -shared -fPIC -o $@ \
-I../03-build/opencv-build/install/include \
-I../allwpilib/wpiutil/src/main/native/include \
-I../allwpilib/cscore/src/main/native/include \
-I../02-extract/raspbian9/arm-raspbian9-linux-gnueabihf/usr/include/python3.5 \
-L../allwpilib/cscore/build/libs/cscore/shared/release \
-L../allwpilib/wpiutil/build/libs/wpiutil/shared/release \
-L../03-build/opencv-build/install/lib \
../robotpy-cscore/src/_cscore.cpp \
../robotpy-cscore/src/ndarray_converter.cpp \
-lcscore \
-lwpiutil \
-lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core
+47
View File
@@ -0,0 +1,47 @@
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
static int prot_gid(gid_t gid)
{
if (setgroups(1,&gid) == -1) return -1;
return setgid(gid); /* _should_ be redundant, but on some systems it isn't */
}
const char *account;
struct passwd *pw;
int main(int argc, char **argv, char **envp)
{
account = *++argv;
if (!account || !*++argv) {
fprintf(stderr, "setuidgids: usage: setuidgids account child");
exit(EXIT_FAILURE);
}
pw = getpwnam(account);
if (!pw) {
fprintf(stderr, "setuidgids: FATAL: unknown account %s", account);
return EXIT_FAILURE;
}
if (prot_gid(pw->pw_gid) == -1) {
fprintf(stderr, "setuidgids: FATAL: unable to setgid\n");
return EXIT_FAILURE;
}
if (initgroups(pw->pw_name, pw->pw_gid) == -1) {
fprintf(stderr, "setuidgids: FATAL: unable to initgroups\n");
return EXIT_FAILURE;
}
if (setuid(pw->pw_uid) == -1) {
fprintf(stderr, "setuidgids: FATAL: unable to setuid\n");
return EXIT_FAILURE;
}
execvpe(*argv,argv,envp);
fprintf(stderr, "setuidgids: FATAL: unable to run %s\n", *argv);
return EXIT_FAILURE;
}