diff --git a/bin/ar.cc b/bin/ar.cc index 898f7aa..d6d3950 100644 --- a/bin/ar.cc +++ b/bin/ar.cc @@ -46,6 +46,7 @@ #include #include #include /* retmem_mb() */ +#include struct ranlib { union { diff --git a/bin/doname.cc b/bin/doname.cc index 85be203..9073de1 100644 --- a/bin/doname.cc +++ b/bin/doname.cc @@ -43,13 +43,18 @@ #include #include #include +#if defined(sun) || defined(__sun) +// XXX really needed, even on Solaris? #include +#else +#endif #include #include #include #include /* uname() */ #include #include /* close() */ +#include /* * Defined macros diff --git a/bin/main.cc b/bin/main.cc index ed0afc0..e5aef91 100644 --- a/bin/main.cc +++ b/bin/main.cc @@ -48,14 +48,23 @@ #include /* ENOENT */ #include /* fstat() */ #include /* open() */ +#include +#if defined(sun) || defined(__sun) # include /* sysinfo() */ +#else +#include +#endif #include /* stat() */ #include /* wait() */ #include /* execv(), unlink(), access() */ #include /* report_dependency(), get_report_file() */ +#include // gettext() + +#include + // From read2.cc extern Name normalize_name(register wchar_t *name_string, register int length); @@ -69,7 +78,7 @@ extern void job_adjust_fini(); #define LD_SUPPORT_ENV_VAR_32 "SGS_SUPPORT_32" #define LD_SUPPORT_ENV_VAR_64 "SGS_SUPPORT_64" #define LD_SUPPORT_MAKE_LIB "libmakestate.so.1" -#ifdef __i386 +#if defined(__i386) || defined(__x86_64__) #define LD_SUPPORT_MAKE_ARCH "i386" #elif __sparc #define LD_SUPPORT_MAKE_ARCH "sparc" @@ -197,7 +206,11 @@ main(int argc, char *argv[]) struct stat out_stat, err_stat; hostid = gethostid(); +#if defined(sun) || defined(__sun) bsd_signals(); +#else +// XXX necessary on linux? +#endif (void) setlocale(LC_ALL, ""); @@ -475,7 +488,11 @@ main(int argc, char *argv[]) /* * Enable interrupt handler for alarms */ +#if defined(sun) || defined(__sun) (void) bsd_signal(SIGALRM, (SIG_PF)doalarm); +#else + (void) bsd_signal(SIGALRM, doalarm); +#endif /* * Check if make should report @@ -1596,7 +1613,13 @@ make_install_prefix(void) char origin[PATH_MAX]; char *dir; - if ((ret = readlink("/proc/self/path/a.out", origin, + if ((ret = readlink( +#if defined(sun) || defined(__sun) + "/proc/self/path/a.out", +#else + "/proc/self/exe", +#endif + origin, PATH_MAX - 1)) < 0) fatal("failed to read origin from /proc\n"); diff --git a/bin/misc.cc b/bin/misc.cc index 25bad0a..05fee12 100644 --- a/bin/misc.cc +++ b/bin/misc.cc @@ -46,6 +46,10 @@ #include /* va_list, va_start(), va_end() */ #include /* SUNPRO_DEPENDENCIES */ #include +#include +#include + +#include extern void job_adjust_fini(); diff --git a/bin/parallel.cc b/bin/parallel.cc index c7712df..a7ffd00 100644 --- a/bin/parallel.cc +++ b/bin/parallel.cc @@ -46,8 +46,11 @@ #include #include #include +#include + #include +#include /* @@ -252,7 +255,12 @@ execute_parallel(Property line, Boolean waitflg, Boolean local) #include /* ftok() */ #include /* shmget(), shmat(), shmdt(), shmctl() */ #include /* sem_init(), sem_trywait(), sem_post(), sem_destroy() */ +#if defined(sun) || defined(__sun) #include /* getloadavg() */ +#else +#include // getloadavg() +#define LOADAVG_1MIN 0 +#endif /* * adjust_pmake_max_jobs (int pmake_max_jobs) diff --git a/bin/read.cc b/bin/read.cc index 0d47f5b..3cb3d3e 100644 --- a/bin/read.cc +++ b/bin/read.cc @@ -43,6 +43,7 @@ #include /* read(), unlink() */ #include +#include /* * typedefs & structs diff --git a/bin/read2.cc b/bin/read2.cc index 50324de..2abab50 100644 --- a/bin/read2.cc +++ b/bin/read2.cc @@ -39,6 +39,8 @@ #include /* va_list, va_start(), va_end() */ #include +#include + /* * Defined macros */ diff --git a/bin/state.cc b/bin/state.cc index 57a0150..955fb7d 100644 --- a/bin/state.cc +++ b/bin/state.cc @@ -39,6 +39,11 @@ #include /* errno */ #include /* MB_CUR_MAX */ +#if defined(sun) || defined(__sun) +#else +#include // gettext() +#endif + /* * Defined macros */ diff --git a/include/bsd/bsd.h b/include/bsd/bsd.h index 2893d62..fdba250 100644 --- a/include/bsd/bsd.h +++ b/include/bsd/bsd.h @@ -32,6 +32,7 @@ #include +#if defined(sun) || defined(__sun) #ifndef __cplusplus typedef void (*SIG_PF) (int); @@ -45,3 +46,5 @@ extern void (*bsd_signal(int, void (*) (int))) (int); extern void bsd_signals(void); #endif + +#endif diff --git a/include/mk/defs.h b/include/mk/defs.h index 5f5beab..a929e03 100644 --- a/include/mk/defs.h +++ b/include/mk/defs.h @@ -294,7 +294,11 @@ extern long int hostid; * Declarations of system defined variables */ /* On linux this variable is defined in 'signal.h' */ +#if defined(sun) || defined(__sun) extern char *sys_siglist[]; +#else +#include +#endif /* * Declarations of system supplied functions @@ -353,7 +357,9 @@ extern wchar_t *getmem_wc(register int size); #ifdef __cplusplus extern "C" { #endif +#if defined(sun) || defined(__sun) extern char *getwd(char *); +#endif #ifdef __cplusplus } #endif diff --git a/include/mksh/defs.h b/include/mksh/defs.h index 9ad58c4..4c13783 100644 --- a/include/mksh/defs.h +++ b/include/mksh/defs.h @@ -36,6 +36,9 @@ #include /* errno */ #include +#include + +#include /* * A type and some utilities for boolean values @@ -861,7 +864,12 @@ extern Boolean do_not_exec_rule; /* `-n' */ extern Boolean dollarget_seen; extern Boolean dollarless_flag; extern Name dollarless_value; +// On Linux, environ is declared with C linkage in unistd.h +// if _GNU_SOURCE is defined. Declaring it with C linkage here +// should also be fine under Solaris. +extern "C" { extern char **environ; +} extern Envvar envvar; extern int exit_status; extern wchar_t *file_being_read; diff --git a/lib/mksh/dosys.cc b/lib/mksh/dosys.cc index 5ff0ab7..7c30a28 100644 --- a/lib/mksh/dosys.cc +++ b/lib/mksh/dosys.cc @@ -93,7 +93,13 @@ redirect_io(char *stdout_file, char *stderr_file) { int i; +#if defined(sun) || defined(__sun) (void) closefrom(3); +#else + // XXX not available on Linux + // if necessary, could provide a compatibility function that + // iterates over /proc/$(getpid())/fd ... +#endif if ((i = my_open(stdout_file, O_WRONLY | O_CREAT | O_TRUNC | O_DSYNC, S_IREAD | S_IWRITE)) < 0) { diff --git a/lib/mksh/misc.cc b/lib/mksh/misc.cc index 4765102..db2cf29 100644 --- a/lib/mksh/misc.cc +++ b/lib/mksh/misc.cc @@ -49,6 +49,7 @@ #include /* wait() */ #include /* strerror() */ +#include #include @@ -271,16 +272,33 @@ void enable_interrupt(register void (*handler) (int)) { if (sigivalue != SIG_IGN) { +#if defined(sun) || defined(__sun) (void) bsd_signal(SIGINT, (SIG_PF) handler); +#else + (void) bsd_signal(SIGINT, handler); +#endif } if (sigqvalue != SIG_IGN) { +#if defined(sun) || defined(__sun) (void) bsd_signal(SIGQUIT, (SIG_PF) handler); +#else + (void) bsd_signal(SIGQUIT, handler); +#endif } if (sigtvalue != SIG_IGN) { +#if defined(sun) || defined(__sun) (void) bsd_signal(SIGTERM, (SIG_PF) handler); +#else + (void) bsd_signal(SIGTERM, handler); +#endif } if (sighvalue != SIG_IGN) { +#if defined(sun) || defined(__sun) (void) bsd_signal(SIGHUP, (SIG_PF) handler); +#else + (void) bsd_signal(SIGHUP, handler); +#endif + } } diff --git a/lib/vroot/lock.cc b/lib/vroot/lock.cc index d3389ce..d31cb5e 100644 --- a/lib/vroot/lock.cc +++ b/lib/vroot/lock.cc @@ -36,10 +36,12 @@ #include /* errno */ #include +#if defined(sun) || defined(__sun) extern char *sys_errlist[]; extern int sys_nerr; +#endif -static void file_lock_error(char *msg, char *file, char *str, int arg1, int arg2); +static void file_lock_error(char *msg, char *file, char *str, const char *arg1, const char *arg2); #define BLOCK_INTERUPTS sigfillset(&newset) ; \ sigprocmask(SIG_SETMASK, &newset, &oldset) @@ -109,7 +111,7 @@ file_lock(char *name, char *lockname, int *file_locked, int timeout) if (errno != EEXIST) { file_lock_error(msg, name, (char *)"symlink(%s, %s)", - (int) name, (int) lockname); + name, lockname); fprintf(stderr, "%s", msg); return errno; } @@ -157,7 +159,7 @@ file_lock(char *name, char *lockname, int *file_locked, int timeout) * Format a message telling why the lock could not be created. */ static void -file_lock_error(char *msg, char *file, char *str, int arg1, int arg2) +file_lock_error(char *msg, char *file, char *str, const char *arg1, const char *arg2) { int len;