Make curl example into a complete tool (#706)

You can now handily use `curl` with popen()/system() by
placing `STATIC_YOINK("_curl")` in your main source file.
This commit is contained in:
Ronsor 2022-12-21 16:12:02 -08:00 committed by GitHub
parent dd04aeba1c
commit f6b3019796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 96 additions and 4 deletions

View file

@ -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

View file

@ -38,6 +38,7 @@
#include "third_party/awk/cmd.h"
#include "third_party/sed/cmd.h"
#include "third_party/tr/cmd.h"
#include "tool/curl/cmd.h"
/**
* @fileoverview Cosmopolitan Command Interpreter
@ -417,6 +418,7 @@ static int TryBuiltin(void) {
if (_weaken(_tr) && !strcmp(args[0], "tr")) return Fake(_weaken(_tr));
if (_weaken(_sed) && !strcmp(args[0], "sed")) return Fake(_weaken(_sed));
if (_weaken(_awk) && !strcmp(args[0], "awk")) return Fake(_weaken(_awk));
if (_weaken(_curl) && !strcmp(args[0], "curl")) return Fake(_weaken(_curl));
return -1;
}

5
tool/curl/cmd.c Normal file
View file

@ -0,0 +1,5 @@
#include "tool/curl/cmd.h"
int main(int argc, char *argv[]) {
return _curl(argc, argv);
}

10
tool/curl/cmd.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef COSMOPOLITAN_TOOL_CURL_CMD_H_
#define COSMOPOLITAN_TOOL_CURL_CMD_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int _curl(int, char *[]);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_TOOL_CURL_CMD_H_ */

View file

@ -52,12 +52,10 @@
#include "third_party/mbedtls/pk.h"
#include "third_party/mbedtls/ssl.h"
#include "third_party/mbedtls/ssl_ticket.h"
#include "tool/curl/cmd.h"
/**
* @fileoverview Downloads HTTP URL to stdout.
*
* make -j8 o//examples/curl.com
* o//examples/curl.com http://justine.lol/ape.html
*/
#define HasHeader(H) (!!msg.headers[H].a)
@ -121,7 +119,7 @@ static wontreturn void PrintUsage(FILE *f, int rc) {
exit(rc);
}
int main(int argc, char *argv[]) {
int _curl(int argc, char *argv[]) {
if (!NoDebug()) ShowCrashReports();
/*

74
tool/curl/curl.mk Normal file
View file

@ -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)

View file

@ -15,6 +15,7 @@ TOOL_NET_BINS = \
$(TOOL_NET_COMS:%=%.dbg)
TOOL_NET_COMS = \
o/$(MODE)/tool/net/curl.com \
o/$(MODE)/tool/net/dig.com \
o/$(MODE)/tool/net/redbean.com \
o/$(MODE)/tool/net/redbean-demo.com \

View file

@ -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 \