From 8e45f63780786743decf62eff5f0bd1c449d3618 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Tue, 25 Oct 2011 23:03:37 +0200
Status: sent
Debbug: 646778
Subject: [PATCH] Enable portability beyond i386 and amd64

---
 app/Makefile    |   26 +-------------------------
 debian/control  |    4 ++--
 src/Makefile    |   30 +-----------------------------
 src/channel.cpp |    4 ++--
 src/common.cpp  |   14 +++++++-------
 src/epoll.cpp   |   12 ++++++------
 6 files changed, 19 insertions(+), 71 deletions(-)

diff --git a/app/Makefile b/app/Makefile
index 9d16c0f..8ae1fa4 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -1,30 +1,6 @@
 C++ = g++
 
-ifndef os
-   os = LINUX
-endif
-
-ifndef arch
-   arch = IA32
-endif
-
-CCFLAGS = -Wall -D$(os) -I../src -finline-functions -O3
-
-ifeq ($(arch), IA32)
-   CCFLAGS += -DIA32 #-mcpu=pentiumpro -march=pentiumpro -mmmx -msse
-endif
-
-ifeq ($(arch), POWERPC)
-   CCFLAGS += -mcpu=powerpc
-endif
-
-ifeq ($(arch), IA64)
-   CCFLAGS += -DIA64
-endif
-
-ifeq ($(arch), SPARC)
-   CCFLAGS += -DSPARC
-endif
+CCFLAGS = -Wall -I../src -finline-functions -O3
 
 LDFLAGS = -L../src -ludt -lstdc++ -lpthread -lm
 
diff --git a/debian/control b/debian/control
index dd7ffd4..bb92d82 100644
--- a/debian/control
+++ b/debian/control
@@ -10,7 +10,7 @@ Vcs-Browser: http://git.debian.org/?p=collab-maint/udt.git;a=summary
 
 Package: libudt-dev
 Section: libdevel
-Architecture: i386 amd64
+Architecture: any
 Depends: libudt0 (= ${binary:Version}), ${misc:Depends}
 Description: UDP-based Data Transfer Protocol - development files
  UDT is a reliable UDP based application level data transport protocol for
@@ -24,7 +24,7 @@ Description: UDP-based Data Transfer Protocol - development files
  UDP-based data transfer protocol library.
 
 Package: libudt0
-Architecture: i386 amd64
+Architecture: any
 Depends: ${shlibs:Depends}, ${misc:Depends}
 Description: UDP-based Data Transfer Protocol
  UDT is a reliable UDP based application level data transport protocol for
diff --git a/src/Makefile b/src/Makefile
index 0f5505d..d9d905f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,34 +1,6 @@
 C++ = g++ 
 
-ifndef os
-   os = LINUX
-endif
-
-ifndef arch
-   arch = IA32
-endif
-
-CCFLAGS = -fPIC -Wall -Wextra -D$(os) -finline-functions -O3 -fno-strict-aliasing #-msse3
-
-ifeq ($(arch), IA32)
-   CCFLAGS += -DIA32
-endif
-
-ifeq ($(arch), POWERPC)
-   CCFLAGS += -mcpu=powerpc
-endif
-
-ifeq ($(arch), SPARC)
-   CCFLAGS += -DSPARC
-endif
-
-ifeq ($(arch), IA64)
-   CCFLAGS += -DIA64
-endif
-
-ifeq ($(arch), AMD64)
-   CCFLAGS += -DAMD64
-endif
+CCFLAGS = -fPIC -Wall -Wextra -finline-functions -O3 -fno-strict-aliasing #-msse3
 
 OBJS = md5.o common.o window.o list.o buffer.o packet.o channel.o queue.o ccc.o cache.o core.o epoll.o api.o
 DIR = $(shell pwd)
diff --git a/src/channel.cpp b/src/channel.cpp
index 59c937f..b9c00b5 100644
--- a/src/channel.cpp
+++ b/src/channel.cpp
@@ -164,7 +164,7 @@ void CChannel::setUDPSockOpt()
       tv.tv_usec = 100;
    #endif
 
-   #ifdef UNIX
+   #ifdef __unix__
       // Set non-blocking I/O
       // UNIX does not support SO_RCVTIMEO
       int opts = fcntl(m_iSocket, F_GETFL);
@@ -298,7 +298,7 @@ int CChannel::recvfrom(sockaddr* addr, CPacket& packet) const
       mh.msg_controllen = 0;
       mh.msg_flags = 0;
 
-      #ifdef UNIX
+      #ifdef __unix__
          fd_set set;
          timeval tv;
          FD_ZERO(&set);
diff --git a/src/common.cpp b/src/common.cpp
index 661ad33..2381042 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -100,7 +100,7 @@ void CTimer::rdtsc(uint64_t &x)
       if (!ret)
          x = getTime() * s_ullCPUFrequency;
 
-   #elif IA32
+   #elif defined(__i386__)
       uint32_t lval, hval;
       //asm volatile ("push %eax; push %ebx; push %ecx; push %edx");
       //asm volatile ("xor %eax, %eax; cpuid");
@@ -108,9 +108,9 @@ void CTimer::rdtsc(uint64_t &x)
       //asm volatile ("pop %edx; pop %ecx; pop %ebx; pop %eax");
       x = hval;
       x = (x << 32) | lval;
-   #elif IA64
+   #elif defined(__ia64__)
       asm ("mov %0=ar.itc" : "=r"(x) :: "memory");
-   #elif AMD64
+   #elif defined(__amd64__)
       uint32_t lval, hval;
       asm ("rdtsc" : "=a" (lval), "=d" (hval));
       x = hval;
@@ -131,7 +131,7 @@ uint64_t CTimer::readCPUFrequency()
          return ccf / 1000000;
       else
          return 1;
-   #elif IA32 || IA64 || AMD64
+   #elif defined(__unix__)
       uint64_t t1, t2;
 
       rdtsc(t1);
@@ -173,11 +173,11 @@ void CTimer::sleepto(const uint64_t& nexttime)
    while (t < m_ullSchedTime)
    {
       #ifndef NO_BUSY_WAITING
-         #ifdef IA32
+         #if defined(__i386__)
             __asm__ volatile ("pause; rep; nop; nop; nop; nop; nop;");
-         #elif IA64
+         #elif defined(__ia64__)
             __asm__ volatile ("nop 0; nop 0; nop 0; nop 0; nop 0;");
-         #elif AMD64
+         #elif defined(__amd64__)
             __asm__ volatile ("nop; nop; nop; nop; nop;");
          #endif
       #else
diff --git a/src/epoll.cpp b/src/epoll.cpp
index 31ac698..bf14d32 100644
--- a/src/epoll.cpp
+++ b/src/epoll.cpp
@@ -38,7 +38,7 @@ written by
    Yunhong Gu, last updated 01/01/2011
 *****************************************************************************/
 
-#ifdef LINUX
+#ifdef __linux__
    #include <sys/epoll.h>
    #include <unistd.h>
 #endif
@@ -70,7 +70,7 @@ int CEPoll::create()
 
    int localid = 0;
 
-   #ifdef LINUX
+   #ifdef __linux__
    localid = epoll_create(1024);
    if (localid < 0)
       throw CUDTException(-1, 0, errno);
@@ -112,7 +112,7 @@ int CEPoll::add_ssock(const int eid, const SYSSOCKET& s, const int* events)
    if (p == m_mPolls.end())
       throw CUDTException(5, 13);
 
-#ifdef LINUX
+#ifdef __linux__
    epoll_event ev;
 
    if (NULL == events)
@@ -162,7 +162,7 @@ int CEPoll::remove_ssock(const int eid, const SYSSOCKET& s, const int* events)
    if (p == m_mPolls.end())
       throw CUDTException(5, 13);
 
-#ifdef LINUX
+#ifdef __linux__
    epoll_event ev;
 
    if (NULL == events)
@@ -234,7 +234,7 @@ int CEPoll::wait(const int eid, set<UDTSOCKET>* readfds, set<UDTSOCKET>* writefd
          if (lwfds)
             lwfds->clear();
 
-         #ifdef LINUX
+         #ifdef __linux__
          const int max_events = p->second.m_sLocals.size();
          epoll_event ev[max_events];
          int nfds = epoll_wait(p->second.m_iLocalID, ev, max_events, 0);
@@ -324,7 +324,7 @@ int CEPoll::release(const int eid)
    if (i == m_mPolls.end())
       throw CUDTException(5, 13);
 
-   #ifdef LINUX
+   #ifdef __linux__
    // release local/system epoll descriptor
    ::close(i->second.m_iLocalID);
    #endif
-- 
1.7.7.1

