Add basic Makefile

ifdef for mount flags which Ubuntu does not expose in sys/mount.h

ifdef around Android's Background/Foreground scheduling support.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..07c8652
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,92 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+TOOLS := \
+	ls \
+	mount \
+	cat \
+	ps \
+	kill \
+	ln \
+	insmod \
+	rmmod \
+	lsmod \
+	ifconfig \
+	setconsole \
+	rm \
+	mkdir \
+	rmdir \
+	reboot \
+	getevent \
+	sendevent \
+	date \
+	wipe \
+	sync \
+	umount \
+	start \
+	stop \
+	notify \
+	cmp \
+	dmesg \
+	route \
+	hd \
+	dd \
+	df \
+	getprop \
+	setprop \
+	watchprops \
+	log \
+	sleep \
+	renice \
+	printenv \
+	smd \
+	chmod \
+	chown \
+	newfs_msdos \
+	netstat \
+	ioctl \
+	mv \
+	schedtop \
+	top \
+	iftop \
+	id \
+	uptime \
+	vmstat \
+	nandread \
+	ionice \
+	lsof
+
+LOCAL_SRC_FILES:= \
+	toolbox.c \
+	$(patsubst %,%.c,$(TOOLS))
+
+LOCAL_MODULE:= toolbox
+
+all: ${LOCAL_MODULE}
+
+CC ?= gcc
+
+# Directory where object files should be placed
+TARGET_OUT ?= .
+
+TOOLS_H := ${TARGET_OUT}/tools.h
+$(TOOLS_H):
+	echo "/* file generated automatically */" > $@ ; for t in $(PRIVATE_TOOLS) ; do echo "TOOL($$t)" >> $@ ; done
+
+$(TARGET_OUT)/%.o: %.c
+	$(CC) $(DEFINES) -I${TARGET_OUT} -c -o $@ $<
+
+OBJFILES := $(patsubst %.c,$(TARGET_OUT)/%.o,$(LOCAL_SRC_FILES))
+
+toolbox: $(OBJFILES)
+	$(CC) -o $(TARGET_OUT)/$(TARGET) $(OBJFILES) $(LIBRARIES)
+
+# Make #!/system/bin/toolbox launchers for each tool.
+#
+SYMLINKS := $(addprefix $(TARGET_OUT)/bin/,$(TOOLS))
+$(SYMLINKS): TOOLBOX_BINARY := $(LOCAL_MODULE)
+$(SYMLINKS):
+	@echo "Symlink: $@ -> $(TOOLBOX_BINARY)"
+	@mkdir -p $(dir $@)
+	@rm -rf $@
+	$(hide) ln -sf $(TOOLBOX_BINARY) $@
diff --git a/mount.c b/mount.c
index 472c952..6c52cc1 100644
--- a/mount.c
+++ b/mount.c
@@ -35,7 +35,11 @@
 /*
  * These options define the function of "mount(2)".
  */
+#ifdef MS_MOVE
 #define MS_TYPE	(MS_REMOUNT|MS_BIND|MS_MOVE)
+#else
+#define MS_TYPE	(MS_REMOUNT|MS_BIND)
+#endif
 
 
 static const struct mount_opts options[] = {
@@ -45,16 +49,24 @@
 	{ "bind",	MS_TYPE,	MS_BIND,	0,		},
 	{ "dev",	MS_NODEV,	0,		MS_NODEV	},
 	{ "diratime",	MS_NODIRATIME,	0,		MS_NODIRATIME	},
+#ifdef MS_DIRSYNC
 	{ "dirsync",	MS_DIRSYNC,	MS_DIRSYNC,	0		},
+#endif
 	{ "exec",	MS_NOEXEC,	0,		MS_NOEXEC	},
+#ifdef MS_MOVE
 	{ "move",	MS_TYPE,	MS_MOVE,	0		},
+#endif
+#ifdef MS_REC
 	{ "recurse",	MS_REC,		MS_REC,		0		},
+#endif
 	{ "remount",	MS_TYPE,	MS_REMOUNT,	0		},
 	{ "ro",		MS_RDONLY,	MS_RDONLY,	0		},
 	{ "rw",		MS_RDONLY,	0,		MS_RDONLY	},
 	{ "suid",	MS_NOSUID,	0,		MS_NOSUID	},
 	{ "sync",	MS_SYNCHRONOUS,	MS_SYNCHRONOUS,	0		},
+#ifdef MS_VERBOSE
 	{ "verbose",	MS_VERBOSE,	MS_VERBOSE,	0		},
+#endif
 };
 
 static void add_extra_option(struct extra_opts *extra, char *s)
@@ -229,7 +241,11 @@
 	int loop = 0;
 
 	progname = argv[0];
+#ifdef MS_VERBOSE
 	rwflag = MS_VERBOSE;
+#else
+	rwflag = 0;
+#endif
 	
 	// mount with no arguments is equivalent to "cat /proc/mounts"
 	if (argc == 1) return print_mounts();
diff --git a/ps.c b/ps.c
index bc50cfa..c7dea95 100644
--- a/ps.c
+++ b/ps.c
@@ -11,7 +11,9 @@
 
 #include <pwd.h>
 
+#ifdef HAS_SCHED_POLICY
 #include <cutils/sched_policy.h>
+#endif
 
 
 static char *nexttoksep(char **strp, char *sep)
@@ -26,7 +28,9 @@
 
 #define SHOW_PRIO 1
 #define SHOW_TIME 2
+#ifdef HAS_SCHED_POLICY
 #define SHOW_POLICY 4
+#endif
 
 static int display_flags = 0;
 
@@ -144,6 +148,7 @@
         printf("%-9s %-5d %-5d %-6d %-5d", user, pid, ppid, vss / 1024, rss * 4);
         if(display_flags&SHOW_PRIO)
             printf(" %-5d %-5d %-5d %-5d", prio, nice, rtprio, sched);
+#ifdef HAS_SCHED_POLICY
         if (display_flags & SHOW_POLICY) {
             SchedPolicy p;
             if (get_sched_policy(pid, &p) < 0)
@@ -157,6 +162,7 @@
                     printf(" er ");
             }
         }
+#endif
         printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name);
         if(display_flags&SHOW_TIME)
             printf(" (u:%d, s:%d)", utime, stime);
@@ -203,8 +209,10 @@
             threads = 1;
         } else if(!strcmp(argv[1],"-x")) {
             display_flags |= SHOW_TIME;
+#ifdef HAS_SCHED_POLICY
         } else if(!strcmp(argv[1],"-P")) {
             display_flags |= SHOW_POLICY;
+#endif
         } else if(!strcmp(argv[1],"-p")) {
             display_flags |= SHOW_PRIO;
         }  else if(isdigit(argv[1][0])){
@@ -218,7 +226,13 @@
 
     printf("USER     PID   PPID  VSIZE  RSS   %s %s WCHAN    PC         NAME\n", 
            (display_flags&SHOW_PRIO)?"PRIO  NICE  RTPRI SCHED ":"",
-           (display_flags&SHOW_POLICY)?"PCY " : "");
+#ifdef HAS_SCHED_POLICY
+           (display_flags&SHOW_POLICY)?"PCY " : ""
+#else
+           ""
+#endif
+    );
+
     while((de = readdir(d)) != 0){
         if(isdigit(de->d_name[0])){
             int pid = atoi(de->d_name);
@@ -231,4 +245,3 @@
     closedir(d);
     return 0;
 }
-