From 4e3978fa4d433040287e5024d221b1ace0f40144 Mon Sep 17 00:00:00 2001 From: Ronsor Date: Tue, 20 Dec 2022 14:26:55 -0700 Subject: [PATCH] Move `curl` to `tool/curl/` and support it as a builtin in `cocmd`. You can now handily use `curl` with popen()/system() with STATIC_YOINK("_curl"). --- Makefile | 1 + libc/runtime/cocmd.c | 2 +- tool/{net/curl.c => curl/cmd.c} | 2 +- tool/{net/curl.h => curl/cmd.h} | 6 +-- tool/{net/curl.inc => curl/curl.c} | 2 +- tool/curl/curl.mk | 74 ++++++++++++++++++++++++++++++ tool/tool.mk | 1 + 7 files changed, 82 insertions(+), 6 deletions(-) rename tool/{net/curl.c => curl/cmd.c} (70%) rename tool/{net/curl.h => curl/cmd.h} (54%) rename tool/{net/curl.inc => curl/curl.c} (99%) create mode 100644 tool/curl/curl.mk diff --git a/Makefile b/Makefile index bf31c1940..d1d72a8aa 100644 --- a/Makefile +++ b/Makefile @@ -193,6 +193,7 @@ include third_party/python/python.mk include tool/build/emucrt/emucrt.mk include tool/build/emubin/emubin.mk include tool/build/build.mk +include tool/curl/curl.mk include examples/examples.mk include examples/pyapp/pyapp.mk include examples/pylife/pylife.mk diff --git a/libc/runtime/cocmd.c b/libc/runtime/cocmd.c index 374e8f2bb..7039f287d 100644 --- a/libc/runtime/cocmd.c +++ b/libc/runtime/cocmd.c @@ -38,7 +38,7 @@ #include "third_party/awk/cmd.h" #include "third_party/sed/cmd.h" #include "third_party/tr/cmd.h" -#include "tool/net/curl.h" +#include "tool/curl/cmd.h" /** * @fileoverview Cosmopolitan Command Interpreter diff --git a/tool/net/curl.c b/tool/curl/cmd.c similarity index 70% rename from tool/net/curl.c rename to tool/curl/cmd.c index 903c06c0b..6cefc2c3e 100644 --- a/tool/net/curl.c +++ b/tool/curl/cmd.c @@ -1,4 +1,4 @@ -#include "curl.inc" +#include "tool/curl/cmd.h" int main(int argc, char *argv[]) { return _curl(argc, argv); diff --git a/tool/net/curl.h b/tool/curl/cmd.h similarity index 54% rename from tool/net/curl.h rename to tool/curl/cmd.h index 410d818d8..041aad1c4 100644 --- a/tool/net/curl.h +++ b/tool/curl/cmd.h @@ -1,5 +1,5 @@ -#ifndef COSMOPOLITAN_TOOL_NET_CURL_CMD_H_ -#define COSMOPOLITAN_TOOL_NET_CURL_CMD_H_ +#ifndef COSMOPOLITAN_TOOL_CURL_CMD_H_ +#define COSMOPOLITAN_TOOL_CURL_CMD_H_ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -7,4 +7,4 @@ int _curl(int, char *[]); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_TOOL_NET_CURL_CMD_H_ */ +#endif /* COSMOPOLITAN_TOOL_CURL_CMD_H_ */ diff --git a/tool/net/curl.inc b/tool/curl/curl.c similarity index 99% rename from tool/net/curl.inc rename to tool/curl/curl.c index 995a0e0c8..9de66ad37 100644 --- a/tool/net/curl.inc +++ b/tool/curl/curl.c @@ -52,7 +52,7 @@ #include "third_party/mbedtls/pk.h" #include "third_party/mbedtls/ssl.h" #include "third_party/mbedtls/ssl_ticket.h" -#include "tool/net/curl.h" +#include "tool/curl/cmd.h" /** * @fileoverview Downloads HTTP URL to stdout. diff --git a/tool/curl/curl.mk b/tool/curl/curl.mk new file mode 100644 index 000000000..c76f60979 --- /dev/null +++ b/tool/curl/curl.mk @@ -0,0 +1,74 @@ +#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐ +#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘ + +PKGS += TOOL_CURL + +TOOL_CURL_ARTIFACTS += TOOL_CURL_A +TOOL_CURL = $(TOOL_CURL_DEPS) $(TOOL_CURL_A) +TOOL_CURL_A = o/$(MODE)/tool/curl/curl.a +TOOL_CURL_FILES := $(wildcard tool/curl/*) +TOOL_CURL_HDRS = $(filter %.h,$(TOOL_CURL_FILES)) +TOOL_CURL_INCS = $(filter %.inc,$(TOOL_CURL_FILES)) +TOOL_CURL_SRCS = $(filter %.c,$(TOOL_CURL_FILES)) +TOOL_CURL_OBJS = $(TOOL_CURL_SRCS:%.c=o/$(MODE)/%.o) + +TOOL_CURL_DIRECTDEPS = \ + LIBC_CALLS \ + LIBC_DNS \ + LIBC_FMT \ + LIBC_INTRIN \ + LIBC_LOG \ + LIBC_MEM \ + LIBC_NEXGEN32E \ + LIBC_NT_IPHLPAPI \ + LIBC_NT_KERNEL32 \ + LIBC_RUNTIME \ + LIBC_SOCK \ + LIBC_STDIO \ + LIBC_STR \ + LIBC_STUBS \ + LIBC_SYSV \ + LIBC_SYSV_CALLS \ + LIBC_TIME \ + LIBC_THREAD \ + LIBC_TINYMATH \ + LIBC_X \ + LIBC_ZIPOS \ + NET_HTTP \ + NET_HTTPS \ + THIRD_PARTY_GETOPT \ + THIRD_PARTY_MBEDTLS + +TOOL_CURL_DEPS := \ + $(call uniq,$(foreach x,$(TOOL_CURL_DIRECTDEPS),$($(x)))) + +TOOL_CURL_CHECKS = \ + $(TOOL_CURL_A).pkg \ + $(TOOL_CURL_HDRS:%=o/$(MODE)/%.ok) + +$(TOOL_CURL_A): \ + tool/curl/ \ + $(TOOL_CURL_A).pkg \ + $(TOOL_CURL_OBJS) + +$(TOOL_CURL_A).pkg: \ + $(TOOL_CURL_OBJS) \ + $(foreach x,$(TOOL_CURL_DIRECTDEPS),$($(x)_A).pkg) + +o/$(MODE)/tool/curl/curl.com.dbg: \ + $(TOOL_CURL) \ + o/$(MODE)/tool/curl/cmd.o \ + o/$(MODE)/tool/curl/curl.o \ + $(CRT) \ + $(APE_NO_MODIFY_SELF) + @$(APELINK) + +TOOL_CURL_LIBS = $(TOOL_CURL_A) +TOOL_CURL_BINS = $(TOOL_CURL_COMS) $(TOOL_CURL_COMS:%=%.dbg) +TOOL_CURL_COMS = o/$(MODE)/tool/curl/curl.com +$(TOOL_CURL_OBJS): $(BUILD_FILES) tool/curl/curl.mk + +.PHONY: o/$(MODE)/tool/curl +o/$(MODE)/tool/curl: \ + $(TOOL_CURL_BINS) \ + $(TOOL_CURL_CHECKS) diff --git a/tool/tool.mk b/tool/tool.mk index b2bde1561..066f9df15 100644 --- a/tool/tool.mk +++ b/tool/tool.mk @@ -5,6 +5,7 @@ o/$(MODE)/tool: \ o/$(MODE)/tool/args \ o/$(MODE)/tool/build \ + o/$(MODE)/tool/curl \ o/$(MODE)/tool/decode \ o/$(MODE)/tool/hash \ o/$(MODE)/tool/lambda \