]> git.ozlabs.org Git - petitboot/commitdiff
Make petitboot installable
authorJeremy Kerr <jk@ozlabs.org>
Mon, 2 Apr 2007 03:54:11 +0000 (13:54 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 2 Apr 2007 03:54:11 +0000 (13:54 +1000)
Add an install target and PREFIX= option the makefile, and change the
artwork loading code to use the prefixed-path.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Makefile
devices.c
devices/udev-helper.c
petitboot-paths.h [new file with mode: 0644]
petitboot.c

index 669e56a8210834994394dad86e7a41a0d318c03f..a9ae25c09fb65f187fdc6e5adeb5d1736ad41a3b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,14 @@
+PREFIX?=/usr
 CC=gcc
+INSTALL=install
 TWIN_CFLAGS=$(shell pkg-config --cflags libtwin)
 TWIN_LDFLAGS=$(shell pkg-config --libs libtwin)
 
 LDFLAGS = 
-CFLAGS = -O0 -ggdb -Wall
+CFLAGS = -O0 -ggdb -Wall '-DPREFIX="$(PREFIX)"'
 
 PARSERS = native
+ARTWORK = background.png cdrom.png hdd.png usbpen.png cursor
 
 all: petitboot udev-helper
 
@@ -19,6 +22,15 @@ udev-helper: devices/udev-helper.o devices/params.o \
                $(foreach p,$(PARSERS),devices/$(p)-parser.o)
        $(CC) $(LDFLAGS) -o $@ $^
 
+devices/%: CFLAGS+=-I.
+
+install: all
+       $(INSTALL) -D petitboot $(PREFIX)/sbin/petitboot
+       $(INSTALL) -D udev-helper $(PREFIX)/sbin/udev-helper
+       $(INSTALL) -Dd $(PREFIX)/share/petitboot/artwork/
+       $(INSTALL) -t $(PREFIX)/share/petitboot/artwork/ \
+               $(foreach a,$(ARTWORK),artwork/$(a))
+
 clean:
        rm -f petitboot
        rm -f udev-helper
index ac932871684e8ea3c6663727ecd7ff9ed4ab0fcf..28cb3a38e3828f328a8ee7434eb073ffb970379a 100644 (file)
--- a/devices.c
+++ b/devices.c
@@ -9,12 +9,12 @@
 
 #include <libtwin/twin_png.h>
 #include "petitboot.h"
+#include "petitboot-paths.h"
 #include "devices/message.h"
 
-#define PBOOT_DEVICE_SOCKET    "/var/tmp/petitboot-dev"
-#define PBOOT_DEFAULT_ICON     "artwork/usbpen.png"
+#define PBOOT_DEFAULT_ICON     "usbpen.png"
 
-static const char *default_icon = PBOOT_DEFAULT_ICON;
+static const char *default_icon = artwork_pathname(PBOOT_DEFAULT_ICON);
 
 struct discovery_context {
        /* nothing at present */
index f9360860e4c8955813a741fbd5444646bbb819ce..ade97872e3b075f20419b5667ea9a733e61e37c1 100644 (file)
 #include <asm/byteorder.h>
 
 #include "udev-helper.h"
-
-#define parser_dir "."
-
-#define tmp_dir "/var/tmp/petitboot"
-#define socket_file "/var/tmp/petitboot-dev"
-#define mount_bin "/bin/mount"
-#define umount_bin "/bin/umount"
+#include "petitboot-paths.h"
 
 extern struct parser native_parser;
 static FILE *logf;
@@ -205,7 +199,7 @@ int connect_to_socket()
        }
 
        addr.sun_family = AF_UNIX;
-       strcpy(addr.sun_path, socket_file);
+       strcpy(addr.sun_path, PBOOT_DEVICE_SOCKET);
 
        if (connect(fd, (struct sockaddr *)&addr, sizeof(addr))) {
                log("can't connect to %s: %s\n",
@@ -235,12 +229,12 @@ static int mount_device(const char *dev_path, char *mount_path)
        int pid, status, rc = -1;
 
        /* create a unique mountpoint */
-       dir = malloc(strlen(tmp_dir) + 2 + strlen(template));
-       sprintf(dir, "%s/%s", tmp_dir, template);
+       dir = malloc(strlen(TMP_DIR) + 2 + strlen(template));
+       sprintf(dir, "%s/%s", TMP_DIR, template);
 
        if (!mkdtemp(dir)) {
                log("failed to create temporary directory in %s: %s",
-                               tmp_dir, strerror(errno));
+                               TMP_DIR, strerror(errno));
                goto out;
        }
 
@@ -251,7 +245,7 @@ static int mount_device(const char *dev_path, char *mount_path)
        }
 
        if (pid == 0) {
-               execl(mount_bin, mount_bin, dev_path, dir, "-o", "ro", NULL);
+               execl(MOUNT_BIN, MOUNT_BIN, dev_path, dir, "-o", "ro", NULL);
                exit(EXIT_FAILURE);
        }
 
@@ -282,7 +276,7 @@ static int unmount_device(const char *dev_path)
        }
 
        if (pid == 0) {
-               execl(umount_bin, umount_bin, dev_path, NULL);
+               execl(UMOUNT_BIN, UMOUNT_BIN, dev_path, NULL);
                exit(EXIT_FAILURE);
        }
 
@@ -300,16 +294,16 @@ const char *generic_icon_file(enum generic_icon_type type)
 {
        switch (type) {
        case ICON_TYPE_DISK:
-               return "artwork/hdd.png";
+               return artwork_pathname("hdd.png");
        case ICON_TYPE_USB:
-               return "artwork/usbpen.png";
+               return artwork_pathname("usbpen.png");
        case ICON_TYPE_OPTICAL:
-               return "artwork/cdrom.png";
+               return artwork_pathname("cdrom.png");
        case ICON_TYPE_NETWORK:
        case ICON_TYPE_UNKNOWN:
                break;
        }
-       return "artwork/hdd.png";
+       return artwork_pathname("hdd.png");
 }
 
 static const struct device fake_boot_devices[] =
@@ -317,12 +311,12 @@ static const struct device fake_boot_devices[] =
        {
                .id             = "fakeDisk0",
                .name           = "Hard Disk",
-               .icon_file      = "artwork/hdd.png",
+               .icon_file      = artwork_pathname("hdd.png"),
        },
        {
                .id             = "fakeDisk1",
                .name           = "PinkCat Linux CD",
-               .icon_file      = "artwork/cdrom.png",
+               .icon_file      = artwork_pathname("cdrom.png"),
        }
 };
 
@@ -332,25 +326,25 @@ static const struct boot_option fake_boot_options[] =
                .id             = "fakeBoot0",
                .name           = "Bloobuntu Linux",
                .description    = "Boot Bloobuntu Linux",
-               .icon_file      = "artwork/hdd.png",
+               .icon_file      = artwork_pathname("hdd.png"),
        },
        {
                .id             = "fakeBoot1",
                .name           = "Pendora Gore 6",
                .description    = "Boot Pendora Gora 6",
-               .icon_file      = "artwork/hdd.png",
+               .icon_file      = artwork_pathname("hdd.png"),
        },
        {
                .id             = "fakeBoot2",
                .name           = "Genfoo Minux",
                .description    = "Boot Genfoo Minux",
-               .icon_file      = "artwork/hdd.png",
+               .icon_file      = artwork_pathname("hdd.png"),
        },
        {
                .id             = "fakeBoot3",
                .name           = "PinkCat Linux",
                .description    = "Install PinkCat Linux - Graphical install",
-               .icon_file      = "artwork/cdrom.png",
+               .icon_file      = artwork_pathname("cdrom.png"),
        },
 };
 
diff --git a/petitboot-paths.h b/petitboot-paths.h
new file mode 100644 (file)
index 0000000..114d0b2
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef _PATHS_H
+#define _PATHS_H
+
+#ifndef PREFIX
+#define PREFIX "/usr"
+#endif
+
+#ifndef PKG_SHARE_DIR
+#define PKG_SHARE_DIR PREFIX "/share/petitboot"
+#endif
+
+#ifndef TMP_DIR
+#define TMP_DIR "/var/tmp"
+#endif
+
+#define PBOOT_DEVICE_SOCKET "/var/tmp/petitboot-dev"
+#define MOUNT_BIN "/bin/mount"
+#define UMOUNT_BIN "/bin/umount"
+
+/* at present, all default artwork strings are const. */
+#define artwork_pathname(s) (PKG_SHARE_DIR "/artwork/" s)
+
+#endif /* _PATHS_H */
index e69353e6b4dbc0bd70300d6d70507a5fd87749f0..44e1cc87b394755b0cdc745725e07916a6f028be 100644 (file)
@@ -14,6 +14,7 @@
 #include <libtwin/twin_png.h>
 
 #include "petitboot.h"
+#include "petitboot-paths.h"
 
 #define _USE_X11
 
@@ -845,6 +846,7 @@ static void sigint(int sig)
 int main(int argc, char **argv)
 {
        twin_pixmap_t *pic;
+       const char *background_path;
 
        atexit(exitfunc);
        signal(SIGINT, sigint);
@@ -868,7 +870,8 @@ int main(int argc, char **argv)
 #endif
 
        if (pboot_fbdev != NULL) {
-               pboot_cursor = twin_load_X_cursor("artwork/cursor", 2,
+               char *cursor_path = artwork_pathname("cursor");
+               pboot_cursor = twin_load_X_cursor(cursor_path, 2,
                                                  &pboot_cursor_hx,
                                                  &pboot_cursor_hy);
                if (pboot_cursor == NULL)
@@ -878,8 +881,9 @@ int main(int argc, char **argv)
        }
 
        /* Set background pixmap */
-       LOG("loading background...");
-       pic = twin_png_to_pixmap("artwork/background.png", TWIN_ARGB32);
+       background_path = artwork_pathname("background.png");
+       LOG("loading background: %s...", background_path);
+       pic = twin_png_to_pixmap(background_path, TWIN_ARGB32);
        LOG("%s\n", pic ? "ok" : "failed");
        if (pic)
                twin_screen_set_background(pboot_screen, pic);