diff --git a/Makefile b/Makefile index 9560766..c317592 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ endif ifeq ($(UNAME), Darwin) # TODO: Putting GCC in C11 mode breaks things. CFLAGS+=-std=c11 +COMPAT+=compat/clock_gettime/clock_gettime.o compat/clock_nanosleep/clock_nanosleep.o endif all: dump1090 view1090 @@ -37,13 +38,13 @@ all: dump1090 view1090 dump1090.o: CFLAGS += `pkg-config --cflags librtlsdr` -dump1090: dump1090.o anet.o compat/clock_gettime/clock_gettime.o compat/clock_nanosleep/clock_nanosleep.o interactive.o mode_ac.o mode_s.o net_io.o crc.o demod_2000.o demod_2400.o stats.o cpr.o icao_filter.o track.o util.o convert.o +dump1090: dump1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o crc.o demod_2000.o demod_2400.o stats.o cpr.o icao_filter.o track.o util.o convert.o $(COMPAT) $(CC) -g -o $@ $^ $(LIBS) $(LIBS_RTL) $(LDFLAGS) -view1090: view1090.o anet.o compat/clock_gettime/clock_gettime.o interactive.o mode_ac.o mode_s.o net_io.o crc.o stats.o cpr.o icao_filter.o track.o util.o +view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o crc.o stats.o cpr.o icao_filter.o track.o util.o $(COMPAT) $(CC) -g -o $@ $^ $(LIBS) $(LDFLAGS) -faup1090: faup1090.o anet.o compat/clock_gettime/clock_gettime.o mode_ac.o mode_s.o net_io.o crc.o stats.o cpr.o icao_filter.o track.o util.o +faup1090: faup1090.o anet.o mode_ac.o mode_s.o net_io.o crc.o stats.o cpr.o icao_filter.o track.o util.o $(COMPAT) $(CC) -g -o $@ $^ $(LIBS) $(LDFLAGS) clean: diff --git a/compat/clock_gettime/README b/compat/clock_gettime/README deleted file mode 100644 index e3ad8a6..0000000 --- a/compat/clock_gettime/README +++ /dev/null @@ -1,31 +0,0 @@ -/* - * clock_gettime_stub.c - * gcc -Wall -c clock_gettime_stub.c - * posix realtime functions; MacOS user space glue - */ - -/* @comment - * other possible implementation using intel builtin rdtsc - * rdtsc-workaround: http://www.mcs.anl.gov/~kazutomo/rdtsc.html - * - * we could get the ticks by doing this - * - * __asm __volatile("mov %%ebx, %%esi\n\t" - * "cpuid\n\t" - * "xchg %%esi, %%ebx\n\t" - * "rdtsc" - * : "=a" (a), - * "=d" (d) - * ); - - * we could even replace our tricky sched_yield call by assembly code to get a better accurency, - * anyway the following C stub will satisfy 99% of apps using posix clock_gettime call, - * moreover, the setter version (clock_settime) could be easly written using mach primitives: - * http://www.opensource.apple.com/source/xnu/xnu-${VERSION}/osfmk/man/ (clock_[set|get]_time) - * - * hackers don't be crackers, don't you use a flush toilet? - * - * - * @see draft: ./posix-realtime-stub/posix-realtime-stub.c - * - */ \ No newline at end of file diff --git a/compat/clock_gettime/clock_gettime.c b/compat/clock_gettime/clock_gettime.c index 2b28f43..372ff2e 100644 --- a/compat/clock_gettime/clock_gettime.c +++ b/compat/clock_gettime/clock_gettime.c @@ -1,4 +1,63 @@ -#ifdef __APPLE__ +/* + * Copyright (c), MM Weiss + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the MM Weiss nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * clock_gettime_stub.c + * gcc -Wall -c clock_gettime_stub.c + * posix realtime functions; MacOS user space glue + */ + +/* @comment + * other possible implementation using intel builtin rdtsc + * rdtsc-workaround: http://www.mcs.anl.gov/~kazutomo/rdtsc.html + * + * we could get the ticks by doing this + * + * __asm __volatile("mov %%ebx, %%esi\n\t" + * "cpuid\n\t" + * "xchg %%esi, %%ebx\n\t" + * "rdtsc" + * : "=a" (a), + * "=d" (d) + * ); + * we could even replace our tricky sched_yield call by assembly code to get a better accurency, + * anyway the following C stub will satisfy 99% of apps using posix clock_gettime call, + * moreover, the setter version (clock_settime) could be easly written using mach primitives: + * http://www.opensource.apple.com/source/xnu/xnu-${VERSION}/osfmk/man/ (clock_[set|get]_time) + * + * hackers don't be crackers, don't you use a flush toilet? + * + * + * @see draft: ./posix-realtime-stub/posix-realtime-stub.c + * + */ + #include "clock_gettime.h" #include // for clock_get_time @@ -75,5 +134,3 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) } return retval; } - -#endif // __APPLE__ \ No newline at end of file diff --git a/compat/clock_gettime/clock_gettime.h b/compat/clock_gettime/clock_gettime.h index 2478104..978f522 100644 --- a/compat/clock_gettime/clock_gettime.h +++ b/compat/clock_gettime/clock_gettime.h @@ -1,5 +1,3 @@ -#ifdef __APPLE__ - #ifndef CLOCK_GETTIME_H #define CLOCK_GETTIME_H @@ -23,4 +21,3 @@ static mach_timebase_info_data_t __clock_gettime_inf; int clock_gettime(clockid_t clk_id, struct timespec *tp); #endif // CLOCK_GETTIME_H -#endif // __APPLE__ \ No newline at end of file diff --git a/compat/clock_nanosleep/clock_nanosleep.c b/compat/clock_nanosleep/clock_nanosleep.c index 6dcecfb..9cbd1e4 100644 --- a/compat/clock_nanosleep/clock_nanosleep.c +++ b/compat/clock_nanosleep/clock_nanosleep.c @@ -2,7 +2,22 @@ * clock_nanosleep.c - clock_nanosleep() replacement */ -#ifdef __APPLE__ +/*********************************************************************** + * Copyright © 2006 Rémi Denis-Courmont. * + * This program is free software; you can redistribute and/or modify * + * it under the terms of the GNU General Public License as published * + * by the Free Software Foundation; version 2 of the license, or (at * + * your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, you can get it from: * + * http://www.gnu.org/copyleft/gpl.html * + ***********************************************************************/ #include "clock_nanosleep.h" #include // for errno, EINVAL @@ -45,5 +60,3 @@ int clock_nanosleep(clockid_t id, int flags, const struct timespec *ts, return ret ? errno : 0; } - -#endif // __APPLE__ \ No newline at end of file diff --git a/compat/clock_nanosleep/clock_nanosleep.h b/compat/clock_nanosleep/clock_nanosleep.h index 6e55db6..5f91915 100644 --- a/compat/clock_nanosleep/clock_nanosleep.h +++ b/compat/clock_nanosleep/clock_nanosleep.h @@ -1,5 +1,3 @@ -#ifdef __APPLE__ - #ifndef CLOCK_NANOSLEEP_H #define CLOCK_NANOSLEEP_H @@ -24,4 +22,3 @@ int clock_nanosleep (clockid_t id, int flags, const struct timespec *ts, struct timespec *ots); #endif //CLOCK_NANOSLEEP_H -#endif // __APPLE__ \ No newline at end of file diff --git a/compat/compat.h b/compat/compat.h new file mode 100644 index 0000000..c8bb5fb --- /dev/null +++ b/compat/compat.h @@ -0,0 +1,32 @@ +#ifndef COMPAT_UTIL_H +#define COMPAT_UTIL_H + +/* + * Platform-specific bits + */ + +#if defined(__APPLE__) + +/* implementations of clock_gettime, clock_nanosleep */ + +#include "clock_gettime/clock_gettime.h" +#include "clock_nanosleep/clock_nanosleep.h" + +/* + * Mach endian conversion + */ +# include +# define bswap_16 OSSwapInt16 +# define bswap_32 OSSwapInt32 +# define bswap_64 OSSwapInt64 +# include +# define le16toh(x) OSSwapLittleToHostInt16(x) +# define le32toh(x) OSSwapLittleToHostInt32(x) + +#else // other platforms + +# include + +#endif + +#endif //COMPAT_UTIL_H diff --git a/compat/util.h b/compat/util.h deleted file mode 100644 index 82bd99c..0000000 --- a/compat/util.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef COMPAT_UTIL_H -#define COMPAT_UTIL_H - -#include "clock_gettime/clock_gettime.h" -#include "clock_nanosleep/clock_nanosleep.h" - -/* - * Mach endian conversion - */ -#if defined(__APPLE__) -#include -#define bswap_16 OSSwapInt16 -#define bswap_32 OSSwapInt32 -#define bswap_64 OSSwapInt64 -#include -#define le16toh(x) OSSwapLittleToHostInt16(x) -#define le32toh(x) OSSwapLittleToHostInt32(x) -#endif - -#endif //COMPAT_UTIL_H diff --git a/convert.c b/convert.c index 0d63355..cb55dca 100644 --- a/convert.c +++ b/convert.c @@ -19,10 +19,6 @@ #include "dump1090.h" -#ifdef __APPLE__ -#include "compat/util.h" -#endif - struct converter_state { float dc_a; float dc_b; diff --git a/dump1090.c b/dump1090.c index 51691b8..72b3e08 100644 --- a/dump1090.c +++ b/dump1090.c @@ -53,14 +53,6 @@ #include -#ifdef __linux__ -#include -#endif - -#ifdef __APPLE__ -#include "compat/util.h" -#endif - static int verbose_device_search(char *s); // diff --git a/dump1090.h b/dump1090.h index fc65b4e..c175bea 100644 --- a/dump1090.h +++ b/dump1090.h @@ -82,6 +82,8 @@ #include "winstubs.h" //Put everything Windows specific in here #endif +#include "compat/compat.h" + // Avoid a dependency on rtl-sdr except where it's really needed. typedef struct rtlsdr_dev rtlsdr_dev_t; diff --git a/net_io.c b/net_io.c index eff6b19..26601f4 100644 --- a/net_io.c +++ b/net_io.c @@ -54,10 +54,6 @@ #include -#ifdef __APPLE__ -#include "compat/util.h" -#endif - // // ============================= Networking ============================= //